Skip to content

Commit 0e1df1c

Browse files
authored
Merge pull request #91 from DeterminateSystems/fix-substituted-input-path-display
Fix rendering of paths in substituted source trees
2 parents 76b9be3 + 74af43e commit 0e1df1c

3 files changed

Lines changed: 77 additions & 1 deletion

File tree

src/libfetchers/fetchers.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "nix/util/json-utils.hh"
66
#include "nix/fetchers/store-path-accessor.hh"
77
#include "nix/fetchers/fetch-settings.hh"
8+
#include "nix/util/forwarding-source-accessor.hh"
89

910
#include <nlohmann/json.hpp>
1011

@@ -293,6 +294,21 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessor(ref<Store> store) const
293294
}
294295
}
295296

297+
/**
298+
* Helper class that ensures that paths in substituted source trees
299+
* are rendered as `«input»/path` rather than
300+
* `«input»/nix/store/<hash>-source/path`.
301+
*/
302+
struct SubstitutedSourceAccessor : ForwardingSourceAccessor
303+
{
304+
using ForwardingSourceAccessor::ForwardingSourceAccessor;
305+
306+
std::string showPath(const CanonPath & path) override
307+
{
308+
return displayPrefix + path.abs() + displaySuffix;
309+
}
310+
};
311+
296312
std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> store) const
297313
{
298314
// FIXME: cache the accessor
@@ -320,10 +336,12 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> sto
320336
debug("using substituted/cached input '%s' in '%s'",
321337
to_string(), store->printStorePath(storePath));
322338

323-
auto accessor = makeStorePathAccessor(store, storePath);
339+
auto accessor = make_ref<SubstitutedSourceAccessor>(makeStorePathAccessor(store, storePath));
324340

325341
accessor->fingerprint = getFingerprint(store);
326342

343+
// FIXME: ideally we would use the `showPath()` of the
344+
// "real" accessor for this fetcher type.
327345
accessor->setPathDisplay("«" + to_string() + "»");
328346

329347
return {accessor, *this};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#pragma once
2+
3+
#include "source-accessor.hh"
4+
5+
namespace nix {
6+
7+
/**
8+
* A source accessor that just forwards every operation to another
9+
* accessor. This is not useful in itself but can be used as a
10+
* superclass for accessors that do change some operations.
11+
*/
12+
struct ForwardingSourceAccessor : SourceAccessor
13+
{
14+
ref<SourceAccessor> next;
15+
16+
ForwardingSourceAccessor(ref<SourceAccessor> next)
17+
: next(next)
18+
{
19+
}
20+
21+
std::string readFile(const CanonPath & path) override
22+
{
23+
return next->readFile(path);
24+
}
25+
26+
void readFile(const CanonPath & path, Sink & sink, std::function<void(uint64_t)> sizeCallback) override
27+
{
28+
next->readFile(path, sink, sizeCallback);
29+
}
30+
31+
std::optional<Stat> maybeLstat(const CanonPath & path) override
32+
{
33+
return next->maybeLstat(path);
34+
}
35+
36+
DirEntries readDirectory(const CanonPath & path) override
37+
{
38+
return next->readDirectory(path);
39+
}
40+
41+
std::string readLink(const CanonPath & path) override
42+
{
43+
return next->readLink(path);
44+
}
45+
46+
std::string showPath(const CanonPath & path) override
47+
{
48+
return next->showPath(path);
49+
}
50+
51+
std::optional<std::filesystem::path> getPhysicalPath(const CanonPath & path) override
52+
{
53+
return next->getPhysicalPath(path);
54+
}
55+
};
56+
57+
}

src/libutil/include/nix/util/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ headers = files(
3434
'file-system.hh',
3535
'finally.hh',
3636
'fmt.hh',
37+
'forwarding-source-accessor.hh',
3738
'fs-sink.hh',
3839
'git.hh',
3940
'hash.hh',

0 commit comments

Comments
 (0)