1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 13:21:47 +02:00

Merge pull request #11959 from Mic92/better-errors

more readable errors if symlinks cannot be created
This commit is contained in:
Eelco Dolstra 2024-11-26 18:06:27 +01:00 committed by GitHub
commit d0f84fd2a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 6 deletions

View file

@ -602,7 +602,11 @@ std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix)
void createSymlink(const Path & target, const Path & link) void createSymlink(const Path & target, const Path & link)
{ {
try {
fs::create_symlink(target, link); fs::create_symlink(target, link);
} catch (fs::filesystem_error & e) {
throw SysError("creating symlink '%1%' -> '%2%'", link, target);
}
} }
void replaceSymlink(const fs::path & target, const fs::path & link) void replaceSymlink(const fs::path & target, const fs::path & link)
@ -615,10 +619,16 @@ void replaceSymlink(const fs::path & target, const fs::path & link)
fs::create_symlink(target, tmp); fs::create_symlink(target, tmp);
} catch (fs::filesystem_error & e) { } catch (fs::filesystem_error & e) {
if (e.code() == std::errc::file_exists) continue; if (e.code() == std::errc::file_exists) continue;
throw; throw SysError("creating symlink '%1%' -> '%2%'", tmp, target);
} }
try {
fs::rename(tmp, link); 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);
}
break; break;
} }

View file

@ -250,8 +250,6 @@ void setWriteTime(const std::filesystem::path & path, const struct stat & st);
/** /**
* Create a symlink. * Create a symlink.
* *
* In the process of being deprecated for
* `std::filesystem::create_symlink`.
*/ */
void createSymlink(const Path & target, const Path & link); void createSymlink(const Path & target, const Path & link);

View file

@ -937,7 +937,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
} }
continue; continue;
} else } else
fs::create_symlink(target, to2); createSymlink(target, to2);
} }
else else
throw Error("file '%s' has unsupported type", from2); throw Error("file '%s' has unsupported type", from2);