{"id":21500260,"url":"https://github.com/clucompany/cluflock","last_synced_at":"2025-07-15T21:32:07.045Z","repository":{"id":49355147,"uuid":"157017517","full_name":"clucompany/cluFlock","owner":"clucompany","description":"Installation and subsequent safe removal of flock locks for data streams.","archived":false,"fork":false,"pushed_at":"2024-05-19T13:02:04.000Z","size":162,"stargazers_count":7,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-08T01:54:27.770Z","etag":null,"topics":["clucompany","file-lock","flock","rust","rust-library","safe-flock","stream-flock","unix-lock","win-lock"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clucompany.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-10T20:11:32.000Z","updated_at":"2024-07-26T05:06:57.000Z","dependencies_parsed_at":"2022-09-26T20:20:39.526Z","dependency_job_id":null,"html_url":"https://github.com/clucompany/cluFlock","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clucompany%2FcluFlock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clucompany%2FcluFlock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clucompany%2FcluFlock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clucompany%2FcluFlock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clucompany","download_url":"https://codeload.github.com/clucompany/cluFlock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226073212,"owners_count":17569485,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clucompany","file-lock","flock","rust","rust-library","safe-flock","stream-flock","unix-lock","win-lock"],"created_at":"2024-11-23T17:23:08.894Z","updated_at":"2024-11-23T17:23:09.455Z","avatar_url":"https://github.com/clucompany.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cluFlock\n\n[![CI](https://github.com/clucompany/cluFlock/actions/workflows/CI.yml/badge.svg?event=push)](https://github.com/clucompany/cluFlock/actions/workflows/CI.yml)\n[![Build Status](https://travis-ci.org/clucompany/cluFlock.svg?branch=master)](https://travis-ci.org/clucompany/cluFlock)\n[![Platform](https://img.shields.io/badge/platform-unix%20|%20linux%20|%20windows-blue)](https://github.com/clucompany/cluFlock/tree/master/tests)\n[![Apache licensed](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](./LICENSE)\n[![crates.io](https://img.shields.io/crates/v/cluFlock)](https://crates.io/crates/cluFlock)\n[![Documentation](https://docs.rs/cluFlock/badge.svg)](https://docs.rs/cluFlock)\n\n\nInstallation and subsequent safe removal of `flock` locks for data streams.\n\n# Use\n1. Exclusive LockFile\n\n```rust\nuse cluFlock::ToFlock;\nuse std::fs::File;\nuse std::io;\n\nfn main() -\u003e Result\u003c(), io::Error\u003e {\n\tlet file_lock = File::create(\"./file\")?.wait_exclusive_lock()?;\n\tprintln!(\"{:?}\", file_lock);\n\t\n\tOk( () )\n}\n```\n\n2. Exclusive LockFile (FnOnce)\n\n```rust\nuse std::io::Write;\nuse cluFlock::ToFlock;\nuse std::fs::File;\nuse std::io;\n\nfn main() -\u003e Result\u003c(), io::Error\u003e {\n\tFile::create(\"./file\")?.wait_exclusive_lock_fn(\n\t\t// valid exclusive lock\n\t\t|mut file| write!(file, \"Test.\"), // result: Ok(usize)/Err(std::io::Error)\n\t\t\n\t\t// invalid lock\n\t\t|err| Err(err.into_err()) // into_err: FlockErr -\u003e std::io::Error\n\t)?;\n\t\n\tOk(())\n}\n```\n\n3. Exclusive LockFile (\u0026File)\n\n```rust\nuse cluFlock::ExclusiveFlock;\nuse std::fs::File;\n\nfn main() -\u003e Result\u003c(), std::io::Error\u003e {\n\tlet file = File::create(\"./file\")?;\n\t\n\t{\n\t\tlet file_lock = ExclusiveFlock::wait_lock(\u0026file)?;\n\t\t// file_lock, type: FlockLock\u003c\u0026File\u003e\n\n\t\tprintln!(\"{:?}\", file_lock);\n\t} // auto unlock ExclusiveFlock\n\n\tfile.sync_all()?;\n\n\tOk( () )\n}\n```\n\n4. Shared LockFile (\u0026File)\n\n```rust\nuse std::fs::File;\nuse cluFlock::SharedFlock;\nuse std::io;\n\nfn main() -\u003e Result\u003c(), io::Error\u003e {\n\tlet file = File::create(\"./test_file\")?;\n\t\n\tlet shared = SharedFlock::wait_lock(\u0026file);\n\tprintln!(\"#1shared {:?}\", shared);\n\tlet shared2 = SharedFlock::try_lock(\u0026file);\n\tprintln!(\"#2shared {:?}\", shared2);\n\t\n\tassert_eq!(shared.is_ok(), true);\n\tassert_eq!(shared2.is_ok(), true);\n\t\n\t// manual or automatic unlock SharedFlock_x2\n\t// drop(shared);\n\t// drop(shared2);\n\t\n\tOk( () )\n}\n```\n\n# Support of platforms:\n1. Unix, Linux: Full support: SharedFlock (Wait, Try), ExclusiveFlock (Wait, Try), Unlock (Wait, Try).\n1. Windows: Full support: SharedFlock (Wait, Try), ExclusiveFlock (Wait, Try), Unlock (Wait, !Try). Unlock Try is not implemented and is considered additional unsafe functionality.\n\n# Features of platforms:\n1. Unix, Linux: The flock system call only works between processes, there are no locks inside the process.\n2. Windows: System calls (LockFileEx UnlockFileEx) work between processes and within the current process. If you use Shared and Exclusive locks, you can lock yourself in the same process.\n\n# License\n\nCopyright 2022 #UlinProject Denis Kotlyarov (Денис Котляров)\n\nLicensed under the Apache License, Version 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclucompany%2Fcluflock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclucompany%2Fcluflock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclucompany%2Fcluflock/lists"}