Fix renaming operation

This commit is contained in:
Weitheng Haw 2025-01-28 15:20:12 +00:00
parent 639d2bdea7
commit 39fbd8a76f
3 changed files with 12 additions and 6 deletions

View File

@ -125,10 +125,14 @@ def deregister_faces(request: Request, name: str, body: dict = None):
)
try:
if os.path.exists(face_dir) and not os.listdir(face_dir):
os.rmdir(face_dir)
if os.path.exists(face_dir):
shutil.rmtree(face_dir)
except Exception as e:
logger.error(f"Failed to remove directory {face_dir}: {str(e)}")
return JSONResponse(
content=({"success": False, "message": f"Failed to remove directory: {str(e)}"}),
status_code=500,
)
return JSONResponse(
content=({"success": True, "message": "Successfully deleted faces."}),

View File

@ -6,6 +6,7 @@ import logging
import os
import random
import string
import shutil
from typing import Optional
import cv2
@ -448,8 +449,8 @@ class FaceProcessor(RealTimeProcessorApi):
"success": False,
}
# Rename the directory
os.rename(old_folder, new_folder)
shutil.copytree(old_folder, new_folder)
shutil.rmtree(old_folder)
# Clear and rebuild classifier with new names
self.__clear_classifier()

View File

@ -210,7 +210,8 @@ export default function FaceLibrary() {
ids: images.length ? images : ['dummy']
});
setRenameDialog(false);
await refreshFaces(); // Wait for refresh
setPageToggle(faces[0]);
await refreshFaces();
toast.success("Successfully deleted face", { position: "top-center" });
} catch (error) {
const axiosError = error as AxiosError<{ message: string }>;
@ -219,7 +220,7 @@ export default function FaceLibrary() {
{ position: "top-center" }
);
}
}, [renameData.oldName, faceData, refreshFaces]);
}, [renameData.oldName, faceData, refreshFaces, faces, setPageToggle]);
if (!config) {
return <ActivityIndicator />;