Skip to content

Commit

Permalink
MAXDWORD is feature gated.
Browse files Browse the repository at this point in the history
  • Loading branch information
Narsil committed Jan 8, 2025
1 parent 4cc79a7 commit 18bf182
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/api/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct Handle {

impl Drop for Handle {
fn drop(&mut self) {
println!("Released lock on {:?}", std::thread::current().id());
unlock(&self.file);
}
}
Expand All @@ -95,7 +94,6 @@ fn lock_file(mut path: PathBuf) -> Result<Handle, ApiError> {
if res != 0 {
Err(ApiError::LockAcquisition(path))
} else {
println!("Acquired lock on {:?}", std::thread::current().id());
Ok(Handle { file })
}
}
Expand All @@ -121,7 +119,6 @@ mod windows {
use windows_sys::Win32::Storage::FileSystem::{
LockFileEx, UnlockFile, LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY,
};
use windows_sys::Win32::System::SystemServices::MAXDWORD;

pub(crate) fn lock(file: &std::fs::File) -> i32 {
unsafe {
Expand All @@ -131,8 +128,8 @@ mod windows {
file.as_raw_handle() as HANDLE,
flags,
0,
MAXDWORD,
MAXDWORD,
!0,
!0,
&mut overlapped,
);
1 - res
Expand Down
7 changes: 3 additions & 4 deletions src/api/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ mod windows {
use windows_sys::Win32::Storage::FileSystem::{
LockFileEx, UnlockFile, LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY,
};
use windows_sys::Win32::System::SystemServices::MAXDWORD;

pub(crate) fn lock(file: &tokio::fs::File) -> i32 {
unsafe {
Expand All @@ -123,8 +122,8 @@ mod windows {
file.as_raw_handle() as HANDLE,
flags,
0,
MAXDWORD,
MAXDWORD,
!0,
!0,
&mut overlapped,
);
1 - res
Expand Down Expand Up @@ -859,7 +858,7 @@ impl ApiRepo {
let blob_path = cache.blob_path(&metadata.etag);
std::fs::create_dir_all(blob_path.parent().unwrap())?;

let lock = lock_file(blob_path.clone()).await.unwrap();
let lock = lock_file(blob_path.clone()).await?;
progress.init(metadata.size, filename).await;
let mut tmp_path = blob_path.clone();
tmp_path.set_extension(EXTENSION);
Expand Down

0 comments on commit 18bf182

Please sign in to comment.