From 82e7cc5c739249cce6024c11f23b0746071e4505 Mon Sep 17 00:00:00 2001 From: David Lai Date: Sun, 20 Sep 2020 04:43:27 +0800 Subject: [PATCH 1/5] use instance method --- src/rezplugins/build_process/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rezplugins/build_process/local.py b/src/rezplugins/build_process/local.py index 83dfc8683..2c2091fbc 100644 --- a/src/rezplugins/build_process/local.py +++ b/src/rezplugins/build_process/local.py @@ -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) From ef3f8700bff34c0892e54005c2ccdbf5659bdca5 Mon Sep 17 00:00:00 2001 From: David Lai Date: Sun, 20 Sep 2020 04:53:46 +0800 Subject: [PATCH 2/5] improved rmtree error handler --- src/rez/utils/filesystem.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/rez/utils/filesystem.py b/src/rez/utils/filesystem.py index 2d82089a1..85b6d8f5d 100644 --- a/src/rez/utils/filesystem.py +++ b/src/rez/utils/filesystem.py @@ -23,6 +23,14 @@ from rez.utils.platform_ import platform_ +try: + unicode # PY2 +except NameError: + unicode = str + +Is_Windows = platform.system() == "Windows" + + class TempDirs(object): """Tempdir manager. @@ -210,14 +218,27 @@ 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 + """ + patch = windows_long_path if Is_Windows else lambda _p: _p + path = unicode(path) + def _on_error(func, path, exc_info): try: + path = patch(path) parent_path = os.path.dirname(path) if parent_path != path and not os.access(parent_path, os.W_OK): st = os.stat(parent_path) os.chmod(parent_path, st.st_mode | stat.S_IWUSR) + else: + st = os.stat(path) + os.chmod(path, st.st_mode | stat.S_IWUSR) + except: # avoid confusion by ensuring original exception is reraised pass @@ -651,6 +672,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 From bbf1ea58ca516f4809ffb5158d3a3f640a5a8a92 Mon Sep 17 00:00:00 2001 From: David Lai Date: Sun, 20 Sep 2020 04:55:11 +0800 Subject: [PATCH 3/5] use forceful_rmtree to clean build/install dir --- src/rezplugins/build_process/local.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rezplugins/build_process/local.py b/src/rezplugins/build_process/local.py index 2c2091fbc..50dd665f0 100644 --- a/src/rezplugins/build_process/local.py +++ b/src/rezplugins/build_process/local.py @@ -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 @@ -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) From adb035795109dd9375c79920967abe5925ef422e Mon Sep 17 00:00:00 2001 From: ajohns Date: Tue, 6 Oct 2020 10:24:55 +1100 Subject: [PATCH 4/5] -some simplifications --- src/rez/utils/filesystem.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/rez/utils/filesystem.py b/src/rez/utils/filesystem.py index 85b6d8f5d..525c85ec1 100644 --- a/src/rez/utils/filesystem.py +++ b/src/rez/utils/filesystem.py @@ -23,12 +23,7 @@ from rez.utils.platform_ import platform_ -try: - unicode # PY2 -except NameError: - unicode = str - -Is_Windows = platform.system() == "Windows" +is_windows = platform.system() == "Windows" class TempDirs(object): @@ -222,22 +217,20 @@ def forceful_rmtree(path): Also handled: * path length over 259 char (on Windows) * unicode path - """ - patch = windows_long_path if Is_Windows else lambda _p: _p - path = unicode(path) + if six.PY2: + path = unicode(path) def _on_error(func, path, exc_info): try: - path = patch(path) + 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) - else: - st = os.stat(path) - os.chmod(path, st.st_mode | stat.S_IWUSR) except: # avoid confusion by ensuring original exception is reraised From 785f424eb01e000c7c886d13294a31d8885d98c8 Mon Sep 17 00:00:00 2001 From: ajohns Date: Tue, 6 Oct 2020 10:31:05 +1100 Subject: [PATCH 5/5] version, changelog update --- CHANGELOG.md | 7 +++++++ src/rez/utils/_version.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3308e6b49..7460d2d38 100644 --- a/CHANGELOG.md +++ b/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) diff --git a/src/rez/utils/_version.py b/src/rez/utils/_version.py index a2e295013..526f8c8de 100644 --- a/src/rez/utils/_version.py +++ b/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.