Windows version does not allow the .plk file to sync to Google Drive
Tested: Windows version "pwsafe-3.55.0-bin" on Windows 10
- Google "Drive File Stream" installed which creates a virtual "G:" drive
- Open test_file.psafe3 file from Google "G:" drive
- test_file.plk file gets created
Current behavior: test_file.plk file does NOT sync to Google Drive. Since the .plk file does not sync, this allows others to open the same password database for writing at the same time which can cause data loss. Sometimes Drive File Stream reports "queued for upload", but apparently the way it is trying to open the file fails and it never actually syncs.
Expected behavior: The .plk should sync to Google Drive to prevent multiple users from open the same file for writing access. Is it possible to open the file in a way that allows it to sync? Possibly creating the file but not holding it open?
(It is possible that this could also be a Google Drive Issue)
Locking between Windows and Non-Windows looks not compatible. While Non-Windows locking is depending from existing of the plk-file the Windows implementation is using file locking based on file left open.
I suggest tracking this issue in #1002.
I did some testing. The code that creates the lock file on Windows is here. If the lock file does not already exist and if it gets successfully created, then data is written to the lock file here.
I created a simple FreePascal program that creates test files with all 24 combinations of
// dwDesiredAccess
GENERIC_WRITE = $40000000
GENERIC_READ = $80000000
GENERIC_READ_OR_WRITE = $80000000 or $40000000
and
// dwShareMode
FILE_SHARE_NONE = 0
FILE_SHARE_READ = 1
FILE_SHARE_WRITE = 2,
FILE_SHARE_READ_OR_WRITE = 1 or 2
FILE_SHARE_DELETE = 4
FILE_SHARE_READ_OR_DELETE = 1 or 4
FILE_SHARE_WRITE_OR_DELETE = 2 or 4
FILE_SHARE_READ_OR_WRITE_OR_DELETE = 1 or 2 or 4
For the CreateFile dwFlagsAndAttributes parameter, the test program uses the same flags and attributes as pwsafe:
FILE_ATTRIBUTE_NORMAL or FILE_FLAG_WRITE_THROUGH or SECURITY_SQOS_PRESENT or SECURITY_IDENTIFICATION
When running the test on Windows Google Drive for Desktop (formerly called Drive File Stream) G:\ drive, all 24 test files (CreateFile with CREATE_ALWAYS) get created and successfully synchronized to Google Drive no matter what modes are used as long as I don't write to any of them. I end up with 24 zero byte files syncd to the cloud and other desktop clients. This works even if I still have the files open.
In a second test, after calling CreateFile I then immediately write some data to the writable files. The files that have data written do not sync to Google Drive (not matter what modes were used) until the file handle is closed. In this test only the files opened for reading get successfully sync'd while the file handle is open:
and the files with open file handles that also have had data written to them do NOT sync:
Therefore on Windows, because pwsafe writes data to the lock file after it is created, and also does not close the file handle, it prevents Google Drive for Desktop from synchronizing the .plk file to the cloud. The four variations are:
- Create lock file, keep open = file sync OK
- Create lock file, close file = file sync OK
- Create lock file, write to file, close file = file sync OK
- Create lock file, write to file, keep open = file sync FAIL