Add overwrite option so the extraction of the archive can be always performed.

This commit is contained in:
Bo Maryniuk 2016-11-24 19:06:20 +01:00
parent e6958f7f15
commit 91b42578b2

View file

@ -12,6 +12,7 @@ import logging
import os
import re
import shlex
import shutil
import stat
import tarfile
from contextlib import closing
@ -140,6 +141,7 @@ def extracted(name,
enforce_toplevel=True,
enforce_ownership_on=None,
archive_format=None,
overwrite=False,
**kwargs):
'''
.. versionadded:: 2014.1.0
@ -497,6 +499,10 @@ def extracted(name,
.. _zipfile: https://docs.python.org/2/library/zipfile.html
.. _xz-utils: http://tukaani.org/xz/
overwrite
If archive was already extracted, then setting this to True will
extract it all over again.
**Examples**
1. tar with lmza (i.e. xz) compression:
@ -897,7 +903,14 @@ def extracted(name,
# already need to catch an OSError to cover edge cases where the minion is
# running as a non-privileged user and is trying to check for the existence
# of a path to which it does not have permission.
extraction_needed = False
extraction_needed = overwrite
if extraction_needed:
destination = os.path.join(name, contents['top_level_dirs'][0])
if os.path.exists(destination):
shutil.rmtree(destination)
try:
if_missing_path_exists = os.path.exists(if_missing)
except TypeError: