krathjen / studiolibrary

Studio Library
https://www.studiolibrary.com
GNU Lesser General Public License v3.0
353 stars 141 forks source link

Safe write #472

Open kalemas opened 1 month ago

kalemas commented 1 month ago

Hi, @krathjen

It is not clear, the problem the algorithm in studiolibrary.utils.write() resolves. Doc string do not state this.

https://github.com/krathjen/studiolibrary/blob/028180125b7562e652af5571a25e2bd191243e44/src/studiolibrary/utils.py#L794

  1. This code creates a .tmp file and in case of sudden termination this file will not be cleanup and StufioLibrary will stop to work.
  2. With distributed workflows this .tmp file seems to prevent concurrent save operations. It may work as expected: if two users call write simultaneously one of them will got exception and will have to repeat adding new item. That is good, but may be there would be better approach that will not throw errors.
  3. Library synchronization with BitTorrent, or Dropbox or rclone as I do, may be long enough and those .tmp files may not cleanup in time, and sometimes we encounter save item failures. Database file would conflict or do not correspond to actually synced files. So it seem that StudioLibrary is not intended to be used with such synchronization solutions.

What do you think?

kalemas commented 1 month ago

Yep, if for some reason there is .tmp file, it is impossible to save any pose, you only able to remove that .tmp file by hands, and most of users are not aware of that file((

kalemas commented 1 month ago

I have different thoughts but simplest solution i could mind is to check modification time of .tmp file and if it is older than minute, remove it.