{"id":17958322,"url":"https://github.com/sheerun/filelock","last_synced_at":"2025-04-09T13:09:43.139Z","repository":{"id":11874160,"uuid":"14434685","full_name":"sheerun/filelock","owner":"sheerun","description":"Heavily tested, but simple filelocking solution using flock command.","archived":false,"fork":false,"pushed_at":"2022-10-28T21:39:48.000Z","size":29,"stargazers_count":30,"open_issues_count":3,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T11:32:47.367Z","etag":null,"topics":["filelock","flock","lockfile","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sheerun.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-15T20:43:48.000Z","updated_at":"2022-10-31T08:03:39.000Z","dependencies_parsed_at":"2023-01-13T16:42:30.897Z","dependency_job_id":null,"html_url":"https://github.com/sheerun/filelock","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheerun%2Ffilelock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheerun%2Ffilelock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheerun%2Ffilelock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheerun%2Ffilelock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sheerun","download_url":"https://codeload.github.com/sheerun/filelock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248045245,"owners_count":21038554,"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":["filelock","flock","lockfile","ruby"],"created_at":"2024-10-29T10:59:27.332Z","updated_at":"2025-04-09T13:09:43.122Z","avatar_url":"https://github.com/sheerun.png","language":"Ruby","readme":"# Filelock [![Build Status][travis-img-url]][travis-url]\n\n[travis-img-url]: https://travis-ci.org/sheerun/filelock.png\n[travis-url]: https://travis-ci.org/sheerun/filelock\n\nHeavily tested, but simple filelocking solution using [flock](http://linux.die.net/man/2/flock) command. It guarantees unlocking of files.\n\nIt works for sure on MRI 1.8, 1.9, 2.0, JRuby in both 1.8 and 1.9 mode, and Rubinius.\n\nThis gem doesn't support NFS. You can use it with [GlusterFS](http://www.gluster.org/), though.\n\n## Basic Usage\n\n```ruby\nFilelock '/tmp/path/to/lock' do\n  # do blocking operation\nend\n```\n\n### Operation Timeout\n\nYou can also pass the timeout for blocking operation (default is 60 seconds):\n\n```ruby\nFilelock '/tmp/path/to/lock', :timeout =\u003e 10 do\n  # do blocking operation\nend\n```\n\nYou can detect timeout by catching `Filelock::ExecTimeout`.\n\n### Lock Acquiring Timeout\n\nYou can also pass a non-zero wait timeout for grabbing the lock (default is 1 day):\n\n```ruby\nFilelock '/tmp/path/to/lock', :wait =\u003e 3600 do\n  # do blocking operation\nend\n```\n\nYou can detect this kind of timeout by catching `Filelock::WaitTimeout`.  Note that a wait timeout of 0 will block until the lock can be acquired instead of raising `Filelock::WaitTimeout`.\n\nNote that lock file directory must already exist, and lock file is not removed after unlock.\n\n### Getting handle to locked file\n\n\n```ruby\nFilelock '/tmp/path/to/lock' do |file|\n  file.truncate\n  file.write Process.pid\nend\n```\n\n## FAQ\n\n*Does it support NFS?*\n\nNo. You can use more complex [lockfile](https://github.com/ahoward/lockfile) gem if you want to support NFS.\n\n*The code is so short. Why shouln't I just copy-paste it?*\n\nBecause even such short code can have issues in future. File locking is very fragile operation. You may expect new releases of this gem fixing discovered bogus behavior (or introducing awesome features).\n\nYou are encouraged to use it if you develop gem that uses flock command, and care about running it on different ruby versions and platforms. Each has its own quirks with regard to flock command.\n\n*How it's different from [lockfile](https://github.com/ahoward/lockfile) gem?*\n\nLockfile is filelocking solution handling NFS filesystems, based on homemade locking solution. Filelock uses [flock](http://linux.die.net/man/2/flock) UNIX command to handle filelocking on very low level. Also lockfile allows you to specify retry timeout. In case of Ruby's flock command this is hard-cored to 0.1 seconds.\n\n*How it's different from [cleverua-lockfile](https://github.com/cleverua/lockfile) gem?*\n\nCleverua removes lockfile after unlocking it. Thas has been proven fatal both in my tests and in [filelocking advices from the Internet](http://world.std.com/~swmcd/steven/tech/flock.html). You could try find a way to remove lock file without breaking Filelock tests. I will be glad to accept such pull-request.\n\n*What happens if my ruby process gets killed while holding a lock? Can new processes acquire this lock?*\n\nYes\n\n## Contribute\n\nTry to break Filelock in some way (note it doesn't support NFS).\n\n## License\n\nFilelock is MIT-licensed. You are awesome.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsheerun%2Ffilelock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsheerun%2Ffilelock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsheerun%2Ffilelock/lists"}