/// Acquire an exclusive OS level write lock on a file in the provided path. This is used to check if another instance
/// of this database has already been initialized in order to prevent two process from using it simultaneously
/// ## Parameters
/// `db_path` - Path where the db will be initialized
///
/// ## Returns
/// Returns a File handle that must be retained to keep the file lock active.
Acquire an exclusive OS level write lock on a file in the provided path. This is used to check if another instance
of this database has already been initialized in order to prevent two process from using it simultaneously
Acquire an exclusive OS level write lock on a file in the provided path . This is used to check if another instance of this database has already been initialized in order to prevent two process from using it simultaneously
pub fn acquire_exclusive_file_lock(db_path: &PathBuf) -> Result<File, CommsInitializationError> {
    let lock_file_path = db_path.join(".p2p_file.lock");
    let file = File::create(lock_file_path)?;
    // Attempt to acquire exclusive OS level Write Lock
    if let Err(e) = file.try_lock_exclusive() {
        error!(
            target: LOG_TARGET,
            "Could not acquire exclusive write lock on database lock file: {:?}", e
        );
        return Err(CommsInitializationError::CannotAcquireFileLock);
    }
    Ok(file)
}
pub fn acquire_exclusive_file_lock ( db_path : & PathBuf ) -> Result < File , CommsInitializationError > { let lock_file_path = db_path . join ( " " ) ; let file = File :: create ( lock_file_path ) ? ; // Attempt to acquire exclusive OS level Write Lock if let Err ( e ) = file . try_lock_exclusive ( ) { error ! ( target LOG_TARGET " " e ) ; return Err ( CommsInitializationError :: CannotAcquireFileLock ) ; } Ok ( file ) }
Acquire an exclusive OS level write lock on a file in the provided path.
Acquire an exclusive OS level write lock on a file in the provided path .
Returns a File handle that must be retained to keep the file lock active.
Returns a File handle that must be retained to keep the file lock active .
db_path
&PathBuf