core (memory): fixed recursive file deletion + log an error and continue when deleting a missing file
This commit is contained in:
parent
9f9a6a5a2b
commit
4e48a889c0
1 changed files with 10 additions and 2 deletions
|
|
@ -1555,7 +1555,12 @@ class Memory(object):
|
||||||
raise exceptions.DataError(_("Can't delete directory, it is not empty"))
|
raise exceptions.DataError(_("Can't delete directory, it is not empty"))
|
||||||
# we first delete the sub-files
|
# we first delete the sub-files
|
||||||
for sub_file_data in sub_files:
|
for sub_file_data in sub_files:
|
||||||
yield self._deleteFile(client, peer_jid, recursive, sub_file_data)
|
if sub_file_data['type'] == C.FILE_TYPE_DIRECTORY:
|
||||||
|
sub_file_path = files_path / sub_file_data['name']
|
||||||
|
else:
|
||||||
|
sub_file_path = files_path
|
||||||
|
yield self._deleteFile(
|
||||||
|
client, peer_jid, recursive, sub_file_path, sub_file_data)
|
||||||
# then the directory itself
|
# then the directory itself
|
||||||
yield self.storage.fileDelete(file_data['id'])
|
yield self.storage.fileDelete(file_data['id'])
|
||||||
elif file_data['type'] == C.FILE_TYPE_FILE:
|
elif file_data['type'] == C.FILE_TYPE_FILE:
|
||||||
|
|
@ -1570,7 +1575,10 @@ class Memory(object):
|
||||||
file_path = os.path.join(files_path, file_data['file_hash'])
|
file_path = os.path.join(files_path, file_data['file_hash'])
|
||||||
log.info(_("no reference left to {file_path}, deleting").format(
|
log.info(_("no reference left to {file_path}, deleting").format(
|
||||||
file_path=file_path))
|
file_path=file_path))
|
||||||
os.unlink(file_path)
|
try:
|
||||||
|
os.unlink(file_path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
log.error(f"file at {file_path!r} doesn't exist but it was referenced in files database")
|
||||||
else:
|
else:
|
||||||
raise exceptions.InternalError('Unexpected file type: {file_type}'
|
raise exceptions.InternalError('Unexpected file type: {file_type}'
|
||||||
.format(file_type=file_data['type']))
|
.format(file_type=file_data['type']))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue