Skip to content

Commit

Permalink
Fix in SquashFSArchive._add #248 (#306)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Kirill888 committed Jan 21, 2024
1 parent 85e21dc commit d3e2f31
Show file tree
Hide file tree
Showing 2 changed files with 26 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
20 changes: 20 additions & 0 deletions news/306-fix-hard-link-failure
@@ -0,0 +1,20 @@
### Enhancements

* <news item>

### Bug fixes

* In `SquashFSArchive._add` use copy instead of hard-link when source and
destination do not share file ownership (#248).

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>

0 comments on commit d3e2f31

Please sign in to comment.