-_, ar, archive, output, *pmdinfogen = sys.argv
-with tempfile.TemporaryDirectory() as temp:
- proc = subprocess.run(
- # Don't use "ar p", because its output is corrupted on Windows.
- [ar, "xv", os.path.abspath(archive)], stdout=subprocess.PIPE, check=True, cwd=temp
- )
- lines = proc.stdout.decode().splitlines()
- names = [line[len("x - ") :] for line in lines]
- paths = [os.path.join(temp, name) for name in names]
+_, tmp_root, ar, archive, output, *pmdinfogen = sys.argv
+with tempfile.TemporaryDirectory(dir=tmp_root) as temp:
+ paths = []
+ for name in subprocess.run([ar, "t", archive], stdout=subprocess.PIPE,
+ check=True).stdout.decode().splitlines():
+ if os.path.exists(name):
+ paths.append(name)
+ else:
+ subprocess.run([ar, "x", os.path.abspath(archive), name],
+ check=True, cwd=temp)
+ paths.append(os.path.join(temp, name))