Skip to content

Commit

Permalink
more readable errors if symlinks cannot be created
Browse files Browse the repository at this point in the history
Before:

filesystem error: cannot create symlink: Permission denied
[/nix/store/1s2p3a4rs172336hj2l8n20nz74hf71j-nix-eval-jobs-2.24.1.drv]
[/1s2p3a4rs172336hj2l8n20nz74hf71j-nix-eval-jobs-2.24.1.drv.tmp-2772352-1316231068]

Now:
  • Loading branch information
Mic92 committed Nov 26, 2024
1 parent 9931881 commit c573d50
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/libutil/file-system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,11 @@ std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix)

void createSymlink(const Path & target, const Path & link)
{
fs::create_symlink(target, link);
try {
fs::create_symlink(target, link);
} except (fs::filesystem_error & e) {
throw SysError("creating symlink '%1%' -> '%2%'", link, target);
}
}

void replaceSymlink(const fs::path & target, const fs::path & link)
Expand All @@ -615,10 +619,16 @@ void replaceSymlink(const fs::path & target, const fs::path & link)
fs::create_symlink(target, tmp);
} catch (fs::filesystem_error & e) {
if (e.code() == std::errc::file_exists) continue;
throw;
throw SysError("creating symlink '%1%' -> '%2%'", tmp, target);
}

try {
fs::rename(tmp, link);
} catch (fs::filesystem_error & e) {
if (e.code() == std::errc::file_exists) continue;
throw SysError("renaming '%1%' to '%2%'", tmp, link);
}

fs::rename(tmp, link);

break;
}
Expand Down

0 comments on commit c573d50

Please sign in to comment.