Skip to content

Commit

Permalink
Fix in SquashFSArchive._add conda#248
Browse files Browse the repository at this point in the history
Can not create hard-link on Linux when source file is owned by root but
conda-pack runs as non-root user.
  • Loading branch information
Kirill888 committed Jan 18, 2024
1 parent 85e21dc commit ff3e947
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions conda_pack/formats.py
Expand Up @@ -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)
Expand Down

0 comments on commit ff3e947

Please sign in to comment.