Skip to content

Commit

Permalink
getSourcePath(): Return std::filesystem::path
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Jan 17, 2025
1 parent adf0e9b commit f26b79f
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void Input::clone(const Path & destDir) const
scheme->clone(*this, destDir);
}

std::optional<Path> Input::getSourcePath() const
std::optional<std::filesystem::path> Input::getSourcePath() const
{
assert(scheme);
return scheme->getSourcePath(*this);
Expand Down Expand Up @@ -461,7 +461,7 @@ Input InputScheme::applyOverrides(
return input;
}

std::optional<Path> InputScheme::getSourcePath(const Input & input) const
std::optional<std::filesystem::path> InputScheme::getSourcePath(const Input & input) const
{
return {};
}
Expand Down
4 changes: 2 additions & 2 deletions src/libfetchers/fetchers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public:

void clone(const Path & destDir) const;

std::optional<Path> getSourcePath() const;
std::optional<std::filesystem::path> getSourcePath() const;

/**
* Write a file to this input, for input types that support
Expand Down Expand Up @@ -247,7 +247,7 @@ struct InputScheme

virtual void clone(const Input & input, const Path & destDir) const;

virtual std::optional<Path> getSourcePath(const Input & input) const;
virtual std::optional<std::filesystem::path> getSourcePath(const Input & input) const;

virtual void putFile(
const Input & input,
Expand Down
9 changes: 2 additions & 7 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,9 @@ struct GitInputScheme : InputScheme
runProgram("git", true, args, {}, true);
}

// FIXME: return std::filesystem::path
std::optional<Path> getSourcePath(const Input & input) const override
std::optional<std::filesystem::path> getSourcePath(const Input & input) const override
{
auto repoInfo = getRepoInfo(input);
if (auto path = repoInfo.getPath())
return *path;
else
return std::nullopt;
return getRepoInfo(input).getPath();
}

void putFile(
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/mercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct MercurialInputScheme : InputScheme
return res;
}

std::optional<Path> getSourcePath(const Input & input) const override
std::optional<std::filesystem::path> getSourcePath(const Input & input) const override
{
auto url = parseURL(getStrAttr(input.attrs, "url"));
if (url.scheme == "file" && !input.getRef() && !input.getRev())
Expand Down
4 changes: 2 additions & 2 deletions src/libfetchers/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ struct PathInputScheme : InputScheme
};
}

std::optional<Path> getSourcePath(const Input & input) const override
std::optional<std::filesystem::path> getSourcePath(const Input & input) const override
{
return getStrAttr(input.attrs, "path");
return getAbsPath(input);
}

void putFile(
Expand Down
2 changes: 1 addition & 1 deletion src/libflake/flake/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ LockedFlake lockFlake(
writeFile(*lockFlags.outputLockFilePath, newLockFileS);
} else {
auto relPath = (topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock";
auto outputLockFilePath = *sourcePath + "/" + relPath;
auto outputLockFilePath = *sourcePath / relPath;

bool lockFileExists = pathExists(outputLockFilePath);

Expand Down
2 changes: 1 addition & 1 deletion src/nix/develop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ struct CmdDevelop : Common, MixEnvironment
auto sourcePath = installableFlake->getLockedFlake()->flake.resolvedRef.input.getSourcePath();
if (sourcePath) {
if (chdir(sourcePath->c_str()) == -1) {
throw SysError("chdir to '%s' failed", *sourcePath);
throw SysError("chdir to %s failed", *sourcePath);
}
}
}
Expand Down

0 comments on commit f26b79f

Please sign in to comment.