Skip to content

Commit a31f2cb

Browse files
authored
Merge pull request #9939 from edolstra/slash-operator
CanonPath, SourcePath: Change operator + to /
2 parents c291d2d + a6737b7 commit a31f2cb

23 files changed

+48
-47
lines changed

src/libexpr/eval.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,14 +2689,14 @@ SourcePath resolveExprPath(SourcePath path)
26892689
// Basic cycle/depth limit to avoid infinite loops.
26902690
if (++followCount >= maxFollow)
26912691
throw Error("too many symbolic links encountered while traversing the path '%s'", path);
2692-
auto p = path.parent().resolveSymlinks() + path.baseName();
2692+
auto p = path.parent().resolveSymlinks() / path.baseName();
26932693
if (p.lstat().type != InputAccessor::tSymlink) break;
26942694
path = {path.accessor, CanonPath(p.readLink(), path.path.parent().value_or(CanonPath::root))};
26952695
}
26962696

26972697
/* If `path' refers to a directory, append `/default.nix'. */
26982698
if (path.resolveSymlinks().lstat().type == InputAccessor::tDirectory)
2699-
return path + "default.nix";
2699+
return path / "default.nix";
27002700

27012701
return path;
27022702
}

src/libexpr/primops.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ static void prim_readDir(EvalState & state, const PosIdx pos, Value * * args, Va
18161816
// detailed node info quickly in this case we produce a thunk to
18171817
// query the file type lazily.
18181818
auto epath = state.allocValue();
1819-
epath->mkPath(path + name);
1819+
epath->mkPath(path / name);
18201820
if (!readFileType)
18211821
readFileType = &state.getBuiltin("readFileType");
18221822
attr.mkApp(readFileType, epath);

src/libfetchers/filtering-input-accessor.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ namespace nix {
55
std::string FilteringInputAccessor::readFile(const CanonPath & path)
66
{
77
checkAccess(path);
8-
return next->readFile(prefix + path);
8+
return next->readFile(prefix / path);
99
}
1010

1111
bool FilteringInputAccessor::pathExists(const CanonPath & path)
1212
{
13-
return isAllowed(path) && next->pathExists(prefix + path);
13+
return isAllowed(path) && next->pathExists(prefix / path);
1414
}
1515

1616
std::optional<InputAccessor::Stat> FilteringInputAccessor::maybeLstat(const CanonPath & path)
1717
{
1818
checkAccess(path);
19-
return next->maybeLstat(prefix + path);
19+
return next->maybeLstat(prefix / path);
2020
}
2121

2222
InputAccessor::DirEntries FilteringInputAccessor::readDirectory(const CanonPath & path)
2323
{
2424
checkAccess(path);
2525
DirEntries entries;
26-
for (auto & entry : next->readDirectory(prefix + path)) {
27-
if (isAllowed(path + entry.first))
26+
for (auto & entry : next->readDirectory(prefix / path)) {
27+
if (isAllowed(path / entry.first))
2828
entries.insert(std::move(entry));
2929
}
3030
return entries;
@@ -33,12 +33,12 @@ InputAccessor::DirEntries FilteringInputAccessor::readDirectory(const CanonPath
3333
std::string FilteringInputAccessor::readLink(const CanonPath & path)
3434
{
3535
checkAccess(path);
36-
return next->readLink(prefix + path);
36+
return next->readLink(prefix / path);
3737
}
3838

3939
std::string FilteringInputAccessor::showPath(const CanonPath & path)
4040
{
41-
return next->showPath(prefix + path);
41+
return next->showPath(prefix / path);
4242
}
4343

4444
void FilteringInputAccessor::checkAccess(const CanonPath & path)

src/libfetchers/fs-input-accessor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct FSInputAccessor : InputAccessor, PosixSourceAccessor
4848

4949
CanonPath makeAbsPath(const CanonPath & path)
5050
{
51-
return root + path;
51+
return root / path;
5252
}
5353

5454
std::optional<CanonPath> getPhysicalPath(const CanonPath & path) override

src/libfetchers/git-utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
295295
throw Error("getting working directory status: %s", git_error_last()->message);
296296

297297
/* Get submodule info. */
298-
auto modulesFile = path + ".gitmodules";
298+
auto modulesFile = path / ".gitmodules";
299299
if (pathExists(modulesFile.abs()))
300300
info.submodules = parseSubmodules(modulesFile);
301301

src/libfetchers/git.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ struct GitInputScheme : InputScheme
319319
if (!repoInfo.isLocal)
320320
throw Error("cannot commit '%s' to Git repository '%s' because it's not a working tree", path, input.to_string());
321321

322-
writeFile((CanonPath(repoInfo.url) + path).abs(), contents);
322+
writeFile((CanonPath(repoInfo.url) / path).abs(), contents);
323323

324324
auto result = runProgram(RunOptions {
325325
.program = "git",
@@ -680,7 +680,7 @@ struct GitInputScheme : InputScheme
680680
std::map<CanonPath, nix::ref<InputAccessor>> mounts;
681681

682682
for (auto & submodule : repoInfo.workdirInfo.submodules) {
683-
auto submodulePath = CanonPath(repoInfo.url) + submodule.path;
683+
auto submodulePath = CanonPath(repoInfo.url) / submodule.path;
684684
fetchers::Attrs attrs;
685685
attrs.insert_or_assign("type", "git");
686686
attrs.insert_or_assign("url", submodulePath.abs());

src/libfetchers/mercurial.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ struct MercurialInputScheme : InputScheme
141141
if (!isLocal)
142142
throw Error("cannot commit '%s' to Mercurial repository '%s' because it's not a working tree", path, input.to_string());
143143

144-
auto absPath = CanonPath(repoPath) + path;
144+
auto absPath = CanonPath(repoPath) / path;
145145

146146
writeFile(absPath.abs(), contents);
147147

src/libfetchers/path.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct PathInputScheme : InputScheme
8484
std::string_view contents,
8585
std::optional<std::string> commitMsg) const override
8686
{
87-
writeFile((CanonPath(getAbsPath(input)) + path).abs(), contents);
87+
writeFile((CanonPath(getAbsPath(input)) / path).abs(), contents);
8888
}
8989

9090
CanonPath getAbsPath(const Input & input) const

src/libstore/binary-cache-store.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
235235
std::regex regex2("^[0-9a-f]{38}\\.debug$");
236236

237237
for (auto & [s1, _type] : narAccessor->readDirectory(buildIdDir)) {
238-
auto dir = buildIdDir + s1;
238+
auto dir = buildIdDir / s1;
239239

240240
if (narAccessor->lstat(dir).type != SourceAccessor::tDirectory
241241
|| !std::regex_match(s1, regex1))
242242
continue;
243243

244244
for (auto & [s2, _type] : narAccessor->readDirectory(dir)) {
245-
auto debugPath = dir + s2;
245+
auto debugPath = dir / s2;
246246

247247
if (narAccessor->lstat(debugPath).type != SourceAccessor::tRegular
248248
|| !std::regex_match(s2, regex2))

src/libstore/local-fs-store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct LocalStoreAccessor : PosixSourceAccessor
2828
auto [storePath, rest] = store->toStorePath(path.abs());
2929
if (requireValidPath && !store->isValidPath(storePath))
3030
throw InvalidPath("path '%1%' is not a valid store path", store->printStorePath(storePath));
31-
return CanonPath(store->getRealStoreDir()) + storePath.to_string() + CanonPath(rest);
31+
return CanonPath(store->getRealStoreDir()) / storePath.to_string() / CanonPath(rest);
3232
}
3333

3434
std::optional<Stat> maybeLstat(const CanonPath & path) override

0 commit comments

Comments
 (0)