permanent delete folders fix

This commit is contained in:
2025-05-27 11:55:54 +02:00
parent f0a2f28f8e
commit 3e3451adda
2 changed files with 11 additions and 0 deletions

View File

@@ -676,7 +676,18 @@ def delete_permanent(room_id):
if rf.type == 'file': if rf.type == 'file':
os.remove(file_path) os.remove(file_path)
elif rf.type == 'folder': elif rf.type == 'folder':
# For folders, we need to delete all contents recursively
shutil.rmtree(file_path) shutil.rmtree(file_path)
# Also delete all database records for files and subfolders
folder_path = os.path.join(rf.path, rf.name) if rf.path else rf.name
contained_items = RoomFile.query.filter(
RoomFile.room_id == room_id,
RoomFile.path.like(f"{folder_path}%")
).all()
for item in contained_items:
db.session.delete(item)
except Exception as e: except Exception as e:
print(f"Error deleting {rf.type} from storage: {e}") print(f"Error deleting {rf.type} from storage: {e}")