Skip to content

Commit

Permalink
Merge branch 'davidlatwe-handle_dir_remove_err_in_build'
Browse files Browse the repository at this point in the history
  • Loading branch information
ajohns committed Oct 5, 2020
2 parents abbd181 + 785f424 commit b215165
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,12 @@
# Change Log

## 2.68.5 (2020-10-06)
[Source](https://github.com/nerdvegas/rez/tree/2.68.5) | [Diff](https://github.com/nerdvegas/rez/compare/2.68.4...2.68.5)

**Merged pull requests:**

- Handling build/install directory remove error in build process [\#959](https://github.com/nerdvegas/rez/pull/959) ([davidlatwe](https://github.com/davidlatwe))

## 2.68.4 (2020-10-06)
[Source](https://github.com/nerdvegas/rez/tree/2.68.4) | [Diff](https://github.com/nerdvegas/rez/compare/2.68.3...2.68.4)

Expand Down
2 changes: 1 addition & 1 deletion src/rez/utils/_version.py
@@ -1,7 +1,7 @@


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


# Copyright 2013-2016 Allan Johns.
Expand Down
31 changes: 30 additions & 1 deletion src/rez/utils/filesystem.py
Expand Up @@ -23,6 +23,9 @@
from rez.utils.platform_ import platform_


is_windows = platform.system() == "Windows"


class TempDirs(object):
"""Tempdir manager.
Expand Down Expand Up @@ -210,14 +213,25 @@ def forceful_rmtree(path):
Specifically, non-writable dirs within `path` can cause rmtree to fail. This
func chmod's to writable to avoid this issue, if possible.
Also handled:
* path length over 259 char (on Windows)
* unicode path
"""
if six.PY2:
path = unicode(path)

def _on_error(func, path, exc_info):
try:
if is_windows:
path = windows_long_path(path)

parent_path = os.path.dirname(path)

if parent_path != path and not os.access(parent_path, os.W_OK):
if not os.access(parent_path, os.W_OK):
st = os.stat(parent_path)
os.chmod(parent_path, st.st_mode | stat.S_IWUSR)

except:
# avoid confusion by ensuring original exception is reraised
pass
Expand Down Expand Up @@ -651,6 +665,21 @@ def walk_up_dirs(path):
current_path = os.path.dirname(prev_path)


def windows_long_path(dos_path):
"""Prefix '\\?\' for path longer than 259 char (Win32API limitation)
"""
path = os.path.abspath(dos_path)

if path.startswith("\\\\?\\"):
pass
elif path.startswith("\\\\"):
path = "\\\\?\\UNC\\" + path[2:]
else:
path = "\\\\?\\" + path

return path


# Copyright 2013-2016 Allan Johns.
#
# This library is free software: you can redistribute it and/or
Expand Down
6 changes: 3 additions & 3 deletions src/rezplugins/build_process/local.py
Expand Up @@ -11,7 +11,7 @@
from rez.utils.base26 import create_unique_base26_symlink
from rez.utils.colorize import Printer, warning
from rez.utils.filesystem import safe_makedirs, copy_or_replace, \
make_path_writable, get_existing_path
make_path_writable, get_existing_path, forceful_rmtree
from rez.utils.sourcecode import IncludeModuleManager
from rez.utils.filesystem import TempDirs
from rez.package_test import PackageTestRunner, PackageTestResults
Expand Down Expand Up @@ -142,7 +142,7 @@ def _build_variant_base(self, variant, build_type, install_path=None,

# create directories (build, install)
if clean and os.path.exists(variant_build_path):
shutil.rmtree(variant_build_path)
self._rmtree(variant_build_path)

safe_makedirs(variant_build_path)

Expand Down Expand Up @@ -308,7 +308,7 @@ def _install_include_modules(self, install_path):

def _rmtree(self, path):
try:
shutil.rmtree(path)
forceful_rmtree(path)
except Exception as e:
print_warning("Failed to delete %s - %s", path, e)

Expand Down

0 comments on commit b215165

Please sign in to comment.