Skip to content

Commit

Permalink
archive.extracted: don't try to cache local sources
Browse files Browse the repository at this point in the history
This will keep us from trying to cache file when we already have it
locally, which will help significantly with larger archives.
  • Loading branch information
terminalmage committed Dec 15, 2016
1 parent 82b1b77 commit e774080
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions salt/states/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,14 @@ def extracted(name,
urlparsed_source = _urlparse(source_match)
source_hash_basename = urlparsed_source.path or urlparsed_source.netloc

source_is_local = urlparsed_source.scheme in ('', 'file')
if source_is_local:
# Get rid of "file://" from start of source_match
source_match = urlparsed_source.path
if not os.path.isfile(source_match):
ret['comment'] = 'Source file \'{0}\' does not exist'.format(source_match)
return ret

valid_archive_formats = ('tar', 'rar', 'zip')
if not archive_format:
archive_format = salt.utils.files.guess_archive_type(source_hash_basename)
Expand Down Expand Up @@ -756,16 +764,19 @@ def extracted(name,
)
return ret

cached_source = os.path.join(
__opts__['cachedir'],
'files',
__env__,
re.sub(r'[:/\\]', '_', source_hash_basename),
)
if source_is_local:
cached_source = source_match
else:
cached_source = os.path.join(
__opts__['cachedir'],
'files',
__env__,
re.sub(r'[:/\\]', '_', source_hash_basename),
)

if os.path.isdir(cached_source):
# Prevent a traceback from attempting to read from a directory path
salt.utils.rm_rf(cached_source)
if os.path.isdir(cached_source):
# Prevent a traceback from attempting to read from a directory path
salt.utils.rm_rf(cached_source)

if source_hash:
try:
Expand All @@ -787,7 +798,7 @@ def extracted(name,
else:
source_sum = {}

if not os.path.isfile(cached_source):
if not source_is_local and not os.path.isfile(cached_source):
if __opts__['test']:
ret['result'] = None
ret['comment'] = \
Expand Down Expand Up @@ -1304,7 +1315,7 @@ def extracted(name,
ret['changes']['directories_created'] = [name]
ret['changes']['extracted_files'] = files
ret['comment'] = '{0} extracted to {1}'.format(source_match, name)
if not keep:
if not source_is_local and not keep:
log.debug('Cleaning cached source file %s', cached_source)
try:
os.remove(cached_source)
Expand Down

0 comments on commit e774080

Please sign in to comment.