[PATCH] D57533: lit: support long paths on Windows

Saleem Abdulrasool via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 31 12:20:03 PST 2019


compnerd updated this revision to Diff 184566.
compnerd added a comment.

comments, error handling, context


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57533/new/

https://reviews.llvm.org/D57533

Files:
  utils/lit/lit/TestRunner.py


Index: utils/lit/lit/TestRunner.py
===================================================================
--- utils/lit/lit/TestRunner.py
+++ utils/lit/lit/TestRunner.py
@@ -607,7 +607,19 @@
                 if not recursive:
                     stderr.write("Error: %s is a directory\n" % path)
                     exitCode = 1
-                shutil.rmtree(path, onerror = on_rm_error if force else None)
+                if platform.system() == 'Windows':
+                    # NOTE: use ctypes to access `RemoveDirectoryW` on Windows
+                    # to use the NT style path to get access to long file paths
+                    # which cannot be removed otherwise.  On python 2.7,
+                    # `shutil.rmtree` is backed by `RemoveDirectoryA` which does
+                    # not support the NT style path, so we must resort to the
+                    # ctypes import.
+                    import ctypes
+                    path = os.path.abspath(path)
+                    if not ctypes.windll.kernel32.RemoveDirectoryW(r'\\?\%s' % path):
+                        raise ctypes.WinError()
+                else:
+                    shutil.rmtree(path, onerror = on_rm_error if force else None)
             else:
                 if force and not os.access(path, os.W_OK):
                     os.chmod(path,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57533.184566.patch
Type: text/x-patch
Size: 1335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190131/e62c6a7c/attachment.bin>


More information about the llvm-commits mailing list