changeset 3300:b56e4c6b13fc

core (memory): fixed recursive file deletion + log an error and continue when deleting a missing file
author Goffi <goffi@goffi.org>
date Fri, 19 Jun 2020 14:55:30 +0200
parents 83795ff8a633
children 9d1c0feba048
files sat/memory/memory.py
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/sat/memory/memory.py	Tue Jun 09 06:25:20 2020 +0200
+++ b/sat/memory/memory.py	Fri Jun 19 14:55:30 2020 +0200
@@ -1555,7 +1555,12 @@
                 raise exceptions.DataError(_("Can't delete directory, it is not empty"))
             # we first delete the 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
             yield self.storage.fileDelete(file_data['id'])
         elif file_data['type'] == C.FILE_TYPE_FILE:
@@ -1570,7 +1575,10 @@
                 file_path = os.path.join(files_path, file_data['file_hash'])
                 log.info(_("no reference left to {file_path}, deleting").format(
                     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:
             raise exceptions.InternalError('Unexpected file type: {file_type}'
                 .format(file_type=file_data['type']))