dir_windows.go
dir_windows.go - Overview
This file provides directory locking mechanisms for Windows. It implements exclusive access to a directory using Windows API calls, ensuring that only one process can access the Badger database at a time.
directoryLockGuard
- Purpose: Represents a lock on a directory in Windows.
- Fields:
- h:
syscall.Handle
- Handle to the directory. - path:
string
- The absolute path to our lock file.
- h:
acquireDirectoryLock
- Purpose: Acquires exclusive access to a directory by creating a temporary file with the
FILE_FLAG_DELETE_ON_CLOSE
flag. - Parameters:
- dirPath:
string
- The path to the directory to lock. - pidFileName:
string
- The name of the lock file. - readOnly:
bool
- Indicates whether to acquire a read-only lock (not supported on Windows).
- dirPath:
- Returns:
*directoryLockGuard
- A pointer to the directoryLockGuard struct on success.error
- An error if the lock could not be acquired.
directoryLockGuard.release
- Purpose: Releases the directory lock by closing the handle.
- Parameters: None
- Returns:
error
- An error, if any.
openDir
- Purpose: Opens a directory for syncing in Windows with write access.
- Parameters:
- path:
string
- The path to the directory.
- path:
- Returns:
*os.File
- A pointer to the opened file.error
- An error, if any.
syncDir
- Purpose: A placeholder function as Windows doesn't support syncing directories.
- Parameters:
- dir:
string
- The directory to sync (ignored).
- dir:
- Returns:
error
- Always nil.