oscontainer: Clean up directory on failure
Since this code gets invoked with `sudo`, if we fail in the middle
it means higher level code running as non-root can fail to clean
up the temporary files.
@@ -301,6 +301,7 @@ def main():
shutil.rmtree(tmpdir)
os.makedirs(tmpdir)
+ try:
if args.action == 'extract':
oscontainer_extract(
containers_storage, tmpdir, args.src, args.dest,
@@ -319,8 +320,8 @@ def main():
tls_verify=not args.disable_tls_verify,
cert_dir=args.cert_dir,
authfile=args.authfile)
-
- if containers_storage is not None:
+ finally:
+ if containers_storage is not None and os.path.isdir(containers_storage):
shutil.rmtree(containers_storage)
