From d3e2f315ca77146fdc97c6d319781eaa09da17c2 Mon Sep 17 00:00:00 2001 From: Kirill Kouzoubov Date: Sun, 21 Jan 2024 21:17:08 +1100 Subject: [PATCH] Fix in SquashFSArchive._add #248 (#306) * 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. * Add news file for pr 306 --- conda_pack/formats.py | 8 ++++++-- news/306-fix-hard-link-failure | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 news/306-fix-hard-link-failure 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) diff --git a/news/306-fix-hard-link-failure b/news/306-fix-hard-link-failure new file mode 100644 index 0000000..7a121fb --- /dev/null +++ b/news/306-fix-hard-link-failure @@ -0,0 +1,20 @@ +### Enhancements + +* + +### Bug fixes + +* In `SquashFSArchive._add` use copy instead of hard-link when source and +destination do not share file ownership (#248). + +### Deprecations + +* + +### Docs + +* + +### Other + +*