From fefa66880a47fdb7c6230ad6bc626086946b6a1a Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 29 Jan 2026 19:44:33 -0500 Subject: [PATCH] Remove suppport for not having `lchown` Linux, macOS, and all 3 BSDs have it (according to man page google search), so let's just drop this. Support for not having it was added in d03f0d411740aebd5b27e5a1ac57d8533843ff6b in 2006, things have changed in the last 20 years! --- src/libexpr/meson.build | 2 +- src/libstore/meson.build | 4 +--- src/libstore/posix-fs-canonicalise.cc | 23 +---------------------- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index 18c4c7fa32c..a98319e4af1 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -28,7 +28,7 @@ deps_public_maybe_subproject = [ subdir('nix-meson-build-support/subprojects') subdir('nix-meson-build-support/big-objs') -# Check for each of these functions, and create a define like `#define HAVE_LCHOWN 1`. +# Check for each of these functions, and create a define like `#define HAVE_SYSCONF 1`. check_funcs = [ 'sysconf', ] diff --git a/src/libstore/meson.build b/src/libstore/meson.build index 3bd4796b73e..4d9b22f56f9 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -68,10 +68,8 @@ endif summary('can hardlink to symlink', can_link_symlink, bool_yn : true) configdata_priv.set('CAN_LINK_SYMLINK', can_link_symlink.to_int()) -# Check for each of these functions, and create a define like `#define HAVE_LCHOWN 1`. +# Check for each of these functions, and create a define like `#define HAVE_POSIX_FALLOCATE 1`. check_funcs = [ - # Optionally used for canonicalising files from the build - 'lchown', 'posix_fallocate', 'statvfs', ] diff --git a/src/libstore/posix-fs-canonicalise.cc b/src/libstore/posix-fs-canonicalise.cc index fe1d0031622..7af63755e5d 100644 --- a/src/libstore/posix-fs-canonicalise.cc +++ b/src/libstore/posix-fs-canonicalise.cc @@ -107,19 +107,9 @@ canonicalisePathMetaData_(const Path & path, CanonicalizePathMetadataOptions opt canonicaliseTimestampAndPermissions(path, st); #ifndef _WIN32 - /* Change ownership to the current uid. If it's a symlink, use - lchown if available, otherwise don't bother. Wrong ownership - of a symlink doesn't matter, since the owning user can't change - the symlink and can't delete it because the directory is not - writable. The only exception is top-level paths in the Nix - store (since that directory is group-writable for the Nix build - users group); we check for this case below. */ + /* Change ownership to the current uid. */ if (st.st_uid != geteuid()) { -# if HAVE_LCHOWN if (lchown(path.c_str(), geteuid(), getegid()) == -1) -# else - if (!S_ISLNK(st.st_mode) && chown(path.c_str(), geteuid(), getegid()) == -1) -# endif throw SysError("changing owner of '%1%' to %2%", path, geteuid()); } #endif @@ -135,17 +125,6 @@ canonicalisePathMetaData_(const Path & path, CanonicalizePathMetadataOptions opt void canonicalisePathMetaData(const Path & path, CanonicalizePathMetadataOptions options, InodesSeen & inodesSeen) { canonicalisePathMetaData_(path, options, inodesSeen); - -#ifndef _WIN32 - /* On platforms that don't have lchown(), the top-level path can't - be a symlink, since we can't change its ownership. */ - auto st = lstat(path); - - if (st.st_uid != geteuid()) { - assert(S_ISLNK(st.st_mode)); - throw Error("wrong ownership of top-level store path '%1%'", path); - } -#endif } void canonicalisePathMetaData(const Path & path, CanonicalizePathMetadataOptions options)