document-drive 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-drive",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "module": "./src/index.ts",
@@ -4,7 +4,7 @@ import type { Dirent } from 'fs';
4
4
  import { existsSync, mkdirSync } from 'fs';
5
5
  import fs from 'fs/promises';
6
6
  import path from 'path';
7
- import { lock } from 'proper-lockfile';
7
+ import { check, lock } from 'proper-lockfile';
8
8
  import sanitize from 'sanitize-filename';
9
9
  import { isDocumentDrive } from '../utils';
10
10
  import { IDriveStorage } from './types';
@@ -22,7 +22,20 @@ function ensureDir(dir: string) {
22
22
  }
23
23
  }
24
24
 
25
- function lockFile(path: string) {
25
+ async function lockFile(path: string, retries = 10) {
26
+ // eslint-disable-next-line no-constant-condition
27
+ if (retries > 0) {
28
+ try {
29
+ const locked = await check(path);
30
+ if (locked) {
31
+ throw new Error('File is locked');
32
+ }
33
+ } catch (error) {
34
+ await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for 1 second before checking again
35
+ return lockFile(path, retries - 1);
36
+ }
37
+ }
38
+
26
39
  return lock(path, {
27
40
  fs,
28
41
  retries: 3,