[libcxx-commits] [libcxx] b00a874 - [libc++] SSH: Fix tarring of dependencies on Windows

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 6 06:58:39 PDT 2020


Author: Louis Dionne
Date: 2020-04-06T09:58:08-04:00
New Revision: b00a874b7c737119c82cc3826fd3a74a9e5405e3

URL: https://github.com/llvm/llvm-project/commit/b00a874b7c737119c82cc3826fd3a74a9e5405e3
DIFF: https://github.com/llvm/llvm-project/commit/b00a874b7c737119c82cc3826fd3a74a9e5405e3.diff

LOG: [libc++] SSH: Fix tarring of dependencies on Windows

On Windows, we must make sure to close the temporary tar file before we
try to scp it.

This is an alternative approach to https://reviews.llvm.org/D77500.

Added: 
    

Modified: 
    libcxx/utils/ssh.py

Removed: 
    


################################################################################
diff  --git a/libcxx/utils/ssh.py b/libcxx/utils/ssh.py
index e23f795b79c3..c7d8c97a1407 100644
--- a/libcxx/utils/ssh.py
+++ b/libcxx/utils/ssh.py
@@ -60,7 +60,8 @@ def main():
 
         # Ensure the test dependencies exist, tar them up and copy the tarball
         # over to the remote host.
-        with tempfile.NamedTemporaryFile(suffix='.tar') as tmpTar:
+        try:
+            tmpTar = tempfile.NamedTemporaryFile(suffix='.tar', delete=False)
             with tarfile.open(fileobj=tmpTar, mode='w') as tarball:
                 for dep in args.dependencies:
                     if not os.path.exists(dep):
@@ -68,9 +69,16 @@ def main():
                         return 1
                     tarball.add(dep, arcname=os.path.basename(dep))
 
+            # Make sure we close the file before we scp it, because accessing
+            # the temporary file while still open doesn't work on Windows.
+            tmpTar.close()
             remoteTarball = pathOnRemote(tmpTar.name)
-            tmpTar.flush()
             subprocess.check_call(scp(tmpTar.name, remoteTarball))
+        finally:
+            # Make sure we close the file in case an exception happens before
+            # we've closed it above -- otherwise close() is idempotent.
+            tmpTar.close()
+            os.remove(tmpTar.name)
 
         # Untar the dependencies in the temporary directory and remove the tarball.
         remoteCommands = [


        


More information about the libcxx-commits mailing list