From ff3e947a2916402fe75db1b488ab5c265853dbed Mon Sep 17 00:00:00 2001 From: Kirill Kouzoubov Date: Thu, 18 Jan 2024 17:13:58 +1100 Subject: [PATCH] Fix in SquashFSArchive._add #248 Can not create hard-link on Linux when source file is owned by root but conda-pack runs as non-root user. --- conda_pack/formats.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/conda_pack/formats.py b/conda_pack/formats.py index 806d725..91a5653 100644 --- a/conda_pack/formats.py +++ b/conda_pack/formats.py @@ -439,8 +439,12 @@ def _add(self, source, target): self._ensure_parent(target_abspath) # hardlink instead of copy is faster, but it doesn't work across devices - same_device = os.lstat(source).st_dev == os.lstat(os.path.dirname(target_abspath)).st_dev - if same_device: + source_stat = os.lstat(source) + target_stat = os.lstat(os.path.dirname(target_abspath)) + same_device = source_stat.st_dev == target_stat.st_dev + same_user = source_stat.st_uid == target_stat.st_uid + + if same_device and same_user: copy_func = partial(os.link, follow_symlinks=False) else: copy_func = partial(shutil.copy2, follow_symlinks=False)