mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #44699 from jfindlay/attr_file
utils/files.py remove temp file upon move failure
This commit is contained in:
commit
97e0cf569c
1 changed files with 20 additions and 5 deletions
|
@ -26,6 +26,16 @@ REMOTE_PROTOS = ('http', 'https', 'ftp', 'swift', 's3')
|
|||
VALID_PROTOS = ('salt', 'file') + REMOTE_PROTOS
|
||||
|
||||
|
||||
def __clean_tmp(tmp):
|
||||
'''
|
||||
Remove temporary files
|
||||
'''
|
||||
try:
|
||||
salt.utils.rm_rf(tmp)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def guess_archive_type(name):
|
||||
'''
|
||||
Guess an archive type (tar, zip, or rar) by its file extension
|
||||
|
@ -93,7 +103,15 @@ def copyfile(source, dest, backup_mode='', cachedir=''):
|
|||
fstat = os.stat(dest)
|
||||
except OSError:
|
||||
pass
|
||||
shutil.move(tgt, dest)
|
||||
|
||||
# The move could fail if the dest has xattr protections, so delete the
|
||||
# temp file in this case
|
||||
try:
|
||||
shutil.move(tgt, dest)
|
||||
except Exception:
|
||||
__clean_tmp(tgt)
|
||||
raise
|
||||
|
||||
if fstat is not None:
|
||||
os.chown(dest, fstat.st_uid, fstat.st_gid)
|
||||
os.chmod(dest, fstat.st_mode)
|
||||
|
@ -111,10 +129,7 @@ def copyfile(source, dest, backup_mode='', cachedir=''):
|
|||
subprocess.call(cmd, stdout=dev_null, stderr=dev_null)
|
||||
if os.path.isfile(tgt):
|
||||
# The temp file failed to move
|
||||
try:
|
||||
os.remove(tgt)
|
||||
except Exception:
|
||||
pass
|
||||
__clean_tmp(tgt)
|
||||
|
||||
|
||||
def rename(src, dst):
|
||||
|
|
Loading…
Add table
Reference in a new issue