{"id":22221958,"url":"https://github.com/fabiospampinato/dotlocker","last_synced_at":"2025-07-27T16:31:59.900Z","repository":{"id":189783024,"uuid":"681289324","full_name":"fabiospampinato/dotlocker","owner":"fabiospampinato","description":"A filesystem exclusionary lock implementation based on .lock files.","archived":false,"fork":false,"pushed_at":"2024-04-04T22:39:07.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-19T16:03:13.028Z","etag":null,"topics":["exclusionary","file","lock","lockfile"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/fabiospampinato.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,"governance":null}},"created_at":"2023-08-21T17:28:43.000Z","updated_at":"2023-12-11T16:10:13.000Z","dependencies_parsed_at":"2023-08-21T19:05:07.420Z","dependency_job_id":null,"html_url":"https://github.com/fabiospampinato/dotlocker","commit_stats":null,"previous_names":["fabiospampinato/dotlocker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fdotlocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fdotlocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fdotlocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fdotlocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabiospampinato","download_url":"https://codeload.github.com/fabiospampinato/dotlocker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227817017,"owners_count":17824200,"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":["exclusionary","file","lock","lockfile"],"created_at":"2024-12-02T23:16:20.278Z","updated_at":"2024-12-02T23:16:20.981Z","avatar_url":"https://github.com/fabiospampinato.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DotLocker\n\nA filesystem exclusionary lock implementation based on `.lock` files.\n\n## Features\n\n- It automatically resolves symlinks, ensuring different paths pointing to the same file use the same lock.\n- It aquires a lock by creating a folder at the given path, with `.lock` appended to it.\n- Creating a folder is an atomic operation even in network-attached file-systems.\n- It keeps the lock fresh by periodically updating the folder's `ctime` timestamp.\n- It automatically detects and deletes stale locks, after a configurable amount of time.\n- It automatically cleans up after itself when the process exists.\n- It supports a configurable amount of retries, with a configurable delay between each, for each operation.\n- It also provides a synchronous implementation, that works the same and blocks the thread efficiently with `Atomics.wait`.\n\n## Install\n\n```sh\nnpm install --save dotlocker\n```\n\n## Usage\n\nThis library can be used asynchronously like this:\n\n```ts\nimport DotLocker from 'dotlocker';\n\n// Acquire a lock for a target path\n\nconst dispose = await DotLocker.lock ( '/path/to/file', {\n  lockPath: '/path/to/file.my-lock', // Optional option for setting the path of the lock file manually, required if the target file doesn't exist\n  retries: 10, // Optional option for configuring the number of retries to acquire a lock, 1 by default\n  retryInterval: 5, // Optional option for configuring the delay between attempts, 10 by default\n  staleInterval: 1_000, // Optional option for configuring the amount of milliseconds after which an existing lock is considered stale and deleted automatically, 10_000 by default\n  updateInterval: 100 // Optional option for configuring how often the acquired lock should be updated to keep it fresh, 10% of \"staleInterval\" by default\n});\n\nconst acquired = !!dispose; // Only if you received a dispose function then the lock was acquired successfully\n\n// Check if a non-stale lock exists for a target path\n// This function can return \"undefined\" if it failed to determine the state of the lock one way or the other\n\nconst locked = await DotLocker.locked ( '/path/to/file', {\n  lockPath: '/path/to/file.my-lock',\n  retries: 10,\n  retryInterval: 5,\n  staleInterval: 1_000\n});\n\n// Delete an acquired lock\n// Using the \"dispose\" function received when acquiring it is safer, as that checks if a new lock got acquired at the same path also\n// This function will return \"true\" if the lock did not exist or if it got deleted, and \"false\" otherwise\n\nconst unlocked = await DotLocker.unlock ( '/path/to/file', {\n  lockPath: '/path/to/file.my-lock',\n  retries: 10,\n  retryInterval: 5\n});\n```\n\nOr synchronously, with the same exact methods and options, but internally blocking the thread efficiently with `Atomics.wait` if needed, like this:\n\n```ts\nimport DotLocker from 'dotlocker';\n\n// Acquire a lock for a target path\n\nconst dispose = DotLocker.lockSync ( '/path/to/file' );\nconst acquired = !!dispose;\n\n// Check if a non-stale lock exists for the target path\n\nconst locked = DotLocker.lockedSync ( '/path/to/file' );\n\n// Delete an acquired lock\n\nconst unlocked = DotLocker.unlockSync ( '/path/to/file' );\n```\n\n## License\n\nMIT © Fabio Spampinato\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiospampinato%2Fdotlocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabiospampinato%2Fdotlocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiospampinato%2Fdotlocker/lists"}