Skip to content

Commit

Permalink
Merge pull request #552 from nerdvegas/issue_551
Browse files Browse the repository at this point in the history
Issue 551
  • Loading branch information
nerdvegas authored Dec 21, 2018
2 parents 62310f4 + 8db837f commit 9199b82
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

## 2.26.1 [[#552](https://github.com/nerdvegas/rez/pull/552)] Bugfix in Package Copy

#### Addressed Issues

* [#551](https://github.com/nerdvegas/rez/issues/551) package copy fails if symlinks in root dir

#### Notes

This was failing when symlinks were present within a non-varianted package being copied. Now, these
symlinks are retained in the target package, unless `--follow-symlinks` is specified.

## 2.26.0 [[#550](https://github.com/nerdvegas/rez/pull/550)] Build System Detection Fixes

#### Addressed Issues
Expand Down
14 changes: 6 additions & 8 deletions src/rez/package_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,13 @@ def _copy_variant_payload(src_variant, dest_pkg_repo, shallow=False,
src_variant.subpath)

# perform the copy/symlinking
copy_func = partial(replacing_copy,
follow_symlinks=follow_symlinks)

if shallow:
maybe_symlink = replacing_symlink
else:
maybe_symlink = partial(
replacing_copy,
copytree_kwargs={
"symlinks": (not follow_symlinks)
}
)
maybe_symlink = copy_func

if src_variant.subpath:
# symlink/copy the last install dir to the variant root
Expand All @@ -259,15 +257,15 @@ def _copy_variant_payload(src_variant, dest_pkg_repo, shallow=False,
else:
safe_makedirs(variant_install_path)

# copy all files, and symlink/copy all dirs within the variant
# copy all files, and symlink/copy all dirs within the null variant
for name in os.listdir(variant_root):
src_path = os.path.join(variant_root, name)
dest_path = os.path.join(variant_install_path, name)

if os.path.isdir(src_path) and not os.path.islink(src_path):
maybe_symlink(src_path, dest_path)
else:
replacing_copy(src_path, dest_path)
copy_func(src_path, dest_path)


def _copy_package_include_modules(src_package, dest_pkg_repo, overrides=None):
Expand Down
2 changes: 1 addition & 1 deletion src/rez/utils/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


# Update this value to version up Rez. Do not place anything else in this file.
_rez_version = "2.26.0"
_rez_version = "2.26.1"

try:
from rez.vendor.version.version import Version
Expand Down
17 changes: 13 additions & 4 deletions src/rez/utils/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,29 @@ def replacing_symlink(source, link_name):
replace_file_or_dir(link_name, tmp_link_name)


def replacing_copy(src, dest, copytree_kwargs=None):
def replacing_copy(src, dest, follow_symlinks=False):
"""Perform copy that overwrites any existing target.
Will copy/copytree `src` to `dest`, and will remove `dest` if it exists,
regardless of what it is.
If `follow_symlinks` is False, symlinks are preserved, otherwise their
contents are copied.
Note that this behavior is different to `shutil.copy`, which copies src
into dest if dest is an existing dir.
"""
with make_tmp_name(dest) as tmp_dest:
if os.path.isdir(src) and not os.path.islink(src):
shutil.copytree(src, tmp_dest, **(copytree_kwargs or {}))
if os.path.islink(src) and not follow_symlinks:
# special case - copy just a symlink
src_ = os.readlink(src)
os.symlink(src_, tmp_dest)
elif os.path.isdir(src):
# copy a dir
shutil.copytree(src, tmp_dest, symlinks=(not follow_symlinks))
else:
shutil.copy2(src, tmp_dest)
# copy a file
shutil.copy(src, tmp_dest)

replace_file_or_dir(dest, tmp_dest)

Expand Down

0 comments on commit 9199b82

Please sign in to comment.