tar 7.5.24 → 8.0.1
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 +1712 -1147
- package/dist/commonjs/bytes.d.ts +21 -0
- package/dist/commonjs/bytes.d.ts.map +1 -0
- package/dist/commonjs/bytes.js +83 -0
- package/dist/commonjs/bytes.js.map +1 -0
- package/dist/commonjs/codec.d.ts +53 -0
- package/dist/commonjs/codec.d.ts.map +1 -0
- package/dist/commonjs/codec.js +35 -0
- package/dist/commonjs/codec.js.map +1 -0
- package/dist/commonjs/concat.d.ts +3 -0
- package/dist/commonjs/concat.d.ts.map +1 -0
- package/dist/commonjs/concat.js +20 -0
- package/dist/commonjs/concat.js.map +1 -0
- package/dist/commonjs/create.d.ts +39 -2
- package/dist/commonjs/create.d.ts.map +1 -1
- package/dist/commonjs/create.js +150 -64
- package/dist/commonjs/create.js.map +1 -1
- package/dist/commonjs/dealias.d.ts +79 -0
- package/dist/commonjs/dealias.d.ts.map +1 -0
- package/dist/commonjs/dealias.js +50 -0
- package/dist/commonjs/dealias.js.map +1 -0
- package/dist/commonjs/delete.d.ts +19 -0
- package/dist/commonjs/delete.d.ts.map +1 -0
- package/dist/commonjs/delete.js +121 -0
- package/dist/commonjs/delete.js.map +1 -0
- package/dist/commonjs/entries.d.ts +82 -0
- package/dist/commonjs/entries.d.ts.map +1 -0
- package/dist/commonjs/entries.js +398 -0
- package/dist/commonjs/entries.js.map +1 -0
- package/dist/commonjs/extract.d.ts +14 -2
- package/dist/commonjs/extract.d.ts.map +1 -1
- package/dist/commonjs/extract.js +40 -81
- package/dist/commonjs/extract.js.map +1 -1
- package/dist/commonjs/fs.d.ts +201 -0
- package/dist/commonjs/fs.d.ts.map +1 -0
- package/dist/commonjs/fs.js +5 -0
- package/dist/commonjs/fs.js.map +1 -0
- package/dist/commonjs/header.d.ts +4 -4
- package/dist/commonjs/header.d.ts.map +1 -1
- package/dist/commonjs/header.js +38 -42
- package/dist/commonjs/header.js.map +1 -1
- package/dist/commonjs/index.d.ts +25 -18
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +46 -18
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/index.min.js +2 -3
- package/dist/commonjs/index.min.js.map +4 -4
- package/dist/commonjs/large-numbers.d.ts +2 -2
- package/dist/commonjs/large-numbers.d.ts.map +1 -1
- package/dist/commonjs/large-numbers.js +4 -4
- package/dist/commonjs/large-numbers.js.map +1 -1
- package/dist/commonjs/list.d.ts +23 -6
- package/dist/commonjs/list.d.ts.map +1 -1
- package/dist/commonjs/list.js +99 -138
- package/dist/commonjs/list.js.map +1 -1
- package/dist/commonjs/mkdir.d.ts +16 -11
- package/dist/commonjs/mkdir.d.ts.map +1 -1
- package/dist/commonjs/mkdir.js +121 -159
- package/dist/commonjs/mkdir.js.map +1 -1
- package/dist/commonjs/options.d.ts +284 -513
- package/dist/commonjs/options.d.ts.map +1 -1
- package/dist/commonjs/options.js +20 -61
- package/dist/commonjs/options.js.map +1 -1
- package/dist/commonjs/pack.d.ts +150 -96
- package/dist/commonjs/pack.d.ts.map +1 -1
- package/dist/commonjs/pack.js +752 -445
- package/dist/commonjs/pack.js.map +1 -1
- package/dist/commonjs/parser.d.ts +94 -0
- package/dist/commonjs/parser.d.ts.map +1 -0
- package/dist/commonjs/parser.js +381 -0
- package/dist/commonjs/parser.js.map +1 -0
- package/dist/commonjs/path-reservations.d.ts +17 -7
- package/dist/commonjs/path-reservations.d.ts.map +1 -1
- package/dist/commonjs/path-reservations.js +96 -119
- package/dist/commonjs/path-reservations.js.map +1 -1
- package/dist/commonjs/path.d.ts +19 -0
- package/dist/commonjs/path.d.ts.map +1 -0
- package/dist/commonjs/path.js +90 -0
- package/dist/commonjs/path.js.map +1 -0
- package/dist/commonjs/pax.d.ts +3 -1
- package/dist/commonjs/pax.d.ts.map +1 -1
- package/dist/commonjs/pax.js +53 -43
- package/dist/commonjs/pax.js.map +1 -1
- package/dist/commonjs/read-entry.d.ts +97 -11
- package/dist/commonjs/read-entry.d.ts.map +1 -1
- package/dist/commonjs/read-entry.js +248 -97
- package/dist/commonjs/read-entry.js.map +1 -1
- package/dist/commonjs/read-file.d.ts +22 -0
- package/dist/commonjs/read-file.d.ts.map +1 -0
- package/dist/commonjs/read-file.js +104 -0
- package/dist/commonjs/read-file.js.map +1 -0
- package/dist/commonjs/replace.d.ts +45 -1
- package/dist/commonjs/replace.d.ts.map +1 -1
- package/dist/commonjs/replace.js +165 -211
- package/dist/commonjs/replace.js.map +1 -1
- package/dist/commonjs/server/codecs.d.ts +38 -0
- package/dist/commonjs/server/codecs.d.ts.map +1 -0
- package/dist/commonjs/server/codecs.js +252 -0
- package/dist/commonjs/server/codecs.js.map +1 -0
- package/dist/commonjs/server/index.d.ts +115 -0
- package/dist/commonjs/server/index.d.ts.map +1 -0
- package/dist/commonjs/server/index.js +166 -0
- package/dist/commonjs/server/index.js.map +1 -0
- package/dist/commonjs/server/index.min.js +3 -0
- package/dist/commonjs/server/index.min.js.map +7 -0
- package/dist/commonjs/strip-absolute-path.d.ts +8 -0
- package/dist/commonjs/strip-absolute-path.d.ts.map +1 -1
- package/dist/commonjs/strip-absolute-path.js +17 -20
- package/dist/commonjs/strip-absolute-path.js.map +1 -1
- package/dist/commonjs/to-stream.d.ts +7 -0
- package/dist/commonjs/to-stream.d.ts.map +1 -0
- package/dist/commonjs/to-stream.js +22 -0
- package/dist/commonjs/to-stream.js.map +1 -0
- package/dist/commonjs/types.d.ts +4 -3
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +4 -3
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/unpack.d.ts +143 -89
- package/dist/commonjs/unpack.d.ts.map +1 -1
- package/dist/commonjs/unpack.js +782 -725
- package/dist/commonjs/unpack.js.map +1 -1
- package/dist/commonjs/update.d.ts +11 -1
- package/dist/commonjs/update.d.ts.map +1 -1
- package/dist/commonjs/update.js +37 -28
- package/dist/commonjs/update.js.map +1 -1
- package/dist/commonjs/warn.d.ts +27 -0
- package/dist/commonjs/warn.d.ts.map +1 -0
- package/dist/commonjs/warn.js +36 -0
- package/dist/commonjs/warn.js.map +1 -0
- package/dist/commonjs/win32-path.d.ts +16 -0
- package/dist/commonjs/win32-path.d.ts.map +1 -0
- package/dist/commonjs/win32-path.js +67 -0
- package/dist/commonjs/win32-path.js.map +1 -0
- package/dist/commonjs/write-entry.d.ts +64 -111
- package/dist/commonjs/write-entry.d.ts.map +1 -1
- package/dist/commonjs/write-entry.js +108 -672
- package/dist/commonjs/write-entry.js.map +1 -1
- package/dist/commonjs/write-flag.d.ts +18 -0
- package/dist/commonjs/write-flag.d.ts.map +1 -0
- package/dist/commonjs/write-flag.js +29 -0
- package/dist/commonjs/write-flag.js.map +1 -0
- package/dist/esm/bytes.d.ts +21 -0
- package/dist/esm/bytes.d.ts.map +1 -0
- package/dist/esm/bytes.js +72 -0
- package/dist/esm/bytes.js.map +1 -0
- package/dist/esm/codec.d.ts +53 -0
- package/dist/esm/codec.d.ts.map +1 -0
- package/dist/esm/codec.js +32 -0
- package/dist/esm/codec.js.map +1 -0
- package/dist/esm/concat.d.ts +3 -0
- package/dist/esm/concat.d.ts.map +1 -0
- package/dist/esm/concat.js +16 -0
- package/dist/esm/concat.js.map +1 -0
- package/dist/esm/create.d.ts +39 -2
- package/dist/esm/create.d.ts.map +1 -1
- package/dist/esm/create.js +144 -61
- package/dist/esm/create.js.map +1 -1
- package/dist/esm/dealias.d.ts +79 -0
- package/dist/esm/dealias.d.ts.map +1 -0
- package/dist/esm/dealias.js +46 -0
- package/dist/esm/dealias.js.map +1 -0
- package/dist/esm/delete.d.ts +19 -0
- package/dist/esm/delete.d.ts.map +1 -0
- package/dist/esm/delete.js +117 -0
- package/dist/esm/delete.js.map +1 -0
- package/dist/esm/entries.d.ts +82 -0
- package/dist/esm/entries.d.ts.map +1 -0
- package/dist/esm/entries.js +388 -0
- package/dist/esm/entries.js.map +1 -0
- package/dist/esm/extract.d.ts +14 -2
- package/dist/esm/extract.d.ts.map +1 -1
- package/dist/esm/extract.js +37 -44
- package/dist/esm/extract.js.map +1 -1
- package/dist/esm/fs.d.ts +201 -0
- package/dist/esm/fs.d.ts.map +1 -0
- package/dist/esm/fs.js +4 -0
- package/dist/esm/fs.js.map +1 -0
- package/dist/esm/header.d.ts +4 -4
- package/dist/esm/header.d.ts.map +1 -1
- package/dist/esm/header.js +38 -42
- package/dist/esm/header.js.map +1 -1
- package/dist/esm/index.d.ts +25 -18
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +23 -18
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +2 -3
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/large-numbers.d.ts +2 -2
- package/dist/esm/large-numbers.d.ts.map +1 -1
- package/dist/esm/large-numbers.js +4 -4
- package/dist/esm/large-numbers.js.map +1 -1
- package/dist/esm/list.d.ts +23 -6
- package/dist/esm/list.d.ts.map +1 -1
- package/dist/esm/list.js +96 -101
- package/dist/esm/list.js.map +1 -1
- package/dist/esm/mkdir.d.ts +16 -11
- package/dist/esm/mkdir.d.ts.map +1 -1
- package/dist/esm/mkdir.js +119 -154
- package/dist/esm/mkdir.js.map +1 -1
- package/dist/esm/options.d.ts +284 -513
- package/dist/esm/options.d.ts.map +1 -1
- package/dist/esm/options.js +17 -51
- package/dist/esm/options.js.map +1 -1
- package/dist/esm/pack.d.ts +150 -96
- package/dist/esm/pack.d.ts.map +1 -1
- package/dist/esm/pack.js +750 -441
- package/dist/esm/pack.js.map +1 -1
- package/dist/esm/parser.d.ts +94 -0
- package/dist/esm/parser.d.ts.map +1 -0
- package/dist/esm/parser.js +377 -0
- package/dist/esm/parser.js.map +1 -0
- package/dist/esm/path-reservations.d.ts +17 -7
- package/dist/esm/path-reservations.d.ts.map +1 -1
- package/dist/esm/path-reservations.js +96 -119
- package/dist/esm/path-reservations.js.map +1 -1
- package/dist/esm/path.d.ts +19 -0
- package/dist/esm/path.d.ts.map +1 -0
- package/dist/esm/path.js +80 -0
- package/dist/esm/path.js.map +1 -0
- package/dist/esm/pax.d.ts +3 -1
- package/dist/esm/pax.d.ts.map +1 -1
- package/dist/esm/pax.js +52 -42
- package/dist/esm/pax.js.map +1 -1
- package/dist/esm/read-entry.d.ts +97 -11
- package/dist/esm/read-entry.d.ts.map +1 -1
- package/dist/esm/read-entry.js +245 -96
- package/dist/esm/read-entry.js.map +1 -1
- package/dist/esm/read-file.d.ts +22 -0
- package/dist/esm/read-file.d.ts.map +1 -0
- package/dist/esm/read-file.js +99 -0
- package/dist/esm/read-file.js.map +1 -0
- package/dist/esm/replace.d.ts +45 -1
- package/dist/esm/replace.d.ts.map +1 -1
- package/dist/esm/replace.js +161 -207
- package/dist/esm/replace.js.map +1 -1
- package/dist/esm/server/codecs.d.ts +38 -0
- package/dist/esm/server/codecs.d.ts.map +1 -0
- package/dist/esm/server/codecs.js +214 -0
- package/dist/esm/server/codecs.js.map +1 -0
- package/dist/esm/server/index.d.ts +115 -0
- package/dist/esm/server/index.d.ts.map +1 -0
- package/dist/esm/server/index.js +102 -0
- package/dist/esm/server/index.js.map +1 -0
- package/dist/esm/server/index.min.js +3 -0
- package/dist/esm/server/index.min.js.map +7 -0
- package/dist/esm/strip-absolute-path.d.ts +8 -0
- package/dist/esm/strip-absolute-path.d.ts.map +1 -1
- package/dist/esm/strip-absolute-path.js +17 -20
- package/dist/esm/strip-absolute-path.js.map +1 -1
- package/dist/esm/to-stream.d.ts +7 -0
- package/dist/esm/to-stream.d.ts.map +1 -0
- package/dist/esm/to-stream.js +18 -0
- package/dist/esm/to-stream.js.map +1 -0
- package/dist/esm/types.d.ts +4 -3
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +4 -3
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/unpack.d.ts +143 -89
- package/dist/esm/unpack.d.ts.map +1 -1
- package/dist/esm/unpack.js +778 -719
- package/dist/esm/unpack.js.map +1 -1
- package/dist/esm/update.d.ts +11 -1
- package/dist/esm/update.d.ts.map +1 -1
- package/dist/esm/update.js +35 -28
- package/dist/esm/update.js.map +1 -1
- package/dist/esm/warn.d.ts +27 -0
- package/dist/esm/warn.d.ts.map +1 -0
- package/dist/esm/warn.js +31 -0
- package/dist/esm/warn.js.map +1 -0
- package/dist/esm/win32-path.d.ts +16 -0
- package/dist/esm/win32-path.d.ts.map +1 -0
- package/dist/esm/win32-path.js +60 -0
- package/dist/esm/win32-path.js.map +1 -0
- package/dist/esm/write-entry.d.ts +64 -111
- package/dist/esm/write-entry.d.ts.map +1 -1
- package/dist/esm/write-entry.js +107 -633
- package/dist/esm/write-entry.js.map +1 -1
- package/dist/esm/write-flag.d.ts +18 -0
- package/dist/esm/write-flag.d.ts.map +1 -0
- package/dist/esm/write-flag.js +25 -0
- package/dist/esm/write-flag.js.map +1 -0
- package/package.json +68 -224
- package/dist/commonjs/get-write-flag.d.ts +0 -2
- package/dist/commonjs/get-write-flag.d.ts.map +0 -1
- package/dist/commonjs/get-write-flag.js +0 -32
- package/dist/commonjs/get-write-flag.js.map +0 -1
- package/dist/commonjs/make-command.d.ts +0 -49
- package/dist/commonjs/make-command.d.ts.map +0 -1
- package/dist/commonjs/make-command.js +0 -52
- package/dist/commonjs/make-command.js.map +0 -1
- package/dist/commonjs/normalize-windows-path.d.ts +0 -2
- package/dist/commonjs/normalize-windows-path.d.ts.map +0 -1
- package/dist/commonjs/normalize-windows-path.js +0 -12
- package/dist/commonjs/normalize-windows-path.js.map +0 -1
- package/dist/commonjs/parse.d.ts +0 -92
- package/dist/commonjs/parse.d.ts.map +0 -1
- package/dist/commonjs/parse.js +0 -655
- package/dist/commonjs/parse.js.map +0 -1
- package/dist/commonjs/process-umask.d.ts +0 -2
- package/dist/commonjs/process-umask.d.ts.map +0 -1
- package/dist/commonjs/process-umask.js +0 -7
- package/dist/commonjs/process-umask.js.map +0 -1
- package/dist/commonjs/warn-method.d.ts +0 -24
- package/dist/commonjs/warn-method.d.ts.map +0 -1
- package/dist/commonjs/warn-method.js +0 -31
- package/dist/commonjs/warn-method.js.map +0 -1
- package/dist/esm/get-write-flag.d.ts +0 -2
- package/dist/esm/get-write-flag.d.ts.map +0 -1
- package/dist/esm/get-write-flag.js +0 -26
- package/dist/esm/get-write-flag.js.map +0 -1
- package/dist/esm/make-command.d.ts +0 -49
- package/dist/esm/make-command.d.ts.map +0 -1
- package/dist/esm/make-command.js +0 -48
- package/dist/esm/make-command.js.map +0 -1
- package/dist/esm/normalize-windows-path.d.ts +0 -2
- package/dist/esm/normalize-windows-path.d.ts.map +0 -1
- package/dist/esm/normalize-windows-path.js +0 -9
- package/dist/esm/normalize-windows-path.js.map +0 -1
- package/dist/esm/parse.d.ts +0 -92
- package/dist/esm/parse.d.ts.map +0 -1
- package/dist/esm/parse.js +0 -651
- package/dist/esm/parse.js.map +0 -1
- package/dist/esm/process-umask.d.ts +0 -2
- package/dist/esm/process-umask.d.ts.map +0 -1
- package/dist/esm/process-umask.js +0 -3
- package/dist/esm/process-umask.js.map +0 -1
- package/dist/esm/warn-method.d.ts +0 -24
- package/dist/esm/warn-method.d.ts.map +0 -1
- package/dist/esm/warn-method.js +0 -27
- package/dist/esm/warn-method.js.map +0 -1
|
@@ -1,169 +1,146 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// is called with a cb that clears the reservation.
|
|
6
|
-
//
|
|
7
|
-
// Used by async unpack to avoid clobbering paths in use,
|
|
8
|
-
// while still allowing maximal safe parallelization.
|
|
2
|
+
// The async extraction does several entries at one time. Two entries
|
|
3
|
+
// must not work on the same path at one time: a link needs its
|
|
4
|
+
// target, and an entry can replace an object of a different type.
|
|
9
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
6
|
exports.PathReservations = void 0;
|
|
11
|
-
const node_path_1 = require("node:path");
|
|
12
7
|
const normalize_unicode_js_1 = require("./normalize-unicode.js");
|
|
13
8
|
const strip_trailing_slashes_js_1 = require("./strip-trailing-slashes.js");
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
// '/a/b/c/d' -> ['/', '/a', '/a/b', '/a/b/c', '/a/b/c/d']
|
|
9
|
+
const path_js_1 = require("./path.js");
|
|
10
|
+
// The parent directories of a normalized path.
|
|
11
|
+
// '/a/b/c' gives ['/', '/a', '/a/b'].
|
|
18
12
|
const getDirs = (path) => {
|
|
19
|
-
const dirs =
|
|
20
|
-
|
|
21
|
-
.slice(0,
|
|
22
|
-
|
|
23
|
-
const s = set.at(-1);
|
|
24
|
-
if (s !== undefined) {
|
|
25
|
-
path = (0, node_path_1.join)(s, path);
|
|
26
|
-
}
|
|
27
|
-
set.push(path || '/');
|
|
28
|
-
return set;
|
|
29
|
-
}, []);
|
|
13
|
+
const dirs = [];
|
|
14
|
+
for (let i = path.indexOf('/'); i !== -1; i = path.indexOf('/', i + 1)) {
|
|
15
|
+
dirs.push(path.slice(0, i) || '/');
|
|
16
|
+
}
|
|
30
17
|
return dirs;
|
|
31
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Gives each task the exclusive use of its paths, and the shared use
|
|
21
|
+
* of their parent directories. A task starts when each task before
|
|
22
|
+
* it that uses one of its paths, or a directory above or below one,
|
|
23
|
+
* is done.
|
|
24
|
+
*
|
|
25
|
+
* Paths that differ only in case or in Unicode form are the same
|
|
26
|
+
* path, because they can be the same file on disk.
|
|
27
|
+
*/
|
|
32
28
|
class PathReservations {
|
|
33
|
-
// path
|
|
34
|
-
// A Set
|
|
35
|
-
//
|
|
29
|
+
// For each path: the tasks that wait for it, in order. A function
|
|
30
|
+
// has the path for itself. A Set of functions shares the path as a
|
|
31
|
+
// parent directory.
|
|
36
32
|
#queues = new Map();
|
|
37
|
-
// fn => {paths:[path,...], dirs:[path, ...]}
|
|
38
33
|
#reservations = new Map();
|
|
39
|
-
// functions currently running
|
|
40
34
|
#running = new Set();
|
|
35
|
+
#win32;
|
|
36
|
+
/** @param win32 run one task at a time */
|
|
37
|
+
constructor(win32 = false) {
|
|
38
|
+
this.#win32 = win32;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Call `fn` when it is first in line for each of its paths. The
|
|
42
|
+
* paths are free again when the promise of `fn` settles. Returns a
|
|
43
|
+
* promise with the result of `fn`.
|
|
44
|
+
*/
|
|
41
45
|
reserve(paths, fn) {
|
|
46
|
+
return new Promise((res, rej) => {
|
|
47
|
+
const handler = () => {
|
|
48
|
+
fn().then(() => {
|
|
49
|
+
this.#clear(handler);
|
|
50
|
+
res();
|
|
51
|
+
}, er => {
|
|
52
|
+
this.#clear(handler);
|
|
53
|
+
rej(er);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
this.#add(paths, handler);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
#add(paths, fn) {
|
|
42
60
|
paths =
|
|
43
|
-
|
|
61
|
+
this.#win32 ?
|
|
44
62
|
['win32 parallelization disabled']
|
|
45
|
-
:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
: [
|
|
64
|
+
...new Set(paths.map(p => (0, strip_trailing_slashes_js_1.stripTrailingSlashes)((0, path_js_1.join)((0, normalize_unicode_js_1.normalizeUnicode)(p))))),
|
|
65
|
+
];
|
|
66
|
+
const dirs = new Set(paths.flatMap(getDirs));
|
|
67
|
+
// A path of the task is exclusive, so it also covers the use of
|
|
68
|
+
// that path as a parent directory of another path.
|
|
69
|
+
for (const p of paths)
|
|
70
|
+
dirs.delete(p);
|
|
50
71
|
this.#reservations.set(fn, { dirs, paths });
|
|
51
72
|
for (const p of paths) {
|
|
52
73
|
const q = this.#queues.get(p);
|
|
53
|
-
if (!q)
|
|
74
|
+
if (!q)
|
|
54
75
|
this.#queues.set(p, [fn]);
|
|
55
|
-
|
|
56
|
-
else {
|
|
76
|
+
else
|
|
57
77
|
q.push(fn);
|
|
58
|
-
}
|
|
59
78
|
}
|
|
60
79
|
for (const dir of dirs) {
|
|
61
80
|
const q = this.#queues.get(dir);
|
|
62
|
-
|
|
81
|
+
const last = q?.[q.length - 1];
|
|
82
|
+
if (!q)
|
|
63
83
|
this.#queues.set(dir, [new Set([fn])]);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
l.add(fn);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
q.push(new Set([fn]));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
84
|
+
else if (last instanceof Set)
|
|
85
|
+
last.add(fn);
|
|
86
|
+
else
|
|
87
|
+
q.push(new Set([fn]));
|
|
74
88
|
}
|
|
75
|
-
|
|
89
|
+
this.#run(fn);
|
|
76
90
|
}
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
const res = this.#reservations.get(fn);
|
|
81
|
-
/* c8 ignore start */
|
|
82
|
-
if (!res) {
|
|
83
|
-
throw new Error('function does not have any path reservations');
|
|
84
|
-
}
|
|
85
|
-
/* c8 ignore stop */
|
|
86
|
-
return {
|
|
87
|
-
paths: res.paths.map((path) => this.#queues.get(path)),
|
|
88
|
-
dirs: [...res.dirs].map(path => this.#queues.get(path)),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
// check if fn is first in line for all its paths, and is
|
|
92
|
-
// included in the first set for all its dir queues
|
|
93
|
-
check(fn) {
|
|
94
|
-
const { paths, dirs } = this.#getQueues(fn);
|
|
95
|
-
return (paths.every(q => q && q[0] === fn) &&
|
|
96
|
-
dirs.every(q => q && q[0] instanceof Set && q[0].has(fn)));
|
|
97
|
-
}
|
|
98
|
-
// run the function if it's first in line and not already running
|
|
91
|
+
// Start the task if it is first in line for each path, and in the
|
|
92
|
+
// first set for each directory. A task that waits is never first in
|
|
93
|
+
// line for each of them, so a task starts one time only.
|
|
99
94
|
#run(fn) {
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
const { paths, dirs } = this.#reservations.get(fn);
|
|
96
|
+
for (const p of paths) {
|
|
97
|
+
if (this.#queues.get(p)?.[0] !== fn)
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
for (const dir of dirs) {
|
|
101
|
+
const first = this.#queues.get(dir)?.[0];
|
|
102
|
+
if (!(first instanceof Set) || !first.has(fn))
|
|
103
|
+
return;
|
|
102
104
|
}
|
|
103
105
|
this.#running.add(fn);
|
|
104
|
-
fn(
|
|
105
|
-
return true;
|
|
106
|
+
fn();
|
|
106
107
|
}
|
|
107
108
|
#clear(fn) {
|
|
108
|
-
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
const res = this.#reservations.get(fn);
|
|
112
|
-
/* c8 ignore start */
|
|
113
|
-
if (!res) {
|
|
114
|
-
throw new Error('invalid reservation');
|
|
115
|
-
}
|
|
116
|
-
/* c8 ignore stop */
|
|
117
|
-
const { paths, dirs } = res;
|
|
109
|
+
const { paths, dirs } = this.#reservations.get(fn);
|
|
118
110
|
const next = new Set();
|
|
119
111
|
for (const path of paths) {
|
|
112
|
+
// A running task is first in the queue of each of its paths.
|
|
120
113
|
const q = this.#queues.get(path);
|
|
121
|
-
|
|
122
|
-
if (!
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
/* c8 ignore stop */
|
|
126
|
-
const q0 = q[1];
|
|
127
|
-
if (!q0) {
|
|
114
|
+
const after = q[1];
|
|
115
|
+
if (!after) {
|
|
128
116
|
this.#queues.delete(path);
|
|
129
117
|
continue;
|
|
130
118
|
}
|
|
131
119
|
q.shift();
|
|
132
|
-
if (typeof
|
|
133
|
-
next.add(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
for (const f of q0) {
|
|
120
|
+
if (typeof after === 'function')
|
|
121
|
+
next.add(after);
|
|
122
|
+
else
|
|
123
|
+
for (const f of after)
|
|
137
124
|
next.add(f);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
125
|
}
|
|
141
126
|
for (const dir of dirs) {
|
|
127
|
+
// A running task is in the first set of each of its directories.
|
|
142
128
|
const q = this.#queues.get(dir);
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (q0.size === 1 && q.length === 1) {
|
|
129
|
+
const first = q[0];
|
|
130
|
+
if (first.size > 1)
|
|
131
|
+
first.delete(fn);
|
|
132
|
+
else if (q.length === 1)
|
|
148
133
|
this.#queues.delete(dir);
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
else if (q0.size === 1) {
|
|
152
|
-
q.shift();
|
|
153
|
-
// next one must be a function,
|
|
154
|
-
// or else the Set would've been reused
|
|
155
|
-
const n = q[0];
|
|
156
|
-
if (typeof n === 'function') {
|
|
157
|
-
next.add(n);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
134
|
else {
|
|
161
|
-
|
|
135
|
+
q.shift();
|
|
136
|
+
// Two sets in a row would be one set, so this is a function.
|
|
137
|
+
next.add(q[0]);
|
|
162
138
|
}
|
|
163
139
|
}
|
|
164
140
|
this.#running.delete(fn);
|
|
165
|
-
|
|
166
|
-
|
|
141
|
+
this.#reservations.delete(fn);
|
|
142
|
+
for (const f of next)
|
|
143
|
+
this.#run(f);
|
|
167
144
|
}
|
|
168
145
|
}
|
|
169
146
|
exports.PathReservations = PathReservations;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-reservations.js","sourceRoot":"","sources":["../../src/path-reservations.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,iCAAiC;AACjC,qDAAqD;AACrD,mDAAmD;AACnD,EAAE;AACF,yDAAyD;AACzD,qDAAqD;;;AAErD,yCAAgC;AAChC,iEAAyD;AACzD,2EAAkE;AAElE,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,OAAO,CAAC,QAAQ,CAAA;AAC1E,MAAM,SAAS,GAAG,QAAQ,KAAK,OAAO,CAAA;AAStC,+CAA+C;AAC/C,0DAA0D;AAC1D,MAAM,OAAO,GAAG,C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AC;oBACnB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;gBACb,CAAC;YACH,CAAC;QACH,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAC/B,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;YACjB,uCAAuC;YACvC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,YAAY,GAAG,CAAC;gBAAE,SAAQ;YACxC,IAAI,EAAE,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACpC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;gBACxB,SAAQ;YACV,CAAC;iBAAM,IAAI,EAAE,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;gBACzB,CAAC,CAAC,KAAK,EAAE,CAAA;gBACT,+BAA+B;gBAC/B,uCAAuC;gBACvC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;gBACd,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE,CAAC;oBAC5B,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;gBACb,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;YACf,CAAC;QACH,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QACxB,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAxJD,4CAwJC","sourcesContent":["// A path exclusive reservation system\n// reserve([list, of, paths], fn)\n// When the fn is first in line for all its paths, it\n// is called with a cb that clears the reservation.\n//\n// Used by async unpack to avoid clobbering paths in use,\n// while still allowing maximal safe parallelization.\n\nimport { join } from 'node:path'\nimport { normalizeUnicode } from './normalize-unicode.js'\nimport { stripTrailingSlashes } from './strip-trailing-slashes.js'\n\nconst platform = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform\nconst isWindows = platform === 'win32'\n\nexport type Reservation = {\n paths: string[]\n dirs: Set<string>\n}\n\nexport type Handler = (clear: () => void) => void\n\n// return a set of parent dirs for a given path\n// '/a/b/c/d' -> ['/', '/a', '/a/b', '/a/b/c', '/a/b/c/d']\nconst getDirs = (path: string) => {\n const dirs = path\n .split('/')\n .slice(0, -1)\n .reduce((set: string[], path) => {\n const s = set.at(-1)\n if (s !== undefined) {\n path = join(s, path)\n }\n set.push(path || '/')\n return set\n }, [])\n return dirs\n}\n\nexport class PathReservations {\n // path => [function or Set]\n // A Set object means a directory reservation\n // A fn is a direct reservation on that path\n #queues = new Map<string, (Handler | Set<Handler>)[]>()\n\n // fn => {paths:[path,...], dirs:[path, ...]}\n #reservations = new Map<Handler, Reservation>()\n\n // functions currently running\n #running = new Set<Handler>()\n\n reserve(paths: string[], fn: Handler) {\n paths =\n isWindows ?\n ['win32 parallelization disabled']\n : paths.map(p => {\n // don't need normPath, because we skip this entirely for windows\n return stripTrailingSlashes(join(normalizeUnicode(p)))\n })\n\n const dirs = new Set<string>(\n paths.map(path => getDirs(path)).reduce((a, b) => a.concat(b)),\n )\n this.#reservations.set(fn, { dirs, paths })\n for (const p of paths) {\n const q = this.#queues.get(p)\n if (!q) {\n this.#queues.set(p, [fn])\n } else {\n q.push(fn)\n }\n }\n for (const dir of dirs) {\n const q = this.#queues.get(dir)\n if (!q) {\n this.#queues.set(dir, [new Set([fn])])\n } else {\n const l = q.at(-1)\n if (l instanceof Set) {\n l.add(fn)\n } else {\n q.push(new Set([fn]))\n }\n }\n }\n return this.#run(fn)\n }\n\n // return the queues for each path the function cares about\n // fn => {paths, dirs}\n #getQueues(fn: Handler): {\n paths: Handler[][]\n dirs: (Handler | Set<Handler>)[][]\n } {\n const res = this.#reservations.get(fn)\n /* c8 ignore start */\n if (!res) {\n throw new Error('function does not have any path reservations')\n }\n /* c8 ignore stop */\n return {\n paths: res.paths.map((path: string) =>\n this.#queues.get(path),\n ) as Handler[][],\n dirs: [...res.dirs].map(path => this.#queues.get(path)) as (\n | Handler\n | Set<Handler>\n )[][],\n }\n }\n\n // check if fn is first in line for all its paths, and is\n // included in the first set for all its dir queues\n check(fn: Handler) {\n const { paths, dirs } = this.#getQueues(fn)\n return (\n paths.every(q => q && q[0] === fn) &&\n dirs.every(q => q && q[0] instanceof Set && q[0].has(fn))\n )\n }\n\n // run the function if it's first in line and not already running\n #run(fn: Handler) {\n if (this.#running.has(fn) || !this.check(fn)) {\n return false\n }\n this.#running.add(fn)\n fn(() => this.#clear(fn))\n return true\n }\n\n #clear(fn: Handler) {\n if (!this.#running.has(fn)) {\n return false\n }\n const res = this.#reservations.get(fn)\n /* c8 ignore start */\n if (!res) {\n throw new Error('invalid reservation')\n }\n /* c8 ignore stop */\n const { paths, dirs } = res\n\n const next = new Set<Handler>()\n for (const path of paths) {\n const q = this.#queues.get(path)\n /* c8 ignore start */\n if (!q || q?.[0] !== fn) {\n continue\n }\n /* c8 ignore stop */\n const q0 = q[1]\n if (!q0) {\n this.#queues.delete(path)\n continue\n }\n q.shift()\n if (typeof q0 === 'function') {\n next.add(q0)\n } else {\n for (const f of q0) {\n next.add(f)\n }\n }\n }\n\n for (const dir of dirs) {\n const q = this.#queues.get(dir)\n const q0 = q?.[0]\n /* c8 ignore next - type safety only */\n if (!q || !(q0 instanceof Set)) continue\n if (q0.size === 1 && q.length === 1) {\n this.#queues.delete(dir)\n continue\n } else if (q0.size === 1) {\n q.shift()\n // next one must be a function,\n // or else the Set would've been reused\n const n = q[0]\n if (typeof n === 'function') {\n next.add(n)\n }\n } else {\n q0.delete(fn)\n }\n }\n\n this.#running.delete(fn)\n next.forEach(fn => this.#run(fn))\n return true\n }\n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AC,CAAY,CAAC,CAAA;YAC3B,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QACxB,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAC7B,KAAK,MAAM,CAAC,IAAI,IAAI;YAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACpC,CAAC;CACF;AAnHD,4CAmHC","sourcesContent":["// The async extraction does several entries at one time. Two entries\n// must not work on the same path at one time: a link needs its\n// target, and an entry can replace an object of a different type.\n\nimport { normalizeUnicode } from './normalize-unicode.js'\nimport { stripTrailingSlashes } from './strip-trailing-slashes.js'\nimport { join } from './path.js'\n\ntype Handler = () => void\ntype Queue = (Handler | Set<Handler>)[]\ntype Reservation = { paths: string[]; dirs: Set<string> }\n\n// The parent directories of a normalized path.\n// '/a/b/c' gives ['/', '/a', '/a/b'].\nconst getDirs = (path: string) => {\n const dirs: string[] = []\n for (let i = path.indexOf('/'); i !== -1; i = path.indexOf('/', i + 1)) {\n dirs.push(path.slice(0, i) || '/')\n }\n return dirs\n}\n\n/**\n * Gives each task the exclusive use of its paths, and the shared use\n * of their parent directories. A task starts when each task before\n * it that uses one of its paths, or a directory above or below one,\n * is done.\n *\n * Paths that differ only in case or in Unicode form are the same\n * path, because they can be the same file on disk.\n */\nexport class PathReservations {\n // For each path: the tasks that wait for it, in order. A function\n // has the path for itself. A Set of functions shares the path as a\n // parent directory.\n #queues = new Map<string, Queue>()\n #reservations = new Map<Handler, Reservation>()\n #running = new Set<Handler>()\n #win32: boolean\n\n /** @param win32 run one task at a time */\n constructor(win32: boolean = false) {\n this.#win32 = win32\n }\n\n /**\n * Call `fn` when it is first in line for each of its paths. The\n * paths are free again when the promise of `fn` settles. Returns a\n * promise with the result of `fn`.\n */\n reserve(paths: string[], fn: () => Promise<void>): Promise<void> {\n return new Promise<void>((res, rej) => {\n const handler: Handler = () => {\n fn().then(\n () => {\n this.#clear(handler)\n res()\n },\n er => {\n this.#clear(handler)\n rej(er)\n },\n )\n }\n this.#add(paths, handler)\n })\n }\n\n #add(paths: string[], fn: Handler) {\n paths =\n this.#win32 ?\n ['win32 parallelization disabled']\n : [\n ...new Set(\n paths.map(p =>\n stripTrailingSlashes(join(normalizeUnicode(p))),\n ),\n ),\n ]\n const dirs = new Set<string>(paths.flatMap(getDirs))\n // A path of the task is exclusive, so it also covers the use of\n // that path as a parent directory of another path.\n for (const p of paths) dirs.delete(p)\n this.#reservations.set(fn, { dirs, paths })\n for (const p of paths) {\n const q = this.#queues.get(p)\n if (!q) this.#queues.set(p, [fn])\n else q.push(fn)\n }\n for (const dir of dirs) {\n const q = this.#queues.get(dir)\n const last = q?.[q.length - 1]\n if (!q) this.#queues.set(dir, [new Set([fn])])\n else if (last instanceof Set) last.add(fn)\n else q.push(new Set([fn]))\n }\n this.#run(fn)\n }\n\n // Start the task if it is first in line for each path, and in the\n // first set for each directory. A task that waits is never first in\n // line for each of them, so a task starts one time only.\n #run(fn: Handler) {\n const { paths, dirs } = this.#reservations.get(fn) as Reservation\n for (const p of paths) {\n if (this.#queues.get(p)?.[0] !== fn) return\n }\n for (const dir of dirs) {\n const first = this.#queues.get(dir)?.[0]\n if (!(first instanceof Set) || !first.has(fn)) return\n }\n this.#running.add(fn)\n fn()\n }\n\n #clear(fn: Handler) {\n const { paths, dirs } = this.#reservations.get(fn) as Reservation\n const next = new Set<Handler>()\n for (const path of paths) {\n // A running task is first in the queue of each of its paths.\n const q = this.#queues.get(path) as Queue\n const after = q[1]\n if (!after) {\n this.#queues.delete(path)\n continue\n }\n q.shift()\n if (typeof after === 'function') next.add(after)\n else for (const f of after) next.add(f)\n }\n for (const dir of dirs) {\n // A running task is in the first set of each of its directories.\n const q = this.#queues.get(dir) as Queue\n const first = q[0] as Set<Handler>\n if (first.size > 1) first.delete(fn)\n else if (q.length === 1) this.#queues.delete(dir)\n else {\n q.shift()\n // Two sets in a row would be one set, so this is a function.\n next.add(q[0] as Handler)\n }\n }\n this.#running.delete(fn)\n this.#reservations.delete(fn)\n for (const f of next) this.#run(f)\n }\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Resolve `.` and `..` parts, and remove repeated slashes. */
|
|
2
|
+
export declare const normalize: (path: string) => string;
|
|
3
|
+
/** Join the parts with a slash, then normalize the result. */
|
|
4
|
+
export declare const join: (...parts: string[]) => string;
|
|
5
|
+
/** The path without its last part. */
|
|
6
|
+
export declare const dirname: (path: string) => string;
|
|
7
|
+
/** The last part of the path. */
|
|
8
|
+
export declare const basename: (path: string) => string;
|
|
9
|
+
/** True if the path starts with a slash. */
|
|
10
|
+
export declare const isAbsolute: (path: string) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the parts from right to left, up to the first absolute
|
|
13
|
+
* part. There is no working directory here: if no part is absolute,
|
|
14
|
+
* the result is a relative path.
|
|
15
|
+
*/
|
|
16
|
+
export declare const resolve: (...parts: string[]) => string;
|
|
17
|
+
/** The relative path from `from` to `to`. */
|
|
18
|
+
export declare const relative: (from: string, to: string) => string;
|
|
19
|
+
//# sourceMappingURL=path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":"AAGA,+DAA+D;AAC/D,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,MAaxC,CAAA;AAED,8DAA8D;AAC9D,eAAO,MAAM,IAAI,GAAI,GAAG,OAAO,MAAM,EAAE,KAAG,MACC,CAAA;AAE3C,sCAAsC;AACtC,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,KAAG,MAQtC,CAAA;AAED,iCAAiC;AACjC,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,KAAG,MAIvC,CAAA;AAED,4CAA4C;AAC5C,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,OACf,CAAA;AAE3B;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,GAAG,OAAO,MAAM,EAAE,KAAG,MAQ5C,CAAA;AAED,6CAA6C;AAC7C,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,IAAI,MAAM,KAAG,MAYnD,CAAA"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The POSIX path functions that tar paths need. Each one gives the
|
|
3
|
+
// same result as the function of the same name in `path.posix`.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.relative = exports.resolve = exports.isAbsolute = exports.basename = exports.dirname = exports.join = exports.normalize = void 0;
|
|
6
|
+
/** Resolve `.` and `..` parts, and remove repeated slashes. */
|
|
7
|
+
const normalize = (path) => {
|
|
8
|
+
const absolute = path.charCodeAt(0) === 47;
|
|
9
|
+
const out = [];
|
|
10
|
+
for (const part of path.split('/')) {
|
|
11
|
+
if (part === '' || part === '.')
|
|
12
|
+
continue;
|
|
13
|
+
if (part !== '..')
|
|
14
|
+
out.push(part);
|
|
15
|
+
else if (out.length && out[out.length - 1] !== '..')
|
|
16
|
+
out.pop();
|
|
17
|
+
else if (!absolute)
|
|
18
|
+
out.push(part);
|
|
19
|
+
}
|
|
20
|
+
const trail = out.length && path.charCodeAt(path.length - 1) === 47;
|
|
21
|
+
const res = out.join('/') + (trail ? '/' : '');
|
|
22
|
+
if (absolute)
|
|
23
|
+
return '/' + res;
|
|
24
|
+
return res || (path.endsWith('/') ? './' : '.');
|
|
25
|
+
};
|
|
26
|
+
exports.normalize = normalize;
|
|
27
|
+
/** Join the parts with a slash, then normalize the result. */
|
|
28
|
+
const join = (...parts) => (0, exports.normalize)(parts.filter(p => p).join('/'));
|
|
29
|
+
exports.join = join;
|
|
30
|
+
/** The path without its last part. */
|
|
31
|
+
const dirname = (path) => {
|
|
32
|
+
let end = path.length;
|
|
33
|
+
while (end > 1 && path.charCodeAt(end - 1) === 47)
|
|
34
|
+
end--;
|
|
35
|
+
const slash = path.lastIndexOf('/', end - 1);
|
|
36
|
+
if (slash === -1)
|
|
37
|
+
return '.';
|
|
38
|
+
if (slash === 0)
|
|
39
|
+
return '/';
|
|
40
|
+
if (slash === 1 && path.charCodeAt(0) === 47)
|
|
41
|
+
return '//';
|
|
42
|
+
return path.slice(0, slash);
|
|
43
|
+
};
|
|
44
|
+
exports.dirname = dirname;
|
|
45
|
+
/** The last part of the path. */
|
|
46
|
+
const basename = (path) => {
|
|
47
|
+
let end = path.length;
|
|
48
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47)
|
|
49
|
+
end--;
|
|
50
|
+
return path.slice(path.lastIndexOf('/', end - 1) + 1, end);
|
|
51
|
+
};
|
|
52
|
+
exports.basename = basename;
|
|
53
|
+
/** True if the path starts with a slash. */
|
|
54
|
+
const isAbsolute = (path) => path.charCodeAt(0) === 47;
|
|
55
|
+
exports.isAbsolute = isAbsolute;
|
|
56
|
+
/**
|
|
57
|
+
* Resolve the parts from right to left, up to the first absolute
|
|
58
|
+
* part. There is no working directory here: if no part is absolute,
|
|
59
|
+
* the result is a relative path.
|
|
60
|
+
*/
|
|
61
|
+
const resolve = (...parts) => {
|
|
62
|
+
let path = '';
|
|
63
|
+
for (let i = parts.length - 1; i >= 0 && !(0, exports.isAbsolute)(path); i--) {
|
|
64
|
+
const part = parts[i];
|
|
65
|
+
if (part)
|
|
66
|
+
path = path ? part + '/' + path : part;
|
|
67
|
+
}
|
|
68
|
+
const res = (0, exports.normalize)(path);
|
|
69
|
+
return res.length > 1 && res.endsWith('/') ? res.slice(0, -1) : res;
|
|
70
|
+
};
|
|
71
|
+
exports.resolve = resolve;
|
|
72
|
+
/** The relative path from `from` to `to`. */
|
|
73
|
+
const relative = (from, to) => {
|
|
74
|
+
const f = (0, exports.resolve)(from).split('/');
|
|
75
|
+
const t = (0, exports.resolve)(to).split('/');
|
|
76
|
+
// The root gives an empty last part.
|
|
77
|
+
if (!f[f.length - 1])
|
|
78
|
+
f.pop();
|
|
79
|
+
if (!t[t.length - 1])
|
|
80
|
+
t.pop();
|
|
81
|
+
let same = 0;
|
|
82
|
+
while (same < f.length && same < t.length && f[same] === t[same])
|
|
83
|
+
same++;
|
|
84
|
+
return [
|
|
85
|
+
...Array.from({ length: f.length - same }, () => '..'),
|
|
86
|
+
...t.slice(same),
|
|
87
|
+
].join('/');
|
|
88
|
+
};
|
|
89
|
+
exports.relative = relative;
|
|
90
|
+
//# sourceMappingURL=path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":";AAAA,mEAAmE;AACnE,gEAAgE;;;AAEhE,+DAA+D;AACxD,MAAM,SAAS,GAAG,CAAC,IAAY,EAAU,EAAE;IAChD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAA;IAC1C,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,GAAG;YAAE,SAAQ;QACzC,IAAI,IAAI,KAAK,IAAI;YAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aAC5B,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI;YAAE,GAAG,CAAC,GAAG,EAAE,CAAA;aACzD,IAAI,CAAC,QAAQ;YAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC;IACD,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,CAAA;IACnE,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,C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AA6C;AACtC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAU,EAAU,EAAE;IAC3D,MAAM,CAAC,GAAG,IAAA,eAAO,EAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClC,MAAM,CAAC,GAAG,IAAA,eAAO,EAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAChC,qCAAqC;IACrC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QAAE,CAAC,CAAC,GAAG,EAAE,CAAA;IAC7B,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QAAE,CAAC,CAAC,GAAG,EAAE,CAAA;IAC7B,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,OAAO,IAAI,GAAG,CAAC,CAAC,MAAM,IAAI,IAAI,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;QAAE,IAAI,EAAE,CAAA;IACxE,OAAO;QACL,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,GAAG,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC;QACtD,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;KACjB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACb,CAAC,CAAA;AAZY,QAAA,QAAQ,YAYpB","sourcesContent":["// The POSIX path functions that tar paths need. Each one gives the\n// same result as the function of the same name in `path.posix`.\n\n/** Resolve `.` and `..` parts, and remove repeated slashes. */\nexport const normalize = (path: string): string => {\n const absolute = path.charCodeAt(0) === 47\n const out: string[] = []\n for (const part of path.split('/')) {\n if (part === '' || part === '.') continue\n if (part !== '..') out.push(part)\n else if (out.length && out[out.length - 1] !== '..') out.pop()\n else if (!absolute) out.push(part)\n }\n const trail = out.length && path.charCodeAt(path.length - 1) === 47\n const res = out.join('/') + (trail ? '/' : '')\n if (absolute) return '/' + res\n return res || (path.endsWith('/') ? './' : '.')\n}\n\n/** Join the parts with a slash, then normalize the result. */\nexport const join = (...parts: string[]): string =>\n normalize(parts.filter(p => p).join('/'))\n\n/** The path without its last part. */\nexport const dirname = (path: string): string => {\n let end = path.length\n while (end > 1 && path.charCodeAt(end - 1) === 47) end--\n const slash = path.lastIndexOf('/', end - 1)\n if (slash === -1) return '.'\n if (slash === 0) return '/'\n if (slash === 1 && path.charCodeAt(0) === 47) return '//'\n return path.slice(0, slash)\n}\n\n/** The last part of the path. */\nexport const basename = (path: string): string => {\n let end = path.length\n while (end > 0 && path.charCodeAt(end - 1) === 47) end--\n return path.slice(path.lastIndexOf('/', end - 1) + 1, end)\n}\n\n/** True if the path starts with a slash. */\nexport const isAbsolute = (path: string): boolean =>\n path.charCodeAt(0) === 47\n\n/**\n * Resolve the parts from right to left, up to the first absolute\n * part. There is no working directory here: if no part is absolute,\n * the result is a relative path.\n */\nexport const resolve = (...parts: string[]): string => {\n let path = ''\n for (let i = parts.length - 1; i >= 0 && !isAbsolute(path); i--) {\n const part = parts[i]\n if (part) path = path ? part + '/' + path : part\n }\n const res = normalize(path)\n return res.length > 1 && res.endsWith('/') ? res.slice(0, -1) : res\n}\n\n/** The relative path from `from` to `to`. */\nexport const relative = (from: string, to: string): string => {\n const f = resolve(from).split('/')\n const t = resolve(to).split('/')\n // The root gives an empty last part.\n if (!f[f.length - 1]) f.pop()\n if (!t[t.length - 1]) t.pop()\n let same = 0\n while (same < f.length && same < t.length && f[same] === t[same]) same++\n return [\n ...Array.from({ length: f.length - same }, () => '..'),\n ...t.slice(same),\n ].join('/')\n}\n"]}
|
package/dist/commonjs/pax.d.ts
CHANGED
|
@@ -18,9 +18,11 @@ export declare class Pax implements HeaderData {
|
|
|
18
18
|
mode?: number;
|
|
19
19
|
global: boolean;
|
|
20
20
|
constructor(obj: HeaderData, global?: boolean);
|
|
21
|
-
encode():
|
|
21
|
+
encode(): Uint8Array<ArrayBuffer>;
|
|
22
22
|
encodeBody(): string;
|
|
23
23
|
encodeField(field: keyof Pax): string;
|
|
24
24
|
static parse(str: string, ex?: HeaderData, g?: boolean): Pax;
|
|
25
|
+
/** Parse the body of a PAX header entry. */
|
|
26
|
+
static parseBytes(buf: Uint8Array, ex?: HeaderData, g?: boolean): Pax;
|
|
25
27
|
}
|
|
26
28
|
//# sourceMappingURL=pax.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pax.d.ts","sourceRoot":"","sources":["../../src/pax.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pax.d.ts","sourceRoot":"","sources":["../../src/pax.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAO7C,qBAAa,GAAI,YAAW,UAAU;IACpC,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,KAAK,CAAC,EAAE,IAAI,CAAA;IAEZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,MAAM,EAAE,OAAO,CAAA;gBAEH,GAAG,EAAE,UAAU,EAAE,MAAM,GAAE,OAAe;IAmBpD,MAAM;IAqCN,UAAU;IAoBV,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,MAAM;IA2BrC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,GAAE,OAAe;IAI7D,4CAA4C;IAC5C,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,GAAE,OAAe;CAGvE"}
|
package/dist/commonjs/pax.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Pax = void 0;
|
|
4
|
-
const node_path_1 = require("node:path");
|
|
5
4
|
const header_js_1 = require("./header.js");
|
|
6
|
-
const
|
|
5
|
+
const bytes_js_1 = require("./bytes.js");
|
|
6
|
+
const path_js_1 = require("./path.js");
|
|
7
|
+
const SIMPLE_NUMBER = /^\d+$/;
|
|
7
8
|
class Pax {
|
|
8
9
|
atime;
|
|
9
10
|
mtime;
|
|
@@ -43,24 +44,18 @@ class Pax {
|
|
|
43
44
|
encode() {
|
|
44
45
|
const body = this.encodeBody();
|
|
45
46
|
if (body === '') {
|
|
46
|
-
return
|
|
47
|
+
return new Uint8Array(0);
|
|
47
48
|
}
|
|
48
|
-
const bodyLen =
|
|
49
|
+
const bodyLen = (0, bytes_js_1.utf8Length)(body);
|
|
49
50
|
// round up to 512 bytes
|
|
50
51
|
// add 512 for header
|
|
51
52
|
const bufLen = 512 * Math.ceil(1 + bodyLen / 512);
|
|
52
|
-
const buf =
|
|
53
|
-
// 0-fill the header section, it might not hit every field
|
|
54
|
-
for (let i = 0; i < 512; i++) {
|
|
55
|
-
buf[i] = 0;
|
|
56
|
-
}
|
|
53
|
+
const buf = new Uint8Array(bufLen);
|
|
57
54
|
new header_js_1.Header({
|
|
58
55
|
// XXX split the path
|
|
59
56
|
// then the path should be PaxHeader + basename, but less than 99,
|
|
60
57
|
// prepend with the dirname
|
|
61
|
-
|
|
62
|
-
path: ('PaxHeader/' + (0, node_path_1.basename)(this.path ?? '')).slice(0, 99),
|
|
63
|
-
/* c8 ignore stop */
|
|
58
|
+
path: ('PaxHeader/' + (0, path_js_1.basename)(this.path ?? '')).slice(0, 99),
|
|
64
59
|
mode: this.mode || 0o644,
|
|
65
60
|
uid: this.uid,
|
|
66
61
|
gid: this.gid,
|
|
@@ -75,11 +70,7 @@ class Pax {
|
|
|
75
70
|
atime: this.atime,
|
|
76
71
|
ctime: this.ctime,
|
|
77
72
|
}).encode(buf);
|
|
78
|
-
|
|
79
|
-
// null pad after the body
|
|
80
|
-
for (let i = bodyLen + 512; i < buf.length; i++) {
|
|
81
|
-
buf[i] = 0;
|
|
82
|
-
}
|
|
73
|
+
(0, bytes_js_1.encodeUtf8Into)(body, buf, 512, bodyLen);
|
|
83
74
|
return buf;
|
|
84
75
|
}
|
|
85
76
|
encodeBody() {
|
|
@@ -104,7 +95,7 @@ class Pax {
|
|
|
104
95
|
return '';
|
|
105
96
|
}
|
|
106
97
|
const r = this[field];
|
|
107
|
-
const v = r
|
|
98
|
+
const v = typeof r === 'object' ? r.getTime() / 1000 : r;
|
|
108
99
|
const s = ' ' +
|
|
109
100
|
(field === 'dev' || field === 'ino' || field === 'nlink' ?
|
|
110
101
|
'SCHILY.'
|
|
@@ -113,7 +104,7 @@ class Pax {
|
|
|
113
104
|
'=' +
|
|
114
105
|
v +
|
|
115
106
|
'\n';
|
|
116
|
-
const byteLen =
|
|
107
|
+
const byteLen = (0, bytes_js_1.utf8Length)(s);
|
|
117
108
|
// the digits includes the length of the digits in ascii base-10
|
|
118
109
|
// so if it's 9 characters, then adding 1 for the 9 makes it 10
|
|
119
110
|
// which makes it 11 chars.
|
|
@@ -125,30 +116,50 @@ class Pax {
|
|
|
125
116
|
return len + s;
|
|
126
117
|
}
|
|
127
118
|
static parse(str, ex, g = false) {
|
|
128
|
-
return new
|
|
119
|
+
return Pax.parseBytes(new TextEncoder().encode(str), ex, g);
|
|
120
|
+
}
|
|
121
|
+
/** Parse the body of a PAX header entry. */
|
|
122
|
+
static parseBytes(buf, ex, g = false) {
|
|
123
|
+
return new Pax(merge(parseKV(buf), ex), g);
|
|
129
124
|
}
|
|
130
125
|
}
|
|
131
126
|
exports.Pax = Pax;
|
|
132
127
|
const merge = (a, b) => b ? Object.assign({}, b, a) : a;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
128
|
+
// Each record is "<len> <key>=<value>\n". <len> is the byte length of
|
|
129
|
+
// the whole record. A value can contain a newline, so use the length
|
|
130
|
+
// to find the end of the record. Stop at the first malformed record.
|
|
131
|
+
const parseKV = (buf) => {
|
|
132
|
+
const set = Object.create(null);
|
|
133
|
+
let pos = 0;
|
|
134
|
+
while (pos < buf.length) {
|
|
135
|
+
let sp = pos;
|
|
136
|
+
while (sp < buf.length &&
|
|
137
|
+
buf[sp] >= 0x30 &&
|
|
138
|
+
buf[sp] <= 0x39) {
|
|
139
|
+
sp++;
|
|
140
|
+
}
|
|
141
|
+
if (sp === pos || buf[sp] !== 0x20)
|
|
142
|
+
break;
|
|
143
|
+
const n = Number((0, bytes_js_1.decodeUtf8)(buf, pos, sp));
|
|
144
|
+
const end = pos + n;
|
|
145
|
+
if (end <= sp + 1 || end > buf.length || buf[end - 1] !== 0x0a)
|
|
146
|
+
break;
|
|
147
|
+
parseKVLine(set, (0, bytes_js_1.decodeUtf8)(buf, sp + 1, end - 1));
|
|
148
|
+
pos = end;
|
|
143
149
|
}
|
|
144
|
-
|
|
150
|
+
return set;
|
|
151
|
+
};
|
|
152
|
+
const parseKVLine = (set, line) => {
|
|
145
153
|
const kv = line.split('=');
|
|
146
154
|
const r = kv.shift();
|
|
147
155
|
if (!r) {
|
|
148
156
|
return set;
|
|
149
157
|
}
|
|
150
158
|
const k = r.replace(/^SCHILY\.(dev|ino|nlink)/, '$1');
|
|
151
|
-
|
|
159
|
+
// The value ends at the first NUL.
|
|
160
|
+
const joined = kv.join('=');
|
|
161
|
+
const nul = joined.indexOf('\0');
|
|
162
|
+
const v = nul === -1 ? joined : joined.slice(0, nul);
|
|
152
163
|
switch (k) {
|
|
153
164
|
case 'path':
|
|
154
165
|
case 'linkpath':
|
|
@@ -162,25 +173,24 @@ const parseKVLine = (set, line) => {
|
|
|
162
173
|
case 'ctime':
|
|
163
174
|
case 'atime':
|
|
164
175
|
case 'mtime':
|
|
165
|
-
|
|
176
|
+
const d = new Date(Number(v) * 1000);
|
|
177
|
+
if (!isNaN(d.getTime()))
|
|
178
|
+
set[k] = d;
|
|
166
179
|
break;
|
|
167
180
|
case 'size':
|
|
168
|
-
// value must be a string of digits with no negative sign
|
|
169
|
-
if (!SIMPLE_NUMBER.test(v.trim()))
|
|
170
|
-
break;
|
|
171
|
-
const s = +v;
|
|
172
|
-
// must be a finite, non-negative integer, like the binary header path
|
|
173
|
-
if (!Number.isSafeInteger(s))
|
|
174
|
-
break;
|
|
175
|
-
set[k] = s;
|
|
176
|
-
break;
|
|
177
181
|
case 'gid':
|
|
178
182
|
case 'uid':
|
|
179
183
|
case 'dev':
|
|
180
184
|
case 'ino':
|
|
181
185
|
case 'nlink':
|
|
182
186
|
case 'mode':
|
|
183
|
-
|
|
187
|
+
// value must be a string of decimal digits
|
|
188
|
+
if (!SIMPLE_NUMBER.test(v.trim()))
|
|
189
|
+
break;
|
|
190
|
+
const s = +v;
|
|
191
|
+
if (!Number.isSafeInteger(s))
|
|
192
|
+
break;
|
|
193
|
+
set[k] = s;
|
|
184
194
|
break;
|
|
185
195
|
}
|
|
186
196
|
return set;
|