Windows decompression: fix removal of intermediate file (#38958)
Extensionless archives requiring two-stage decompression and extraction require intermediate archives to be renamed after decompression/extraction to prevent collision. Prior behavior attempted to cleanup the intermediate archive with the original name, this PR ensures the renamed folder is cleaned instead. Co-authored-by: Dan Lipsa <dan.lipsa@khq.kitware.com> Co-authored-by: John Parent <john.parent@kitware.com>
This commit is contained in:
		| @@ -70,7 +70,7 @@ def allowed_archive(path): | |||||||
|     return False if not path else any(path.endswith(t) for t in ALLOWED_ARCHIVE_TYPES) |     return False if not path else any(path.endswith(t) for t in ALLOWED_ARCHIVE_TYPES) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _system_untar(archive_file): | def _system_untar(archive_file, remove_archive_file=False): | ||||||
|     """Returns path to unarchived tar file. |     """Returns path to unarchived tar file. | ||||||
|     Untars archive via system tar. |     Untars archive via system tar. | ||||||
| 
 | 
 | ||||||
| @@ -89,6 +89,11 @@ def _system_untar(archive_file): | |||||||
|     tar = which("tar", required=True) |     tar = which("tar", required=True) | ||||||
|     tar.add_default_arg("-oxf") |     tar.add_default_arg("-oxf") | ||||||
|     tar(archive_file) |     tar(archive_file) | ||||||
|  |     if remove_archive_file: | ||||||
|  |         # remove input file to prevent two stage | ||||||
|  |         # extractions from being treated as exploding | ||||||
|  |         # archives by the fetcher | ||||||
|  |         os.remove(archive_file) | ||||||
|     return outfile |     return outfile | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @@ -243,13 +248,9 @@ def _win_compressed_tarball_handler(decompressor): | |||||||
|     def unarchive(archive_file): |     def unarchive(archive_file): | ||||||
|         # perform intermediate extraction step |         # perform intermediate extraction step | ||||||
|         # record name of new archive so we can extract |         # record name of new archive so we can extract | ||||||
|         # and later clean up |  | ||||||
|         decomped_tarball = decompressor(archive_file) |         decomped_tarball = decompressor(archive_file) | ||||||
|         # run tar on newly decomped archive |         # run tar on newly decomped archive | ||||||
|         outfile = _system_untar(decomped_tarball) |         outfile = _system_untar(decomped_tarball, remove_archive_file=True) | ||||||
|         # clean intermediate archive to mimic end result |  | ||||||
|         # produced by one shot decomp/extraction |  | ||||||
|         os.remove(decomped_tarball) |  | ||||||
|         return outfile |         return outfile | ||||||
| 
 | 
 | ||||||
|     return unarchive |     return unarchive | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Dan Lipsa
					Dan Lipsa