@zukhruf/fs 0.6.16 → 0.7.0
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/README.md +1 -1
- package/dist/file-lock.d.ts.map +1 -1
- package/dist/file-lock.js +11 -9
- package/dist/file-lock.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -127,7 +127,7 @@ Each write of this package uses `patiently` for its rename or link, with the clo
|
|
|
127
127
|
|
|
128
128
|
A process can die while it holds a lock. When the lock is a file that is present, for example a file from `createExclusive`, the file stays after the process dies. Then the lock stays until somebody deletes the file. A `FileLock` is a lock that the kernel holds. When the process of the holder stops, however it stops, the kernel frees the lock at once.
|
|
129
129
|
|
|
130
|
-
Node.js has no `flock`. Thus a `FileLock` is an exclusive SQLite transaction on the file. SQLite is part of Node.js (`node:sqlite`)
|
|
130
|
+
Node.js has no `flock`. Thus a `FileLock` is an exclusive SQLite transaction on the file. SQLite is part of Node.js (`node:sqlite`). `FileLock` opens the file with `open` of `@zukhruf/sqlite-open`.
|
|
131
131
|
|
|
132
132
|
```ts
|
|
133
133
|
import { FileLock } from '@zukhruf/fs';
|
package/dist/file-lock.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-lock.d.ts","sourceRoot":"","sources":["../src/file-lock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file-lock.d.ts","sourceRoot":"","sources":["../src/file-lock.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;GAUG;AACH,qBAAa,QAAS,YAAW,UAAU;;IAIzC,OAAO;IAKP,6EAA6E;IAC7E,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ;IAUnC;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS;IAsB7D,oFAAoF;IACpF,OAAO,IAAI,OAAO;IAmBlB,sEAAsE;IACtE,MAAM,IAAI,IAAI;IAUd,4DAA4D;IAC5D,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAIzB"}
|
package/dist/file-lock.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { UnavailableError, UnchangedJournal, open } from '@zukhruf/sqlite-open';
|
|
3
3
|
const SQLITE_BUSY = 5;
|
|
4
|
-
const SQLITE_CANTOPEN = 14;
|
|
5
4
|
/** Garbage collection closes a connection that nobody references, and a lock that it holds goes with it. */
|
|
6
5
|
const held = new Set();
|
|
7
6
|
/**
|
|
@@ -24,9 +23,10 @@ export class FileLock {
|
|
|
24
23
|
}
|
|
25
24
|
/** Opens the file, and creates it empty when it is absent. Takes no lock. */
|
|
26
25
|
static open(path) {
|
|
27
|
-
// No busy timeout
|
|
28
|
-
//
|
|
29
|
-
|
|
26
|
+
// No busy timeout: one above zero blocks the event loop while it waits, so
|
|
27
|
+
// a caller tries again instead. The open does not set the journal: that
|
|
28
|
+
// statement waits for the lock of the file, so each `tryLock` sets it.
|
|
29
|
+
return new FileLock(path, open(path, { journal: new UnchangedJournal(), timeout: 0 }));
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Whether a handle holds the lock on the file at `path` now. It reads
|
|
@@ -37,13 +37,15 @@ export class FileLock {
|
|
|
37
37
|
static check(path) {
|
|
38
38
|
let database;
|
|
39
39
|
try {
|
|
40
|
-
database =
|
|
40
|
+
database = open(path, { readOnly: true, timeout: 0 });
|
|
41
41
|
}
|
|
42
42
|
catch (error) {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
if (!(error instanceof UnavailableError))
|
|
44
|
+
throw error;
|
|
45
|
+
if (!existsSync(path))
|
|
45
46
|
return 'missing';
|
|
46
|
-
|
|
47
|
+
// A file that exists but cannot be opened is a fault, not a missing
|
|
48
|
+
// file: it surfaces as the UnavailableError of the open.
|
|
47
49
|
throw error;
|
|
48
50
|
}
|
|
49
51
|
try {
|
package/dist/file-lock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-lock.js","sourceRoot":"","sources":["../src/file-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"file-lock.js","sourceRoot":"","sources":["../src/file-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEhF,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,4GAA4G;AAC5G,MAAM,IAAI,GAAG,IAAI,GAAG,EAAgB,CAAC;AAErC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,QAAQ;IACV,KAAK,CAAS;IACd,SAAS,CAAe;IAEjC,YAAoB,IAAY,EAAE,QAAsB;QACtD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,6EAA6E;IAC7E,MAAM,CAAC,IAAI,CAAC,IAAY;QACtB,2EAA2E;QAC3E,wEAAwE;QACxE,uEAAuE;QACvE,OAAO,IAAI,QAAQ,CACjB,IAAI,EACJ,IAAI,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,gBAAgB,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAC5D,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,IAAY;QACvB,IAAI,QAAsB,CAAC;QAC3B,IAAI,CAAC;YACH,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;QACxD,CAAC;QAAC,OAAO,KAAK,EAAE,CAA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;YAClC,MAAM,IAAI,KAAK,CACb,2CAA2C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CACzE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;IAED,4DAA4D;IAC5D,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IACnC,CAAC;CACF;AAED,gHAAgH;AAChH,SAAS,aAAa,CAAC,KAAc,EAAE,IAAY;IACjD,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,IAAI,CAChC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/fs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "File writes a reader never sees half done, a file lock the kernel frees when its holder dies, and a file stamp that tells that a file changed, as git does. Retries Windows' short refusals. Names a file after any key.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -50,9 +50,10 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@zukhruf/async": "^0.
|
|
53
|
+
"@zukhruf/async": "^0.7.0",
|
|
54
|
+
"@zukhruf/sqlite-open": "^0.7.0"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@zukhruf/testing": "^0.
|
|
57
|
+
"@zukhruf/testing": "^0.7.0"
|
|
57
58
|
}
|
|
58
59
|
}
|