fix folder rename not retaining files
This commit is contained in:
Binary file not shown.
@@ -303,6 +303,23 @@ def rename_room_file(room_id):
|
|||||||
# Update RoomFile entry
|
# Update RoomFile entry
|
||||||
rf.name = new_name
|
rf.name = new_name
|
||||||
rf.modified = os.path.getmtime(new_path)
|
rf.modified = os.path.getmtime(new_path)
|
||||||
|
|
||||||
|
# If this is a folder, update paths of all contained files and subfolders
|
||||||
|
if os.path.isdir(new_path):
|
||||||
|
old_folder_path = os.path.join(rel_path, old_name) if rel_path else old_name
|
||||||
|
new_folder_path = os.path.join(rel_path, new_name) if rel_path else new_name
|
||||||
|
|
||||||
|
# Get all files and folders that are under the old path
|
||||||
|
contained_items = RoomFile.query.filter(
|
||||||
|
RoomFile.room_id == room_id,
|
||||||
|
RoomFile.path.like(f"{old_folder_path}%")
|
||||||
|
).all()
|
||||||
|
|
||||||
|
# Update their paths
|
||||||
|
for item in contained_items:
|
||||||
|
# Replace the old folder path with the new one in the item's path
|
||||||
|
item.path = item.path.replace(old_folder_path, new_folder_path, 1)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return jsonify({'success': True, 'old_name': old_name, 'new_name': new_name})
|
return jsonify({'success': True, 'old_name': old_name, 'new_name': new_name})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user