Fix clean operation in fetch_sources.py
authorBoris Zanin <boris.zanin@mobica.com>
Mon, 4 Sep 2017 11:04:42 +0000 (13:04 +0200)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Mon, 11 Sep 2017 08:45:43 +0000 (04:45 -0400)
Running fetch_sources.py with --clean parameter under Windows causes
script to fail, due to git creates files read only in following
folder: ".git\\objects\\pack\\*".

The fix now removes readonly files first, then the whole tree.

Components: Framework

VK-GL-CTS Issue: 661

Change-Id: I5f739405a090708d76642bdb4fa3623a25bd1dc7

external/fetch_sources.py

index 98d1aa8..cd74622 100644 (file)
@@ -28,6 +28,7 @@ import hashlib
 import argparse
 import subprocess
 import ssl
+import stat
 
 sys.path.append(os.path.join(os.path.dirname(__file__), "..", "scripts"))
 
@@ -38,6 +39,10 @@ EXTERNAL_DIR = os.path.realpath(os.path.normpath(os.path.dirname(__file__)))
 def computeChecksum (data):
        return hashlib.sha256(data).hexdigest()
 
+def onReadonlyRemoveError (func, path, exc_info):
+       os.chmod(path, stat.S_IWRITE)
+       os.unlink(path)
+
 class Source:
        def __init__(self, baseDir, extractDir):
                self.baseDir            = baseDir
@@ -45,6 +50,10 @@ class Source:
 
        def clean (self):
                fullDstPath = os.path.join(EXTERNAL_DIR, self.baseDir, self.extractDir)
+               # Remove read-only first
+               readonlydir = os.path.join(fullDstPath, ".git", "objects", "pack")
+               if os.path.exists(readonlydir):
+                       shutil.rmtree(readonlydir, onerror = onReadonlyRemoveError )
                if os.path.exists(fullDstPath):
                        shutil.rmtree(fullDstPath, ignore_errors=False)