Fix tests on systems with a non-master git defaultBranch #1

Open
zebreus wants to merge 140 commits from fix-tests-without-master into main
2 changed files with 16 additions and 5 deletions
Showing only changes of commit 742303dc3a - Show all commits

View file

@ -17,15 +17,19 @@ namespace fs = std::filesystem;
namespace nix { namespace nix {
Path absPath(Path path, std::optional<PathView> dir, bool resolveSymlinks) Path getCwd() {
{
if (path.empty() || path[0] != '/') {
if (!dir) {
char buf[PATH_MAX]; char buf[PATH_MAX];
if (!getcwd(buf, sizeof(buf))) { if (!getcwd(buf, sizeof(buf))) {
throw SysError("cannot get cwd"); throw SysError("cannot get cwd");
} }
path = concatStrings(buf, "/", path); return Path(buf);
}
Path absPath(Path path, std::optional<PathView> dir, bool resolveSymlinks)
{
if (path.empty() || path[0] != '/') {
if (!dir) {
path = concatStrings(getCwd(), "/", path);
} else { } else {
path = concatStrings(*dir, "/", path); path = concatStrings(*dir, "/", path);
} }

View file

@ -29,6 +29,13 @@ namespace nix {
struct Sink; struct Sink;
struct Source; struct Source;
/**
* Get the current working directory.
*
* Throw an error if the current directory cannot get got.
*/
Path getCwd();
/** /**
* @return An absolutized path, resolving paths relative to the * @return An absolutized path, resolving paths relative to the
* specified directory, or the current directory otherwise. The path * specified directory, or the current directory otherwise. The path