mpv-bookmarker
mpv-bookmarker copied to clipboard
fix: file helpers
A possible fix for #3.
Cleaned an unused var.
They fixed the io.open() issues with unicode paths a year ago -> https://github.com/mpv-player/mpv/issues/7704
so this workaround is not needed anymore, the fileExists(path) function in the original script works flawlessly on Windows too with the latest official builds of MPV
The other - remaining - problem in Windows with this script is that it uses os.remove() and os.rename() lua functions in the saveTable() part of the script . those 2 functions are not fixed and they don't deal with unicode characters either.
So if you should put unicode characters in the filename chosen for the bookmarks file.. saveTable() function won't never end correctly: while the temporary file ".tmp" is correctly created (since it relies on the io.open() file handle) .. then the os.rename() will never change its name back to the original (without the ".tmp" part) .. and so the bookmarks system won't work anymore (unless you manually rename the ".tmp" bookmark file to its original name EVERY TIME a new bookmark is created/modified).
My solution for this problem is to remove both those 2 calls to those "broken" (on Windows) LUA functions and to create a backup copy of the bookmarks file before saving the new version (in the case something should go wrong/bad) with regular io.open(). io.read() and io.write() operations. If something unexpected should happen and the script crash/hang while writing the new bookmarks file, at least one can always recover (manually renaming it) the copy that has been created.