Merge pull request #13454 from terminalmage/issue13389

Properly handle branches/tags with slashes in name
This commit is contained in:
Thomas S Hatch 2014-06-14 07:19:48 -06:00
commit ab6c9a0f23
3 changed files with 17 additions and 17 deletions

View File

@ -89,7 +89,7 @@ def clean_fsbackend(opts):
log.debug('Clearing {0}fs env cache'.format(backend))
try:
os.remove(env_cache)
except (IOError, OSError) as exc:
except OSError as exc:
log.critical(
'Unable to clear env cache file {0}: {1}'
.format(env_cache, exc)
@ -108,7 +108,7 @@ def clean_fsbackend(opts):
cache_file = os.path.join(file_lists_dir, file_lists_cache)
try:
os.remove(cache_file)
except (IOError, OSError) as exc:
except OSError as exc:
log.critical(
'Unable to file_lists cache file {0}: {1}'
.format(cache_file, exc)

View File

@ -4,12 +4,12 @@ File server pluggable modules and generic backend functions
'''
# Import python libs
import os
import re
import errno
import fnmatch
import logging
import os
import re
import time
import errno
# Import salt libs
import salt.loader
@ -21,8 +21,8 @@ log = logging.getLogger(__name__)
def _lock_cache(w_lock):
try:
os.mkdir(w_lock)
except OSError, e:
if e.errno != errno.EEXIST:
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
return False
else:
@ -120,8 +120,8 @@ def write_file_list_cache(opts, data, list_cache, w_lock):
fp_.write(serial.dumps(data))
try:
os.rmdir(w_lock)
except OSError, e:
log.trace("Error removing lockfile {0}: {1}".format(w_lock, e))
except OSError as exc:
log.trace('Error removing lockfile {0}: {1}'.format(w_lock, exc))
log.trace('Lockfile {0} removed'.format(w_lock))

View File

@ -341,7 +341,6 @@ def _get_tree_gitpython(repo, tgt_env):
if isinstance(ref, (git.RemoteReference, git.TagReference)):
parted = ref.name.partition('/')
rspec = parted[2] if parted[2] else parted[0]
rspec = rspec.replace('/', '_')
if rspec == tgt_env:
return ref.commit.tree
@ -369,7 +368,6 @@ def _get_tree_pygit2(repo, tgt_env):
if rtype in ('remotes', 'tags'):
parted = rspec.partition('/')
rspec = parted[2] if parted[2] else parted[0]
rspec = rspec.replace('/', '_')
if rspec == tgt_env and _env_is_exposed(rspec):
return repo['repo'].lookup_reference(ref).get_object().tree
@ -399,7 +397,6 @@ def _get_tree_dulwich(repo, tgt_env):
for ref in sorted(_dulwich_env_refs(refs)):
# ref will be something like 'refs/heads/master'
rtype, rspec = ref[5:].split('/', 1)
rspec = rspec.replace('/', '_')
if rspec == tgt_env and _env_is_exposed(rspec):
if rtype == 'heads':
commit = repo['repo'].get_object(refs[ref])
@ -919,7 +916,6 @@ def _envs_gitpython(repo):
for ref in repo['repo'].refs:
parted = ref.name.partition('/')
rspec = parted[2] if parted[2] else parted[0]
rspec = rspec.replace('/', '_')
if isinstance(ref, git.Head):
if rspec == repo['base']:
rspec = 'base'
@ -944,7 +940,6 @@ def _envs_pygit2(repo):
if rspec not in stale_refs:
parted = rspec.partition('/')
rspec = parted[2] if parted[2] else parted[0]
rspec = rspec.replace('/', '_')
if rspec == repo['base']:
rspec = 'base'
if _env_is_exposed(rspec):
@ -963,7 +958,6 @@ def _envs_dulwich(repo):
for ref in _dulwich_env_refs(repo['repo'].get_refs()):
# ref will be something like 'refs/heads/master'
rtype, rspec = ref[5:].split('/', 1)
rspec = rspec.replace('/', '_')
if rtype == 'heads':
if rspec == repo['base']:
rspec = 'base'
@ -1179,8 +1173,14 @@ def _file_lists(load, form):
except os.error:
log.critical('Unable to make cachedir {0}'.format(list_cachedir))
return []
list_cache = os.path.join(list_cachedir, '{0}.p'.format(load['saltenv']))
w_lock = os.path.join(list_cachedir, '.{0}.w'.format(load['saltenv']))
list_cache = os.path.join(
list_cachedir,
'{0}.p'.format(load['saltenv'].replace(os.path.sep, '_|-'))
)
w_lock = os.path.join(
list_cachedir,
'.{0}.w'.format(load['saltenv'].replace(os.path.sep, '_|-'))
)
cache_match, refresh_cache, save_cache = \
salt.fileserver.check_file_list_cache(
__opts__, form, list_cache, w_lock