unlink target if move failed

This commit is contained in:
j 2019-01-13 00:28:01 +05:30
parent 3d1a629970
commit a01e574a8f
1 changed files with 2 additions and 0 deletions

View File

@ -797,6 +797,8 @@ class File(db.Model):
shutil.move(current_path, path)
except:
logger.debug('failed to move %s to %s', current_path, path, exc_info=True)
if os.path.exists(path) and os.path.exists(current_path):
os.unlink(path)
return
self.path = new_path
self.save()