Use LockFile for directory locking on windows

Moved from GitHub badger/1364

Posted by jarifibrahim:

Badger acquires an exclusive lock on the directory to prevent multiple processes from using it. The existing code in dir_windows.go file relies on an in-memory handle to prevent multiple files from accessing it.

While opening we set the sharing mode to zero which means only one process can access it
From Create File Documentation

If this parameter is zero and CreateFile succeeds, the file or device cannot be shared and cannot be opened again until the handle to the file or device is closed. For more information, see the Remarks section.

We can use LockFile for instead.

1 Like