mirror of
https://github.com/valitydev/salt.git
synced 2024-11-09 01:36:48 +00:00
Add salt.fileserver.svnfs.clear_lock()
This commit is contained in:
parent
48b0977e01
commit
537a78ec5c
@ -257,6 +257,52 @@ def clear_cache():
|
||||
return errors
|
||||
|
||||
|
||||
def clear_lock(remote=None):
|
||||
'''
|
||||
Clear update.lk
|
||||
'''
|
||||
def _add_error(errlist, url, lk_fn, exc):
|
||||
errlist.append('Unable to remove update lock for {0} ({1}): {2} '
|
||||
.format(url, lk_fn, exc))
|
||||
|
||||
cleared = []
|
||||
errors = []
|
||||
for repo in init():
|
||||
if remote:
|
||||
try:
|
||||
if remote not in repo['url']:
|
||||
continue
|
||||
except TypeError:
|
||||
# remote was non-string, try again
|
||||
if _text_type(remote) not in repo['url']:
|
||||
continue
|
||||
lk_fn = _update_lockfile(repo)
|
||||
if os.path.exists(lk_fn):
|
||||
try:
|
||||
os.remove(lk_fn)
|
||||
except OSError as exc:
|
||||
if exc.errno == errno.EISDIR:
|
||||
# Somehow this path is a directory. Should never happen
|
||||
# unless some wiseguy manually creates a directory at this
|
||||
# path, but just in case, handle it.
|
||||
try:
|
||||
shutil.rmtree(lk_fn)
|
||||
except OSError as exc:
|
||||
_add_error(errors, repo['url'], lk_fn, exc)
|
||||
else:
|
||||
_add_error(errors, repo['url'], lk_fn, exc)
|
||||
else:
|
||||
cleared.append('Removed lock for {0}'.format(repo['url']))
|
||||
return cleared, errors
|
||||
|
||||
|
||||
def _update_lockfile(repo):
|
||||
'''
|
||||
Return the filename of the update lock
|
||||
'''
|
||||
return os.path.join(repo['repo'], 'update.lk')
|
||||
|
||||
|
||||
def update():
|
||||
'''
|
||||
Execute an svn update on all of the repos
|
||||
@ -267,7 +313,17 @@ def update():
|
||||
pid = os.getpid()
|
||||
data['changed'] = _clear_old_remotes()
|
||||
for repo in init():
|
||||
lk_fn = os.path.join(repo['repo'], 'update.lk')
|
||||
lk_fn = _update_lockfile(repo)
|
||||
if os.path.exists(lk_fn):
|
||||
log.warning(
|
||||
'Update lockfile is present for svn remote {0}, skipping. '
|
||||
'If this warning persists, it is possible that the update '
|
||||
'process was interrupted. Removing {1} or running '
|
||||
'\'salt-run fileserver.clear_lock backend=svn\' will allow '
|
||||
'updates to continue for this remote.'
|
||||
.format(repo['url'], lk_fn)
|
||||
)
|
||||
continue
|
||||
with salt.utils.fopen(lk_fn, 'w+') as fp_:
|
||||
fp_.write(str(pid))
|
||||
old_rev = _rev(repo)
|
||||
|
Loading…
Reference in New Issue
Block a user