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

Merge pull request #12535 from NixOS/mergify/bp/2.24-maintenance/pr-12391

Only try to chmod /nix/var/nix/profiles/per-user when necessary (backport #12391)
This commit is contained in:
mergify[bot] 2025-02-20 16:55:38 +00:00 committed by GitHub
commit 79828c12e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -233,7 +233,12 @@ LocalStore::LocalStore(
for (auto & perUserDir : {profilesDir + "/per-user", gcRootsDir + "/per-user"}) {
createDirs(perUserDir);
if (!readOnly) {
if (chmod(perUserDir.c_str(), 0755) == -1)
auto st = lstat(perUserDir);
// Skip chmod call if the directory already has the correct permissions (0755).
// This is to avoid failing when the executing user lacks permissions to change the directory's permissions
// even if it would be no-op.
if ((st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) != 0755 && chmod(perUserDir.c_str(), 0755) == -1)
throw SysError("could not set permissions on '%s' to 755", perUserDir);
}
}