TagStudioDev / TagStudio

A User-Focused Photo & Document Management System
GNU General Public License v3.0
1.88k stars 231 forks source link

If tag studio cannot find the library to save the library it cannot close the library #119

Closed Loran425 closed 1 week ago

Loran425 commented 2 weeks ago

Expected Behavior

If TagStudio cannot find the save directory for the library it should prompt the user to close the library or save in a new location

Current Behavior

Saving/Closing errors and the library remains open

Possible Solution

During save or close library, check that the save location is valid, if not, prompt the user to close the library or select a new location to save the library (should be the root of wherever the library folder moved)

Steps to Reproduce (Edit: no need to close/reopen TagStudio)

  1. Open a library
  2. Delete or rename the library folder from the file manager
  3. Attempt to use File > Save Library or File > Close Library
[LIBRARY] Saving Library to Disk...
Traceback (most recent call last):
  File "C:\Users\Loran425\PycharmProjects\TagStudio\tagstudio\src\qt\ts_qt.py", line 254, in <lambda>
    close_library_action.triggered.connect(lambda: self.close_library())
                                                   ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Loran425\PycharmProjects\TagStudio\tagstudio\src\qt\ts_qt.py", line 439, in close_library
    self.lib.save_library_to_disk()
  File "C:\Users\Loran425\PycharmProjects\TagStudio\tagstudio\src\core\library.py", line 870, in save_library_to_disk
    self.verify_ts_folders()
  File "C:\Users\Loran425\PycharmProjects\TagStudio\tagstudio\src\core\library.py", line 575, in verify_ts_folders
    os.mkdir(full_ts_path)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\Loran425\\Pictures\\Item Icons\\tradingicons\\Testing\\.TagStudio'
gabrieljreed commented 2 weeks ago

Similar to #118, I can't repro this on Mac

Loran425 commented 2 weeks ago

Modified Steps to reproduce. Does this still not error on mac? @gabrieljreed

gabrieljreed commented 2 weeks ago

Yeah, I'm still not getting the error. Looking through the stack trace, it looks like it calls Library.verify_ts_folders() which will create the library path if it does not exist, which is where it's erroring out for you. For me, it successfully creates the new library and saves everything there.

I wonder if it's related to #120?

SylviaSK commented 1 week ago

I am able to reproduce this on Linux (Mint). Even in cases with no spaces in filename, so unless that part is a Windows specific issue, I don't think its tied to #120.

Looking at os.mkdir() there might be a simple fix, changing it to os.makedirs(), that said it would only recreate the file structure it was expecting, so it also might not be what is actually desired.

That said, its worth noting that since swapping libraries performs a save first, if it fails, trying to swap libraries can't continue leaving you on the previous library. If that happens there is no error message for it in the core program, just in the logs. Might be worth its own issue?