[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.
diff --git a/libcxx/utils/ssh.py b/libcxx/utils/ssh.py
index e23f795..c7d8c97 100644
--- a/libcxx/utils/ssh.py
+++ b/libcxx/utils/ssh.py
@@ -60,7 +60,8 @@
# 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 @@
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 = [