document-drive 0.0.13 → 0.0.15

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.13",
3
+ "version": "0.0.15",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "module": "./src/index.ts",
@@ -9,12 +9,6 @@ import sanitize from 'sanitize-filename';
9
9
  import { isDocumentDrive } from '../utils';
10
10
  import { IDriveStorage } from './types';
11
11
 
12
- function ensureDir(dir: string) {
13
- if (!existsSync(dir)) {
14
- mkdirSync(dir, { recursive: true });
15
- }
16
- }
17
-
18
12
  type FSError = {
19
13
  errno: number;
20
14
  code: string;
@@ -22,8 +16,19 @@ type FSError = {
22
16
  path: string;
23
17
  };
24
18
 
19
+ function ensureDir(dir: string) {
20
+ if (!existsSync(dir)) {
21
+ mkdirSync(dir, { recursive: true });
22
+ }
23
+ }
24
+
25
25
  function lockFile(path: string) {
26
- return lock(path, { fs, retries: 3, realpath: false });
26
+ return lock(path, {
27
+ fs,
28
+ retries: 3,
29
+ realpath: false,
30
+ onCompromised: () => {}
31
+ });
27
32
  }
28
33
 
29
34
  export class FilesystemStorage implements IDriveStorage {
@@ -90,14 +95,16 @@ export class FilesystemStorage implements IDriveStorage {
90
95
 
91
96
  async saveDocument(drive: string, id: string, document: Document) {
92
97
  const documentPath = this._buildDocumentPath(drive, id);
93
- const releaseLock = await lockFile(documentPath);
98
+ const releaseLock = existsSync(documentPath)
99
+ ? await lockFile(documentPath)
100
+ : undefined;
94
101
  try {
95
102
  await ensureDir(path.dirname(documentPath));
96
103
  return fs.writeFile(documentPath, JSON.stringify(document), {
97
104
  encoding: 'utf-8'
98
105
  });
99
106
  } finally {
100
- releaseLock();
107
+ releaseLock?.();
101
108
  }
102
109
  }
103
110