Switch to: V14V13V12V11V10V9V8V7V6V5

Valentina File Locks

Valentina uses different file-lock techniques to prevent multiple RW access to the files (such as database volumes). But, unfortunately, there is no reliable, common, and standard way to do such things on different platforms and file systems.

Valentina always opens any file in this way - firstly, we are trying to open a file for RW (exclusive mode). If the file is blocked somehow (advisory locks on Linux/Mac and WinAPI locks on Windows) we are trying to open the file in RO (shared mode).

For most cases, we choose flock() to mark the file exclusively locked, but it's not a bulletproof solution for some file systems like remote ones - SMB, AFP (NAS, flash drives …). The worst thing is - it may cause undefined behavior, and as a result, you get some weird POSIX errors like EIO later, and nothing there points to the real problem.

So, finally (v.13.0) we choose the old-fashion dot-file locking approach for remote file systems on Mac. In short - before opening some file “file_name” for RW, we check - is there a “.lfile_name” companion in the same directory. If no - we create such dot-file as a sign that file “file_name” is opened for RW. After closing the file “file_name” we delete the dot-file companion. If dot-file exists we open file “file_name” for RO.

But this solution has its own drawback - nobody removes those dot files in case of a crash, power failure, or something like that, and your files remain “advisory” locked forever. So, you should have some code in your app to find and remove dotfiles as a cleanup procedure after crashes.