Skip to content

Commit

Permalink
Unlock farm explicitly on drop
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Dec 20, 2023
1 parent 309a07d commit 41416f7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/subspace-farmer/src/single_disk_farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,17 @@ impl SingleDiskFarmId {
/// Exclusive lock for single disk farm info file, ensuring no concurrent edits by cooperating processes is done
#[must_use = "Lock file must be kept around or as long as farm is used"]
pub struct SingleDiskFarmInfoLock {
_file: File,
file: File,
}

impl Drop for SingleDiskFarmInfoLock {
fn drop(&mut self) {
use fs4::FileExt;

if let Err(error) = self.file.unlock() {
error!(%error, "Failed to unlock single disk farm lock");
}
}
}

/// Important information about the contents of the `SingleDiskFarm`
Expand Down Expand Up @@ -174,7 +184,7 @@ impl SingleDiskFarmInfo {
let file = File::open(directory.join(Self::FILE_NAME))?;
fs4::FileExt::try_lock_exclusive(&file)?;

Ok(SingleDiskFarmInfoLock { _file: file })
Ok(SingleDiskFarmInfoLock { file })
}

// ID of the farm
Expand Down

0 comments on commit 41416f7

Please sign in to comment.