8 stable releases

1.1.3 Sep 2, 2024
1.1.2 Aug 19, 2022
1.1.1 Feb 4, 2022
1.0.5 Nov 8, 2020
1.0.2 Jul 25, 2020

#153 in Unix APIs

Download history 164/week @ 2024-08-02 386/week @ 2024-08-09 259/week @ 2024-08-16 131/week @ 2024-08-23 310/week @ 2024-08-30 136/week @ 2024-09-06 220/week @ 2024-09-13 324/week @ 2024-09-20 200/week @ 2024-09-27 188/week @ 2024-10-04 175/week @ 2024-10-11 258/week @ 2024-10-18 225/week @ 2024-10-25 178/week @ 2024-11-01 244/week @ 2024-11-08 150/week @ 2024-11-15

833 downloads per month
Used in 10 crates (2 directly)

MIT license

19KB
273 lines

file-locker

File locking via POSIX advisory record locks (fork of file-lock)

This crate provides the facility to lock and unlock a file following the advisory record lock scheme as specified by UNIX IEEE Std 1003.1-2001 (POSIX.1) via fcntl().

This crate currently supports Linux and FreeBSD.

USAGE

use file_lock::FileLock;
use std::io::prelude::*;
use std::io::Result;

fn main() -> Result<()> {
    let filelock = FileLock::new("myfile.txt")
                    .writeable(true)
                    .blocking(true)
                    .lock()?;

    filelock.file.write_all(b"Hello, World!")?;

    // Manually unlocking is optional as we unlock on Drop
    filelock.unlock();
}

DOCUMENTATION

SUPPORT

Please report any bugs at:

Or by email at:

AUTHORS

Sashanoraa <sasha@noraa.gay>

Alfie John <alfie@alfie.wtf>

Sebastian Thiel <byronimo@gmail.com>

Contribution

Contribution welcome!

Please send any patches to ~zethra/public-inbox@lists.sr.ht

If you need help sending a patch over email please see this guide

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed under the MIT license, without any additional terms or conditions.

Dependencies

~1.5MB
~35K SLoC