Skip to content

Commit

Permalink
1. Adaptation of the assembly of windows for changes in the main branch.
Browse files Browse the repository at this point in the history
2. Extending layer on top of windows api
3. Adding an experimental flag combining some Windows with linux bugs
4. Expansion of API errors.
  • Loading branch information
denisandroid committed Dec 27, 2021
1 parent 613f86b commit 0884dec
Show file tree
Hide file tree
Showing 22 changed files with 238 additions and 53 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .travis.yml
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion Cargo.toml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ categories = ["development-tools::ffi"]
description = "Installation and subsequent safe removal of `flock` locks for data streams."

[features]
default = []
default = ["win_fix_woudblock_in_errresult"]
win_fix_woudblock_in_errresult = []

[dependencies]

Expand Down
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified examples/exclusive_file.rs
100644 → 100755
Empty file.
Empty file modified examples/exclusive_fn_file.rs
100644 → 100755
Empty file.
Empty file modified examples/exclusive_slice_file.rs
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions examples/runtime_lock_file.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::fs::OpenOptions;


#[derive(Debug)]
#[allow(dead_code)]
pub struct RuntimeLockFile<'a> {
exclusive_flock: FlockLock<File>,
maybe_autoremove_file: Option<AutoRemovePath<'a>>,
Expand Down
Empty file modified examples/shared_file.rs
100644 → 100755
Empty file.
5 changes: 1 addition & 4 deletions examples/sync_file.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use cluFlock::ExclusiveFlock;
use std::fs::File;
use std::time::Duration;
use std::io::ErrorKind;

fn main() {
let file: File = match File::create("./test_file") {
Expand All @@ -11,7 +10,6 @@ fn main() {
};

println!("Try_Exclusive_Lock, {:?}", file);

let lock = match ExclusiveFlock::try_lock(&file) {
//Success, we blocked the file.
Ok(lock) => {
Expand All @@ -21,7 +19,7 @@ fn main() {
},

// File already locked.
Err(ref e) if e.kind() == ErrorKind::WouldBlock => {
Err(ref e) if e.is_already_lock() => {
println!("ALREADY LOCKED: File {:?}.", file);

println!("!Exclusive_Lock, {:?}", file);
Expand All @@ -32,7 +30,6 @@ fn main() {
},

Err(e) => panic!("Panic, err lock file {:?}", e)

};

println!("Sleep, 5s");
Expand Down
Empty file modified examples/sync_file_fn.rs
100644 → 100755
Empty file.
12 changes: 12 additions & 0 deletions src/data/err.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use core::fmt::Display;
use std::error::Error;
use crate::element::FlockElement;
use core::ops::Deref;
use std::io::ErrorKind;

/// The standard error for Flock methods, from the error you can get a borrowed value.
//#[derive(Debug)]
Expand Down Expand Up @@ -93,6 +94,17 @@ impl<T> FlockError<T> where T: FlockElement {
self.into_data()
}

#[inline(always)]
pub fn is_would_block(&self) -> bool {
self.err.kind() == ErrorKind::WouldBlock
}

/// The error occurred due to the presence of a lock.
#[inline(always)]
pub fn is_already_lock(&self) -> bool {
self.is_would_block()
}

/// Get a link to data.
#[inline(always)]
pub fn as_data(&self) -> &T {
Expand Down
Empty file modified src/data/lock.rs
100644 → 100755
Empty file.
Empty file modified src/data/unlock.rs
100644 → 100755
Empty file.
Empty file modified src/element.rs
100644 → 100755
Empty file.
Empty file modified src/lib.rs
100644 → 100755
Empty file.
Empty file modified src/os_release/unix.rs
100644 → 100755
Empty file.
Loading

0 comments on commit 0884dec

Please sign in to comment.