Skip to content

Commit

Permalink
Only try to chmod /nix/var/nix/profiles/per-user when necessary
Browse files Browse the repository at this point in the history
Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
  • Loading branch information
SuperSandro2000 and edolstra committed Feb 11, 2025
1 parent d949c8d commit dcbf4dc
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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);
}
}
Expand Down

0 comments on commit dcbf4dc

Please sign in to comment.