Closed curtwagner1984 closed 3 years ago
This is an extremely serious error which has probably always existed. I am providing a fix in a few minutes. Thanks a lot for the report.
This is a quick fix, which I have also pushed to develop. It may require further testing, but my initial tests were successful.
I am going out but will test further this evening.
In videos.views.AddItems (around line 1356), modify to:
class AddItems(views.APIView):
def get(self, request, format=None):
if request.query_params["folderToAddPath"] != "":
folders_to_add_path = request.query_params["folderToAddPath"]
for folder_to_add_path in folders_to_add_path.split(","):
folder_to_add_path_stripped = folder_to_add_path.strip()
if os.path.isdir(folder_to_add_path_stripped):
# if the second argument is true - tries to make a sample video when inserting scene to db.
temp = os.path.abspath(folder_to_add_path_stripped)
try:
if platform.system() == "Windows":
for test in Folder.objects.all():
if temp.lower() in test.name.lower(): # Check f the new folder exists in the set of registered paths
raise Exception(f'Folder already registered')
if request.query_params["createSampleVideo"] == "true":
videos.addScenes.get_files(folder_to_add_path_stripped, True)
else:
videos.addScenes.get_files(folder_to_add_path_stripped, False)
local_scene_folder = LocalSceneFolders(name=temp)
local_scene_folder.save()
log.info(
f"Added folder {temp} to folder list..."
)
except (django.db.IntegrityError, Exception) as e:
log.error(
f"{e} while trying to add {temp} to folder list"
)
else:
content = {"Path does not exist!": "Can't find path!"}
return Response(
content, status=status.HTTP_500_INTERNAL_SERVER_ERROR
)
Handled in videos.AddItems by raising an exception and logging it as an error (alongside adding video files that cannot be processed for any reason)
Describe the bug Windows paths are case insensitive. If one was to add "e:\my_videos" and then "E:\MY_VIDEOS". YAPO-e will add a duplicate entry for each one that is already added from the previous path. The more critical problem is that 'cleaning the database' removes the duplicates, but it also physically deletes the files from the disk.
To Reproduce Steps to reproduce the behavior: On windows, add two identical paths with a different case. Then clean the library.
Expected behavior Files from the same path should not be added twice.
Python version: 3.7
Additional context Probably should check on insertion whether the OS is windows. And if it is should check in a case insensitive manner if the path already in the database.