Fix permanent delete
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -652,14 +652,16 @@ def delete_permanent(room_id):
|
||||
if not rf:
|
||||
continue
|
||||
|
||||
# Delete the file from storage if it's a file
|
||||
if rf.type == 'file':
|
||||
try:
|
||||
file_path = os.path.join(get_room_dir(room_id), rf.path, rf.name)
|
||||
if os.path.exists(file_path):
|
||||
# Delete the file/folder from storage
|
||||
try:
|
||||
file_path = os.path.join(get_room_dir(room_id), rf.path, rf.name)
|
||||
if os.path.exists(file_path):
|
||||
if rf.type == 'file':
|
||||
os.remove(file_path)
|
||||
except Exception as e:
|
||||
print(f"Error deleting file from storage: {e}")
|
||||
elif rf.type == 'folder':
|
||||
shutil.rmtree(file_path)
|
||||
except Exception as e:
|
||||
print(f"Error deleting {rf.type} from storage: {e}")
|
||||
|
||||
# Delete the database record
|
||||
db.session.delete(rf)
|
||||
|
||||
@@ -103,8 +103,25 @@ def empty_trash(room_id):
|
||||
if not user_has_permission(room, 'can_delete'):
|
||||
abort(403)
|
||||
|
||||
# Delete all trashed files for this room
|
||||
# Get all trashed files for this room
|
||||
trashed_files = TrashedFile.query.filter_by(room_id=room_id).all()
|
||||
room_files = RoomFile.query.filter_by(room_id=room_id, deleted=True).all()
|
||||
|
||||
# Delete physical files
|
||||
room_dir = os.path.join('/data/rooms', str(room_id))
|
||||
for file in trashed_files + room_files:
|
||||
try:
|
||||
if file.type == 'file':
|
||||
file_path = os.path.join(room_dir, file.original_path if hasattr(file, 'original_path') else file.path, file.name)
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
except Exception as e:
|
||||
print(f"Error deleting physical file {file.name}: {str(e)}")
|
||||
continue
|
||||
|
||||
# Delete all trashed files from both tables
|
||||
TrashedFile.query.filter_by(room_id=room_id).delete()
|
||||
RoomFile.query.filter_by(room_id=room_id, deleted=True).delete()
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({'success': True})
|
||||
Reference in New Issue
Block a user