@@ -91,10 +91,10 @@ struct PathInputScheme : InputScheme
9191 std::string_view contents,
9292 std::optional<std::string> commitMsg) const override
9393 {
94- writeFile (( CanonPath ( getAbsPath (input)) / path). abs (), contents);
94+ writeFile (getAbsPath (input) / path. rel (), contents);
9595 }
9696
97- std::optional<std::string> isRelative (const Input & input) const
97+ std::optional<std::string> isRelative (const Input & input) const override
9898 {
9999 auto path = getStrAttr (input.attrs , " path" );
100100 if (isAbsolute (path))
@@ -108,44 +108,27 @@ struct PathInputScheme : InputScheme
108108 return (bool ) input.getNarHash ();
109109 }
110110
111- CanonPath getAbsPath (const Input & input) const
111+ std::filesystem::path getAbsPath (const Input & input) const
112112 {
113113 auto path = getStrAttr (input.attrs , " path" );
114114
115- if (path[ 0 ] == ' / ' )
116- return CanonPath (path);
115+ if (isAbsolute ( path) )
116+ return canonPath (path);
117117
118118 throw Error (" cannot fetch input '%s' because it uses a relative path" , input.to_string ());
119119 }
120120
121121 std::pair<ref<SourceAccessor>, Input> getAccessor (ref<Store> store, const Input & _input) const override
122122 {
123123 Input input (_input);
124- std::string absPath;
125124 auto path = getStrAttr (input.attrs , " path" );
126125
127- if (path[0 ] != ' /' ) {
128- if (!input.parent )
129- throw Error (" cannot fetch input '%s' because it uses a relative path" , input.to_string ());
130-
131- auto parent = canonPath (*input.parent );
132-
133- // the path isn't relative, prefix it
134- absPath = nix::absPath (path, parent);
135-
136- // for security, ensure that if the parent is a store path, it's inside it
137- if (store->isInStore (parent)) {
138- auto storePath = store->printStorePath (store->toStorePath (parent).first );
139- if (!isDirOrInDir (absPath, storePath))
140- throw BadStorePath (" relative path '%s' points outside of its parent's store path '%s'" , path, storePath);
141- }
142- } else
143- absPath = path;
126+ auto absPath = getAbsPath (input);
144127
145- Activity act (*logger, lvlTalkative, actUnknown, fmt (" copying '%s'" , absPath));
128+ Activity act (*logger, lvlTalkative, actUnknown, fmt (" copying '%s' to the store " , absPath));
146129
147130 // FIXME: check whether access to 'path' is allowed.
148- auto storePath = store->maybeParseStorePath (absPath);
131+ auto storePath = store->maybeParseStorePath (absPath. string () );
149132
150133 if (storePath)
151134 store->addTempRoot (*storePath);
@@ -154,7 +137,7 @@ struct PathInputScheme : InputScheme
154137 if (!storePath || storePath->name () != " source" || !store->isValidPath (*storePath)) {
155138 // FIXME: try to substitute storePath.
156139 auto src = sinkToSource ([&](Sink & sink) {
157- mtime = dumpPathAndGetMtime (absPath, sink, defaultPathFilter);
140+ mtime = dumpPathAndGetMtime (absPath. string () , sink, defaultPathFilter);
158141 });
159142 storePath = store->addToStoreFromDump (*src, " source" );
160143 }
@@ -176,7 +159,7 @@ struct PathInputScheme : InputScheme
176159 store object and the subpath. */
177160 auto path = getAbsPath (input);
178161 try {
179- auto [storePath, subPath] = store->toStorePath (path.abs ());
162+ auto [storePath, subPath] = store->toStorePath (path.string ());
180163 auto info = store->queryPathInfo (storePath);
181164 return fmt (" path:%s:%s" , info->narHash .to_string (HashFormat::Base16, false ), subPath);
182165 } catch (Error &) {
0 commit comments