tar 7.5.23 → 8.0.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 +1705 -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 -37
- 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 +135 -89
- package/dist/commonjs/unpack.d.ts.map +1 -1
- package/dist/commonjs/unpack.js +760 -727
- 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 -36
- 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 +135 -89
- package/dist/esm/unpack.d.ts.map +1 -1
- package/dist/esm/unpack.js +756 -721
- 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
package/dist/commonjs/unpack.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// the PEND/UNPEND stuff tracks whether we're ready to emit end/close yet.
|
|
3
|
-
// but the path reservations are required to avoid race conditions where
|
|
4
|
-
// parallelized unpack ops may mess with one another, due to dependencies
|
|
5
|
-
// (like a Link depending on its target) or destructive operations (like
|
|
6
|
-
// clobbering an fs object to create one of a different type.)
|
|
7
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
3
|
if (k2 === undefined) k2 = k;
|
|
9
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -37,376 +32,338 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
37
32
|
return result;
|
|
38
33
|
};
|
|
39
34
|
})();
|
|
40
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
-
};
|
|
43
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.UnpackSync = exports.Unpack = void 0;
|
|
45
|
-
const
|
|
46
|
-
const node_assert_1 = __importDefault(require("node:assert"));
|
|
47
|
-
const node_crypto_1 = require("node:crypto");
|
|
48
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
49
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
50
|
-
const get_write_flag_js_1 = require("./get-write-flag.js");
|
|
51
|
-
const mkdir_js_1 = require("./mkdir.js");
|
|
52
|
-
const normalize_windows_path_js_1 = require("./normalize-windows-path.js");
|
|
53
|
-
const parse_js_1 = require("./parse.js");
|
|
54
|
-
const strip_absolute_path_js_1 = require("./strip-absolute-path.js");
|
|
36
|
+
exports.UnpackSync = exports.Unpack = exports.UnpackBase = void 0;
|
|
37
|
+
const symlink_error_js_1 = require("./symlink-error.js");
|
|
55
38
|
const wc = __importStar(require("./winchars.js"));
|
|
39
|
+
const entries_js_1 = require("./entries.js");
|
|
40
|
+
const mkdir_js_1 = require("./mkdir.js");
|
|
41
|
+
const options_js_1 = require("./options.js");
|
|
56
42
|
const path_reservations_js_1 = require("./path-reservations.js");
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const ISREUSABLE = Symbol('isReusable');
|
|
63
|
-
const MAKEFS = Symbol('makeFs');
|
|
64
|
-
const FILE = Symbol('file');
|
|
65
|
-
const DIRECTORY = Symbol('directory');
|
|
66
|
-
const LINK = Symbol('link');
|
|
67
|
-
const SYMLINK = Symbol('symlink');
|
|
68
|
-
const HARDLINK = Symbol('hardlink');
|
|
69
|
-
const ENSURE_NO_SYMLINK = Symbol('ensureNoSymlink');
|
|
70
|
-
const UNSUPPORTED = Symbol('unsupported');
|
|
71
|
-
const CHECKPATH = Symbol('checkPath');
|
|
72
|
-
const STRIPABSOLUTEPATH = Symbol('stripAbsolutePath');
|
|
73
|
-
const MKDIR = Symbol('mkdir');
|
|
74
|
-
const ONERROR = Symbol('onError');
|
|
75
|
-
const PENDING = Symbol('pending');
|
|
76
|
-
const PEND = Symbol('pend');
|
|
77
|
-
const UNPEND = Symbol('unpend');
|
|
78
|
-
const ENDED = Symbol('ended');
|
|
79
|
-
const MAYBECLOSE = Symbol('maybeClose');
|
|
80
|
-
const SKIP = Symbol('skip');
|
|
81
|
-
const DOCHOWN = Symbol('doChown');
|
|
82
|
-
const UID = Symbol('uid');
|
|
83
|
-
const GID = Symbol('gid');
|
|
84
|
-
const CHECKED_CWD = Symbol('checkedCwd');
|
|
85
|
-
const platform = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
|
|
86
|
-
const isWindows = platform === 'win32';
|
|
43
|
+
const path_js_1 = require("./path.js");
|
|
44
|
+
const strip_absolute_path_js_1 = require("./strip-absolute-path.js");
|
|
45
|
+
const warn_js_1 = require("./warn.js");
|
|
46
|
+
const win32_path_js_1 = require("./win32-path.js");
|
|
47
|
+
const write_flag_js_1 = require("./write-flag.js");
|
|
87
48
|
const DEFAULT_MAX_DEPTH = 1024;
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
//
|
|
102
|
-
// See: https://github.com/npm/node-tar/issues/183
|
|
103
|
-
/* c8 ignore start */
|
|
104
|
-
const unlinkFile = (path, cb) => {
|
|
105
|
-
if (!isWindows) {
|
|
106
|
-
return node_fs_1.default.unlink(path, cb);
|
|
107
|
-
}
|
|
108
|
-
const name = path + '.DELETE.' + (0, node_crypto_1.randomBytes)(16).toString('hex');
|
|
109
|
-
node_fs_1.default.rename(path, name, er => {
|
|
110
|
-
if (er) {
|
|
111
|
-
return cb(er);
|
|
112
|
-
}
|
|
113
|
-
node_fs_1.default.unlink(name, cb);
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
/* c8 ignore stop */
|
|
117
|
-
/* c8 ignore start */
|
|
118
|
-
const unlinkFileSync = (path) => {
|
|
119
|
-
if (!isWindows) {
|
|
120
|
-
return node_fs_1.default.unlinkSync(path);
|
|
121
|
-
}
|
|
122
|
-
const name = path + '.DELETE.' + (0, node_crypto_1.randomBytes)(16).toString('hex');
|
|
123
|
-
node_fs_1.default.renameSync(path, name);
|
|
124
|
-
node_fs_1.default.unlinkSync(name);
|
|
125
|
-
};
|
|
126
|
-
/* c8 ignore stop */
|
|
127
|
-
// this.gid, entry.gid, this.processUid
|
|
128
|
-
const uint32 = (a, b, c) => a !== undefined && a === a >>> 0 ? a
|
|
49
|
+
// Longer than any path that a supported platform can create.
|
|
50
|
+
const MAX_PATH_LENGTH = 32768;
|
|
51
|
+
const DEFAULT_JOBS = 16;
|
|
52
|
+
const fileTypes = new Set([
|
|
53
|
+
'File',
|
|
54
|
+
'OldFile',
|
|
55
|
+
'ContiguousFile',
|
|
56
|
+
]);
|
|
57
|
+
const dirTypes = new Set(['Directory', 'GNUDumpDir']);
|
|
58
|
+
const linkTypes = new Set(['Link', 'SymbolicLink']);
|
|
59
|
+
// The first of the values that is an unsigned 32-bit integer, or the
|
|
60
|
+
// last value.
|
|
61
|
+
const uint32 = (a, b, c) => a !== undefined ? a
|
|
129
62
|
: b !== undefined && b === b >>> 0 ? b
|
|
130
63
|
: c;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
64
|
+
/**
|
|
65
|
+
* The parts of the extraction that do not use the file system: the
|
|
66
|
+
* options, the checks of each entry, and the warnings. `Unpack` and
|
|
67
|
+
* `UnpackSync` add the file system work.
|
|
68
|
+
*/
|
|
69
|
+
class UnpackBase {
|
|
70
|
+
/** The options, with no prototype. */
|
|
71
|
+
opt;
|
|
72
|
+
/** The absolute path of the extraction directory. */
|
|
73
|
+
cwd;
|
|
74
|
+
win32;
|
|
75
|
+
strip;
|
|
76
|
+
maxDepth;
|
|
77
|
+
preservePaths;
|
|
78
|
+
unlink;
|
|
79
|
+
keep;
|
|
80
|
+
newer;
|
|
81
|
+
noMtime;
|
|
82
|
+
chmod;
|
|
139
83
|
uid;
|
|
140
84
|
gid;
|
|
141
|
-
setOwner;
|
|
142
85
|
preserveOwner;
|
|
143
|
-
processGid;
|
|
144
|
-
processUid;
|
|
145
|
-
maxDepth;
|
|
146
86
|
forceChown;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
keep;
|
|
150
|
-
noMtime;
|
|
151
|
-
preservePaths;
|
|
152
|
-
unlink;
|
|
153
|
-
cwd;
|
|
154
|
-
strip;
|
|
87
|
+
processUid;
|
|
88
|
+
processGid;
|
|
155
89
|
processUmask;
|
|
156
90
|
umask;
|
|
157
91
|
dmode;
|
|
158
92
|
fmode;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
93
|
+
/** Gives the `open` flag for a new file of a given size. */
|
|
94
|
+
writeFlag;
|
|
95
|
+
/** Resolve a path from an absolute path. */
|
|
96
|
+
resolve;
|
|
97
|
+
/** The parent directory of an absolute path. */
|
|
98
|
+
dirname;
|
|
99
|
+
/** Set when an error stops the extraction. */
|
|
100
|
+
fatal;
|
|
101
|
+
constructor(options) {
|
|
102
|
+
const opt = (this.opt = (0, options_js_1.ownOptions)(options));
|
|
103
|
+
const win32 = (this.win32 = opt.platform === 'win32');
|
|
104
|
+
this.resolve = win32 ? win32_path_js_1.win32Resolve : path_js_1.resolve;
|
|
105
|
+
this.dirname = win32 ? win32_path_js_1.win32Dirname : path_js_1.dirname;
|
|
106
|
+
if (typeof opt.cwd !== 'string') {
|
|
107
|
+
throw new TypeError('cwd is required');
|
|
108
|
+
}
|
|
109
|
+
const cwd = win32 ? opt.cwd.replaceAll('\\', '/') : opt.cwd;
|
|
110
|
+
if (!(win32 ? win32_path_js_1.win32IsAbsolute : path_js_1.isAbsolute)(cwd)) {
|
|
111
|
+
throw new TypeError('cwd must be an absolute path');
|
|
112
|
+
}
|
|
113
|
+
this.cwd = this.resolve(cwd, '');
|
|
168
114
|
if (typeof opt.uid === 'number' || typeof opt.gid === 'number') {
|
|
169
115
|
// need both or neither
|
|
170
116
|
if (typeof opt.uid !== 'number' || typeof opt.gid !== 'number') {
|
|
171
117
|
throw new TypeError('cannot set owner without number uid and gid');
|
|
172
118
|
}
|
|
119
|
+
// A value that is not valid must not fall back to the owner
|
|
120
|
+
// in the archive.
|
|
121
|
+
if (opt.uid !== opt.uid >>> 0 || opt.gid !== opt.gid >>> 0) {
|
|
122
|
+
throw new TypeError('uid and gid must be unsigned 32-bit integers');
|
|
123
|
+
}
|
|
173
124
|
if (opt.preserveOwner) {
|
|
174
125
|
throw new TypeError('cannot preserve owner in archive and also set owner explicitly');
|
|
175
126
|
}
|
|
176
127
|
this.uid = opt.uid;
|
|
177
128
|
this.gid = opt.gid;
|
|
178
|
-
this.setOwner = true;
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
this.uid = undefined;
|
|
182
|
-
this.gid = undefined;
|
|
183
|
-
this.setOwner = false;
|
|
184
129
|
}
|
|
185
|
-
|
|
130
|
+
this.processUid = opt.processUid;
|
|
131
|
+
this.processGid = opt.processGid;
|
|
186
132
|
this.preserveOwner =
|
|
187
133
|
opt.preserveOwner === undefined && typeof opt.uid !== 'number' ?
|
|
188
|
-
|
|
134
|
+
opt.processUid === 0
|
|
189
135
|
: !!opt.preserveOwner;
|
|
190
|
-
this.
|
|
191
|
-
(this.preserveOwner || this.setOwner) && process.getuid ?
|
|
192
|
-
process.getuid()
|
|
193
|
-
: undefined;
|
|
194
|
-
this.processGid =
|
|
195
|
-
(this.preserveOwner || this.setOwner) && process.getgid ?
|
|
196
|
-
process.getgid()
|
|
197
|
-
: undefined;
|
|
198
|
-
// prevent excessively deep nesting of subfolders
|
|
199
|
-
// set to `Infinity` to remove this restriction
|
|
136
|
+
this.forceChown = opt.forceChown === true;
|
|
200
137
|
this.maxDepth =
|
|
201
138
|
typeof opt.maxDepth === 'number' ? opt.maxDepth : DEFAULT_MAX_DEPTH;
|
|
202
|
-
|
|
203
|
-
// Forcibly trigger a chown on every entry, no matter what
|
|
204
|
-
this.forceChown = opt.forceChown === true;
|
|
205
|
-
// turn ><?| in filenames into 0xf000-higher encoded forms
|
|
206
|
-
this.win32 = !!opt.win32 || isWindows;
|
|
207
|
-
// do not unpack over files that are newer than what's in the archive
|
|
208
|
-
this.newer = !!opt.newer;
|
|
209
|
-
// do not unpack over ANY files
|
|
210
|
-
this.keep = !!opt.keep;
|
|
211
|
-
// do not set mtime/atime of extracted entries
|
|
212
|
-
this.noMtime = !!opt.noMtime;
|
|
213
|
-
// allow .., absolute path entries, and unpacking through symlinks
|
|
214
|
-
// without this, warn and skip .., relativize absolutes, and error
|
|
215
|
-
// on symlinks in extraction path
|
|
139
|
+
this.strip = Number(opt.strip) || 0;
|
|
216
140
|
this.preservePaths = !!opt.preservePaths;
|
|
217
|
-
// unlink files and links before writing. This breaks existing hard
|
|
218
|
-
// links, and removes symlink directories rather than erroring
|
|
219
141
|
this.unlink = !!opt.unlink;
|
|
220
|
-
this.
|
|
221
|
-
this.
|
|
222
|
-
|
|
142
|
+
this.keep = !!opt.keep;
|
|
143
|
+
this.newer = !!opt.newer;
|
|
144
|
+
this.noMtime = !!opt.noMtime;
|
|
145
|
+
this.chmod = !!opt.chmod;
|
|
146
|
+
// Without chmod, the umask of the process is not needed.
|
|
223
147
|
this.processUmask =
|
|
224
148
|
!this.chmod ? 0
|
|
225
149
|
: typeof opt.processUmask === 'number' ? opt.processUmask
|
|
226
|
-
:
|
|
150
|
+
: 0o22;
|
|
227
151
|
this.umask =
|
|
228
152
|
typeof opt.umask === 'number' ? opt.umask : this.processUmask;
|
|
229
|
-
|
|
230
|
-
this.
|
|
231
|
-
this.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
153
|
+
this.dmode = opt.dmode || 0o777 & ~this.umask;
|
|
154
|
+
this.fmode = opt.fmode || 0o666 & ~this.umask;
|
|
155
|
+
this.writeFlag = (0, write_flag_js_1.writeFlags)(opt.fs.constants, win32);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Report a problem to `onwarn`, or throw it if `strict` is set. A
|
|
159
|
+
* damaged archive is always an error here, because the extraction
|
|
160
|
+
* cannot be complete.
|
|
161
|
+
*/
|
|
162
|
+
warn(code, message, data = {}) {
|
|
238
163
|
if (code === 'TAR_BAD_ARCHIVE' || code === 'TAR_ABORT') {
|
|
239
164
|
data.recoverable = false;
|
|
240
165
|
}
|
|
241
|
-
|
|
166
|
+
data.cwd = this.cwd;
|
|
167
|
+
(0, warn_js_1.warn)(this.opt, code, message, data);
|
|
242
168
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
169
|
+
/** The options for the reader. Its warnings go to `warn()`. */
|
|
170
|
+
readerOptions() {
|
|
171
|
+
return (0, options_js_1.ownOptions)(this.opt, {
|
|
172
|
+
strict: false,
|
|
173
|
+
onwarn: (code, message, data) => data instanceof Error ?
|
|
174
|
+
this.warn(code, data)
|
|
175
|
+
: this.warn(code, message, data),
|
|
176
|
+
});
|
|
249
177
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Report the failure of one entry as a `TAR_ENTRY_ERROR` warning.
|
|
180
|
+
* Throws the error if it stops the extraction: the extraction
|
|
181
|
+
* directory is not usable, the archive cannot be read, or `strict`
|
|
182
|
+
* is set.
|
|
183
|
+
*/
|
|
184
|
+
entryError(er, entry) {
|
|
185
|
+
if (this.fatal?.error === er || er?.name === 'CwdError') {
|
|
186
|
+
throw er;
|
|
187
|
+
}
|
|
188
|
+
this.warn('TAR_ENTRY_ERROR', er, { entry });
|
|
189
|
+
}
|
|
190
|
+
/** Record the error that stops the extraction. Returns it. */
|
|
191
|
+
fail(error) {
|
|
192
|
+
this.fatal ??= { error };
|
|
193
|
+
return error;
|
|
194
|
+
}
|
|
195
|
+
// Remove the root of an absolute path, and refuse a path that can
|
|
196
|
+
// leave the extraction directory. False if the entry is refused.
|
|
197
|
+
#stripAbsolutePath(entry, field) {
|
|
253
198
|
const p = entry[field];
|
|
254
|
-
const { type } = entry;
|
|
255
199
|
if (!p || this.preservePaths)
|
|
256
200
|
return true;
|
|
257
|
-
// strip off the root
|
|
258
201
|
const [root, stripped] = (0, strip_absolute_path_js_1.stripAbsolutePath)(p);
|
|
259
|
-
const parts = stripped.replaceAll(
|
|
260
|
-
if (parts.includes('..')
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
//
|
|
264
|
-
|
|
265
|
-
// '../sibling/file' are valid if they resolve within the cwd.
|
|
266
|
-
// For paths, they just simply may not ever use .. at all.
|
|
267
|
-
if (field === 'path' || type === 'Link') {
|
|
202
|
+
const parts = stripped.replaceAll('\\', '/').split('/');
|
|
203
|
+
if (parts.includes('..')) {
|
|
204
|
+
// A path, and the target of a hard link, cannot have '..' at
|
|
205
|
+
// all. The target of a symbolic link is relative to the
|
|
206
|
+
// directory of the link, so '../sibling/file' can be valid.
|
|
207
|
+
if (field === 'path' || entry.type === 'Link') {
|
|
268
208
|
this.warn('TAR_ENTRY_ERROR', `${field} contains '..'`, {
|
|
269
209
|
entry,
|
|
270
210
|
[field]: p,
|
|
271
211
|
});
|
|
272
|
-
// not ok!
|
|
273
212
|
return false;
|
|
274
213
|
}
|
|
275
|
-
//
|
|
276
|
-
//
|
|
277
|
-
//
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
214
|
+
// A '..' is only safe at the start of the target. Any named
|
|
215
|
+
// part before it can be a symlink, and then the '..' goes to
|
|
216
|
+
// the parent of the target of that symlink.
|
|
217
|
+
const firstName = parts.findIndex(part => part !== '..' && part !== '.' && part !== '');
|
|
218
|
+
if (firstName !== -1 && parts.includes('..', firstName)) {
|
|
219
|
+
this.warn('TAR_ENTRY_ERROR', `${field} contains '..' after a path portion`, { entry, [field]: p });
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
// Normalize the path, so that the directory is the one where
|
|
223
|
+
// the link is created. The path 'x/.' creates the link 'x'.
|
|
224
|
+
const entryDir = (0, path_js_1.dirname)((0, path_js_1.normalize)(entry.path));
|
|
225
|
+
const resolved = (0, path_js_1.normalize)((0, path_js_1.join)(entryDir, parts.join('/')));
|
|
281
226
|
if (resolved.startsWith('../') || resolved === '..') {
|
|
282
|
-
this.warn('TAR_ENTRY_ERROR', `${field} escapes extraction directory`, {
|
|
283
|
-
entry,
|
|
284
|
-
[field]: p,
|
|
285
|
-
});
|
|
227
|
+
this.warn('TAR_ENTRY_ERROR', `${field} escapes extraction directory`, { entry, [field]: p });
|
|
286
228
|
return false;
|
|
287
229
|
}
|
|
288
230
|
}
|
|
289
231
|
if (root) {
|
|
290
|
-
|
|
291
|
-
entry[field] =
|
|
292
|
-
this.warn('TAR_ENTRY_INFO', `stripping ${root} from absolute ${field}`, {
|
|
293
|
-
entry,
|
|
294
|
-
[field]: p,
|
|
295
|
-
});
|
|
232
|
+
;
|
|
233
|
+
entry[field] = stripped;
|
|
234
|
+
this.warn('TAR_ENTRY_INFO', `stripping ${root} from absolute ${field}`, { entry, [field]: p });
|
|
296
235
|
}
|
|
297
236
|
return true;
|
|
298
237
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
238
|
+
/**
|
|
239
|
+
* Check the entry, with no use of the file system. Set its
|
|
240
|
+
* `absolute` path, and change its `path`, `linkpath`, and `mode` to
|
|
241
|
+
* the values to extract. False if the entry must not be extracted.
|
|
242
|
+
*/
|
|
243
|
+
check(entry) {
|
|
244
|
+
const p = entry.path;
|
|
302
245
|
const parts = p.split('/');
|
|
303
246
|
if (this.strip) {
|
|
304
|
-
if (parts.length < this.strip)
|
|
247
|
+
if (parts.length < this.strip)
|
|
305
248
|
return false;
|
|
306
|
-
}
|
|
307
249
|
if (entry.type === 'Link') {
|
|
308
|
-
const linkparts =
|
|
309
|
-
if (linkparts.length
|
|
310
|
-
entry.linkpath = linkparts.slice(this.strip).join('/');
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
250
|
+
const linkparts = String(entry.linkpath).split('/');
|
|
251
|
+
if (linkparts.length < this.strip)
|
|
313
252
|
return false;
|
|
314
|
-
|
|
253
|
+
entry.linkpath = linkparts.slice(this.strip).join('/');
|
|
315
254
|
}
|
|
316
255
|
parts.splice(0, this.strip);
|
|
256
|
+
// No part of the path is left, as for the top directory of a
|
|
257
|
+
// package. The entry must not change the extraction directory.
|
|
258
|
+
if (parts.every(part => part === ''))
|
|
259
|
+
return false;
|
|
317
260
|
entry.path = parts.join('/');
|
|
318
261
|
}
|
|
319
|
-
|
|
262
|
+
const { maxDepth } = this;
|
|
263
|
+
if (isFinite(maxDepth) && parts.length > maxDepth) {
|
|
320
264
|
this.warn('TAR_ENTRY_ERROR', 'path excessively deep', {
|
|
321
265
|
entry,
|
|
322
266
|
path: p,
|
|
323
267
|
depth: parts.length,
|
|
324
|
-
maxDepth
|
|
268
|
+
maxDepth,
|
|
269
|
+
});
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
// The path reservations do work for each parent directory of the
|
|
273
|
+
// path and of the linkpath.
|
|
274
|
+
const { linkpath } = entry;
|
|
275
|
+
if (linkpath &&
|
|
276
|
+
isFinite(maxDepth) &&
|
|
277
|
+
linkpath.split('/').length > maxDepth) {
|
|
278
|
+
this.warn('TAR_ENTRY_ERROR', 'linkpath excessively deep', {
|
|
279
|
+
entry,
|
|
280
|
+
path: p,
|
|
281
|
+
linkpath,
|
|
282
|
+
maxDepth,
|
|
325
283
|
});
|
|
326
284
|
return false;
|
|
327
285
|
}
|
|
328
|
-
|
|
329
|
-
|
|
286
|
+
for (const field of ['path', 'linkpath']) {
|
|
287
|
+
const { length } = entry[field] ?? '';
|
|
288
|
+
if (length > MAX_PATH_LENGTH) {
|
|
289
|
+
this.warn('TAR_ENTRY_ERROR', `${field} excessively long`, {
|
|
290
|
+
entry,
|
|
291
|
+
path: p,
|
|
292
|
+
length,
|
|
293
|
+
maxLength: MAX_PATH_LENGTH,
|
|
294
|
+
});
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (!this.#stripAbsolutePath(entry, 'path') ||
|
|
299
|
+
!this.#stripAbsolutePath(entry, 'linkpath')) {
|
|
330
300
|
return false;
|
|
331
301
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
// if we somehow ended up with a path that escapes the cwd, and we are
|
|
337
|
-
// not in preservePaths mode, then something is fishy! This should have
|
|
338
|
-
// been prevented above, so ignore this for coverage.
|
|
339
|
-
/* c8 ignore start - defense in depth */
|
|
302
|
+
const { cwd } = this;
|
|
303
|
+
let absolute = this.resolve(cwd, entry.path);
|
|
304
|
+
// The checks above refuse a path that leaves the extraction
|
|
305
|
+
// directory. This check is defense in depth.
|
|
340
306
|
if (!this.preservePaths &&
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
307
|
+
absolute !== cwd &&
|
|
308
|
+
// A root, such as `/` or `c:/`, ends with a slash.
|
|
309
|
+
!absolute.startsWith(cwd.endsWith('/') ? cwd : cwd + '/')) {
|
|
344
310
|
this.warn('TAR_ENTRY_ERROR', 'path escaped extraction target', {
|
|
345
311
|
entry,
|
|
346
|
-
path:
|
|
347
|
-
resolvedPath:
|
|
348
|
-
cwd
|
|
312
|
+
path: entry.path,
|
|
313
|
+
resolvedPath: absolute,
|
|
314
|
+
cwd,
|
|
349
315
|
});
|
|
350
316
|
return false;
|
|
351
317
|
}
|
|
352
|
-
|
|
353
|
-
//
|
|
354
|
-
|
|
355
|
-
if (entry.absolute === this.cwd &&
|
|
356
|
-
entry.type !== 'Directory' &&
|
|
357
|
-
entry.type !== 'GNUDumpDir') {
|
|
318
|
+
// An archive can set properties of the extraction directory, but
|
|
319
|
+
// it cannot replace it with a different kind of thing.
|
|
320
|
+
if (absolute === cwd && !dirTypes.has(entry.type))
|
|
358
321
|
return false;
|
|
359
|
-
|
|
360
|
-
// only encode : chars that aren't drive letter indicators
|
|
322
|
+
// Do not change the ':' of a drive letter.
|
|
361
323
|
if (this.win32) {
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const { root: pRoot } = node_path_1.default.win32.parse(entry.path);
|
|
324
|
+
const aRoot = (0, win32_path_js_1.win32Root)(absolute);
|
|
325
|
+
absolute = aRoot + wc.encode(absolute.slice(aRoot.length));
|
|
326
|
+
const pRoot = (0, win32_path_js_1.win32Root)(entry.path);
|
|
366
327
|
entry.path = pRoot + wc.encode(entry.path.slice(pRoot.length));
|
|
367
328
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
// eslint-disable-next-line no-fallthrough
|
|
382
|
-
case 'File':
|
|
383
|
-
case 'OldFile':
|
|
384
|
-
case 'ContiguousFile':
|
|
385
|
-
case 'Link':
|
|
386
|
-
case 'SymbolicLink':
|
|
387
|
-
return this[CHECKFS](entry);
|
|
388
|
-
case 'CharacterDevice':
|
|
389
|
-
case 'BlockDevice':
|
|
390
|
-
case 'FIFO':
|
|
391
|
-
default:
|
|
392
|
-
return this[UNSUPPORTED](entry);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
[ONERROR](er, entry) {
|
|
396
|
-
// Cwd has to exist, or else nothing works. That's serious.
|
|
397
|
-
// Other errors are warnings, which raise the error in strict
|
|
398
|
-
// mode, but otherwise continue on.
|
|
399
|
-
if (er.name === 'CwdError') {
|
|
400
|
-
this.emit('error', er);
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
this.warn('TAR_ENTRY_ERROR', er, { entry });
|
|
404
|
-
this[UNPEND]();
|
|
405
|
-
entry.resume();
|
|
329
|
+
entry.absolute = absolute;
|
|
330
|
+
// Never set the setuid, setgid, or sticky bit from an archive.
|
|
331
|
+
if (typeof entry.mode === 'number')
|
|
332
|
+
entry.mode &= 0o777;
|
|
333
|
+
if (dirTypes.has(entry.type)) {
|
|
334
|
+
if (entry.mode)
|
|
335
|
+
entry.mode |= 0o700;
|
|
336
|
+
}
|
|
337
|
+
else if (!fileTypes.has(entry.type) && !linkTypes.has(entry.type)) {
|
|
338
|
+
// A device or a FIFO is never made.
|
|
339
|
+
entry.unsupported = true;
|
|
340
|
+
this.warn('TAR_ENTRY_UNSUPPORTED', `unsupported entry type: ${entry.type}`, { entry });
|
|
341
|
+
return false;
|
|
406
342
|
}
|
|
343
|
+
return true;
|
|
407
344
|
}
|
|
408
|
-
|
|
409
|
-
|
|
345
|
+
/**
|
|
346
|
+
* The paths that the entry must have for itself while it is made.
|
|
347
|
+
* A link also reserves its target, so that an entry that makes the
|
|
348
|
+
* target, and an entry that goes through the link, do not run at
|
|
349
|
+
* the same time as the link.
|
|
350
|
+
*/
|
|
351
|
+
reservedPaths(entry) {
|
|
352
|
+
const { path, linkpath } = entry;
|
|
353
|
+
if (!linkpath)
|
|
354
|
+
return [path];
|
|
355
|
+
// The target of a symlink is relative to the directory of the
|
|
356
|
+
// link. The target of a hard link is relative to the cwd.
|
|
357
|
+
return [
|
|
358
|
+
path,
|
|
359
|
+
entry.type === 'SymbolicLink' && !(0, path_js_1.isAbsolute)(linkpath) ?
|
|
360
|
+
(0, path_js_1.join)((0, path_js_1.dirname)(path), linkpath)
|
|
361
|
+
: linkpath,
|
|
362
|
+
];
|
|
363
|
+
}
|
|
364
|
+
/** The options to make a directory with a mode. */
|
|
365
|
+
mkdirOptions(mode) {
|
|
366
|
+
return {
|
|
410
367
|
uid: this.uid,
|
|
411
368
|
gid: this.gid,
|
|
412
369
|
processUid: this.processUid,
|
|
@@ -415,517 +372,593 @@ class Unpack extends parse_js_1.Parser {
|
|
|
415
372
|
preserve: this.preservePaths,
|
|
416
373
|
unlink: this.unlink,
|
|
417
374
|
cwd: this.cwd,
|
|
418
|
-
mode
|
|
419
|
-
}
|
|
375
|
+
mode,
|
|
376
|
+
};
|
|
420
377
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
378
|
+
/**
|
|
379
|
+
* The owner to set on the entry, if it needs one: with
|
|
380
|
+
* `preserveOwner`, when the owner in the archive is not the process
|
|
381
|
+
* owner, and with `uid` and `gid`, when they are not the process
|
|
382
|
+
* owner.
|
|
383
|
+
*/
|
|
384
|
+
owner(entry) {
|
|
385
|
+
const doChown = this.forceChown ||
|
|
425
386
|
(this.preserveOwner &&
|
|
426
387
|
((typeof entry.uid === 'number' &&
|
|
427
388
|
entry.uid !== this.processUid) ||
|
|
428
389
|
(typeof entry.gid === 'number' &&
|
|
429
390
|
entry.gid !== this.processGid))) ||
|
|
430
391
|
(typeof this.uid === 'number' && this.uid !== this.processUid) ||
|
|
431
|
-
(typeof this.gid === 'number' && this.gid !== this.processGid)
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
return
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
392
|
+
(typeof this.gid === 'number' && this.gid !== this.processGid);
|
|
393
|
+
const uid = uint32(this.uid, entry.uid, this.processUid);
|
|
394
|
+
const gid = uint32(this.gid, entry.gid, this.processGid);
|
|
395
|
+
return doChown && typeof uid === 'number' && typeof gid === 'number' ?
|
|
396
|
+
{ uid, gid }
|
|
397
|
+
: undefined;
|
|
398
|
+
}
|
|
399
|
+
/** The times to set on the entry, if it needs them. */
|
|
400
|
+
times(entry) {
|
|
401
|
+
return entry.mtime && !this.noMtime ?
|
|
402
|
+
{ atime: entry.atime || new Date(), mtime: entry.mtime }
|
|
403
|
+
: undefined;
|
|
404
|
+
}
|
|
405
|
+
/** True if the object on disk at the path of the entry must stay. */
|
|
406
|
+
skip(entry, st) {
|
|
407
|
+
return (this.keep || (this.newer && st.mtime > (entry.mtime ?? st.mtime)));
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* True if the entry can be written into the file that is on disk.
|
|
411
|
+
* A file with more than one link is not used, because the write
|
|
412
|
+
* would change the other links. Windows does not report a useful
|
|
413
|
+
* link count.
|
|
414
|
+
*/
|
|
415
|
+
isReusable(entry, st) {
|
|
416
|
+
return (entry.type === 'File' &&
|
|
417
|
+
!this.unlink &&
|
|
418
|
+
st.isFile() &&
|
|
419
|
+
st.nlink <= 1 &&
|
|
420
|
+
!this.win32);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* The parts of the path from the extraction directory to the
|
|
424
|
+
* target of a link entry. None of them can be a symbolic link.
|
|
425
|
+
*/
|
|
426
|
+
linkParts(entry, absolute) {
|
|
427
|
+
const linkpath = String(entry.linkpath);
|
|
428
|
+
return entry.type === 'Link' ?
|
|
429
|
+
linkpath.split('/')
|
|
430
|
+
: (0, path_js_1.relative)(this.cwd, this.resolve(this.dirname(absolute), linkpath)).split('/');
|
|
431
|
+
}
|
|
432
|
+
/** The error for a link target that goes through a symbolic link. */
|
|
433
|
+
symlinkError(symlink, parts) {
|
|
434
|
+
return new symlink_error_js_1.SymlinkError(symlink, this.resolve(this.cwd, parts.join('/')));
|
|
438
435
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
436
|
+
}
|
|
437
|
+
exports.UnpackBase = UnpackBase;
|
|
438
|
+
// Unlinks on Windows are not atomic. A file that is made at the path
|
|
439
|
+
// of a file that was just removed can be removed with it. So rename
|
|
440
|
+
// the file first, and then remove it under the new name.
|
|
441
|
+
const deleteName = (path) => path +
|
|
442
|
+
'.DELETE.' +
|
|
443
|
+
Array.from(crypto.getRandomValues(new Uint8Array(16)), b => b.toString(16).padStart(2, '0')).join('');
|
|
444
|
+
/**
|
|
445
|
+
* Extracts the entries of an archive with async file system
|
|
446
|
+
* functions.
|
|
447
|
+
*
|
|
448
|
+
* Several entries are extracted at one time. Entries that use the
|
|
449
|
+
* same path, or a path and a directory above it, are extracted in
|
|
450
|
+
* the order of the archive.
|
|
451
|
+
*/
|
|
452
|
+
class Unpack extends UnpackBase {
|
|
453
|
+
#fs;
|
|
454
|
+
#reservations;
|
|
455
|
+
#jobs;
|
|
456
|
+
// the number of entries that are in work
|
|
457
|
+
#active = 0;
|
|
458
|
+
#wake;
|
|
459
|
+
#checkedCwd = false;
|
|
460
|
+
#cwdCheck;
|
|
461
|
+
constructor(opt) {
|
|
462
|
+
super(opt);
|
|
463
|
+
this.#fs = this.opt.fs;
|
|
464
|
+
this.#reservations = new path_reservations_js_1.PathReservations(this.win32);
|
|
465
|
+
this.#jobs = (0, options_js_1.countOption)('jobs', this.opt.jobs, DEFAULT_JOBS);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Extract the archive. The promise settles when all the file
|
|
469
|
+
* system work is done. It rejects with the first error that stops
|
|
470
|
+
* the extraction.
|
|
471
|
+
*/
|
|
472
|
+
async extract(input) {
|
|
473
|
+
const reader = new entries_js_1.TarReader(input, this.readerOptions());
|
|
474
|
+
const { onEntry } = this.opt;
|
|
475
|
+
const stream = !!this.opt.transform;
|
|
476
|
+
try {
|
|
477
|
+
while (!this.fatal) {
|
|
478
|
+
const entry = reader.poll();
|
|
479
|
+
if (entry === null)
|
|
480
|
+
break;
|
|
481
|
+
if (entry === undefined) {
|
|
482
|
+
await reader.fill();
|
|
483
|
+
continue;
|
|
464
484
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
485
|
+
if (onEntry)
|
|
486
|
+
await onEntry(entry);
|
|
487
|
+
// The caller took the content, so there is nothing to write.
|
|
488
|
+
if (entry.bodyUsed)
|
|
489
|
+
continue;
|
|
490
|
+
if (!this.check(entry))
|
|
491
|
+
continue;
|
|
492
|
+
// A file whose content is all in memory is written while the
|
|
493
|
+
// next entries are read. Other files are written as their
|
|
494
|
+
// content arrives.
|
|
495
|
+
const body = [];
|
|
496
|
+
let inMemory = !stream;
|
|
497
|
+
if (inMemory && fileTypes.has(entry.type)) {
|
|
498
|
+
for (;;) {
|
|
499
|
+
const part = reader.readBody(entry);
|
|
500
|
+
if (part === null)
|
|
501
|
+
break;
|
|
502
|
+
if (part === undefined) {
|
|
503
|
+
inMemory = false;
|
|
504
|
+
break;
|
|
478
505
|
}
|
|
479
|
-
|
|
480
|
-
}
|
|
506
|
+
body.push(part);
|
|
507
|
+
}
|
|
481
508
|
}
|
|
509
|
+
const work = this.#start(entry, body, inMemory ? undefined : reader);
|
|
510
|
+
if (!inMemory)
|
|
511
|
+
await work;
|
|
512
|
+
while (this.#active >= this.#jobs)
|
|
513
|
+
await this.#idle();
|
|
482
514
|
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
node_fs_1.default.futimes(fd, atime, mtime, er => er ?
|
|
495
|
-
node_fs_1.default.utimes(abs, atime, mtime, er2 => done(er2 && er))
|
|
496
|
-
: done());
|
|
497
|
-
}
|
|
498
|
-
if (typeof fd === 'number' && this[DOCHOWN](entry)) {
|
|
499
|
-
actions++;
|
|
500
|
-
const uid = this[UID](entry);
|
|
501
|
-
const gid = this[GID](entry);
|
|
502
|
-
if (typeof uid === 'number' && typeof gid === 'number') {
|
|
503
|
-
node_fs_1.default.fchown(fd, uid, gid, er => er ? node_fs_1.default.chown(abs, uid, gid, er2 => done(er2 && er)) : done());
|
|
504
|
-
}
|
|
515
|
+
}
|
|
516
|
+
catch (er) {
|
|
517
|
+
this.fail(er);
|
|
518
|
+
}
|
|
519
|
+
await reader.return().catch(er => this.fail(er));
|
|
520
|
+
while (this.#active > 0)
|
|
521
|
+
await this.#idle();
|
|
522
|
+
if (this.fatal) {
|
|
523
|
+
const { error } = this.fatal;
|
|
524
|
+
if (error && typeof error === 'object' && 'tarCode' in error) {
|
|
525
|
+
Object.assign(error, { cwd: this.cwd });
|
|
505
526
|
}
|
|
506
|
-
|
|
507
|
-
});
|
|
508
|
-
const tx = this.transform ? this.transform(entry) || entry : entry;
|
|
509
|
-
if (tx !== entry) {
|
|
510
|
-
tx.on('error', er => {
|
|
511
|
-
this[ONERROR](er, entry);
|
|
512
|
-
fullyDone();
|
|
513
|
-
});
|
|
514
|
-
entry.pipe(tx);
|
|
527
|
+
throw error;
|
|
515
528
|
}
|
|
516
|
-
tx.pipe(stream);
|
|
517
529
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
530
|
+
// Resolves when an entry that is in work is done.
|
|
531
|
+
#idle() {
|
|
532
|
+
return new Promise(res => {
|
|
533
|
+
this.#wake = res;
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
// Extract the entry when its paths are free. The promise never
|
|
537
|
+
// rejects: a failure is a warning, or it sets `fatal`.
|
|
538
|
+
#start(entry, body, reader) {
|
|
539
|
+
this.#active++;
|
|
540
|
+
return this.#reservations.reserve(this.reservedPaths(entry), async () => {
|
|
541
|
+
try {
|
|
542
|
+
if (!this.fatal)
|
|
543
|
+
await this.#extract(entry, body, reader);
|
|
525
544
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
545
|
+
catch (er) {
|
|
546
|
+
try {
|
|
547
|
+
this.entryError(er, entry);
|
|
548
|
+
}
|
|
549
|
+
catch (fatal) {
|
|
550
|
+
this.fail(fatal);
|
|
532
551
|
}
|
|
533
|
-
};
|
|
534
|
-
if (entry.mtime && !this.noMtime) {
|
|
535
|
-
actions++;
|
|
536
|
-
node_fs_1.default.utimes(String(entry.absolute), entry.atime || new Date(), entry.mtime, done);
|
|
537
|
-
}
|
|
538
|
-
if (this[DOCHOWN](entry)) {
|
|
539
|
-
actions++;
|
|
540
|
-
node_fs_1.default.chown(String(entry.absolute), Number(this[UID](entry)), Number(this[GID](entry)), done);
|
|
541
552
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
[UNSUPPORTED](entry) {
|
|
546
|
-
entry.unsupported = true;
|
|
547
|
-
this.warn('TAR_ENTRY_UNSUPPORTED', `unsupported entry type: ${entry.type}`, { entry });
|
|
548
|
-
entry.resume();
|
|
549
|
-
}
|
|
550
|
-
[SYMLINK](entry, done) {
|
|
551
|
-
const parts = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.relative(this.cwd, node_path_1.default.resolve(node_path_1.default.dirname(String(entry.absolute)), String(entry.linkpath)))).split('/');
|
|
552
|
-
this[ENSURE_NO_SYMLINK](entry, this.cwd, parts, () => this[LINK](entry, String(entry.linkpath), 'symlink', done), er => {
|
|
553
|
-
this[ONERROR](er, entry);
|
|
554
|
-
done();
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
[HARDLINK](entry, done) {
|
|
558
|
-
const linkpath = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.resolve(this.cwd, String(entry.linkpath)));
|
|
559
|
-
const parts = (0, normalize_windows_path_js_1.normalizeWindowsPath)(String(entry.linkpath)).split('/');
|
|
560
|
-
this[ENSURE_NO_SYMLINK](entry, this.cwd, parts, () => this[LINK](entry, linkpath, 'link', done), er => {
|
|
561
|
-
this[ONERROR](er, entry);
|
|
562
|
-
done();
|
|
553
|
+
this.#active--;
|
|
554
|
+
this.#wake?.();
|
|
563
555
|
});
|
|
564
556
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
557
|
+
#mkdir(dir, mode) {
|
|
558
|
+
return (0, mkdir_js_1.mkdir)(this.#fs, dir, this.mkdirOptions(mode));
|
|
559
|
+
}
|
|
560
|
+
// The extraction directory must exist. Entries that start at the
|
|
561
|
+
// same time share one check.
|
|
562
|
+
#checkCwd() {
|
|
563
|
+
return (this.#cwdCheck ??= this.#mkdir(this.cwd, this.dmode).then(() => {
|
|
564
|
+
this.#checkedCwd = true;
|
|
565
|
+
}, er => {
|
|
566
|
+
this.#cwdCheck = undefined;
|
|
567
|
+
throw er;
|
|
568
|
+
}));
|
|
569
|
+
}
|
|
570
|
+
async #extract(entry, body, reader) {
|
|
571
|
+
const fs = this.#fs;
|
|
572
|
+
const absolute = entry.absolute;
|
|
573
|
+
const { cwd } = this;
|
|
574
|
+
if (!this.#checkedCwd)
|
|
575
|
+
await this.#checkCwd();
|
|
576
|
+
if (absolute !== cwd) {
|
|
577
|
+
const parent = this.dirname(absolute);
|
|
578
|
+
if (parent !== cwd)
|
|
579
|
+
await this.#mkdir(parent, this.dmode);
|
|
580
|
+
}
|
|
581
|
+
// Remove what is at the path, if the entry cannot use it.
|
|
582
|
+
const st = await fs.lstat(absolute).catch(() => undefined);
|
|
583
|
+
if (st && this.skip(entry, st))
|
|
584
|
+
return;
|
|
585
|
+
if (st && !this.isReusable(entry, st)) {
|
|
586
|
+
if (st.isDirectory() && dirTypes.has(entry.type)) {
|
|
587
|
+
if (this.chmod &&
|
|
588
|
+
entry.mode &&
|
|
589
|
+
(st.mode & 0o7777) !== entry.mode) {
|
|
590
|
+
await fs.chmod(absolute, entry.mode);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
else if (absolute !== cwd) {
|
|
594
|
+
if (st.isDirectory())
|
|
595
|
+
await fs.rmdir(absolute);
|
|
596
|
+
else
|
|
597
|
+
await this.#unlink(absolute);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
if (fileTypes.has(entry.type)) {
|
|
601
|
+
return this.#file(entry, absolute, body, reader);
|
|
602
|
+
}
|
|
603
|
+
if (dirTypes.has(entry.type))
|
|
604
|
+
return this.#directory(entry, absolute);
|
|
605
|
+
await this.#ensureNoSymlink(this.linkParts(entry, absolute));
|
|
606
|
+
const linkpath = String(entry.linkpath);
|
|
607
|
+
if (entry.type === 'Link') {
|
|
608
|
+
await fs.link(this.resolve(cwd, linkpath), absolute);
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
await fs.symlink(linkpath, absolute);
|
|
612
|
+
}
|
|
585
613
|
}
|
|
586
|
-
|
|
587
|
-
this
|
|
588
|
-
|
|
614
|
+
async #unlink(path) {
|
|
615
|
+
const fs = this.#fs;
|
|
616
|
+
if (!this.win32)
|
|
617
|
+
return fs.unlink(path);
|
|
618
|
+
const name = deleteName(path);
|
|
619
|
+
await fs.rename(path, name);
|
|
620
|
+
await fs.unlink(name);
|
|
589
621
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
st.
|
|
597
|
-
st
|
|
598
|
-
|
|
622
|
+
async #ensureNoSymlink(parts) {
|
|
623
|
+
if (this.preservePaths)
|
|
624
|
+
return;
|
|
625
|
+
let t = this.cwd;
|
|
626
|
+
for (const p of parts) {
|
|
627
|
+
t = this.resolve(t, p);
|
|
628
|
+
const st = await this.#fs.lstat(t).catch(() => undefined);
|
|
629
|
+
if (!st)
|
|
630
|
+
return;
|
|
631
|
+
if (st.isSymbolicLink())
|
|
632
|
+
throw this.symlinkError(t, parts);
|
|
633
|
+
}
|
|
599
634
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
this
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
635
|
+
async #directory(entry, absolute) {
|
|
636
|
+
const fs = this.#fs;
|
|
637
|
+
await this.#mkdir(absolute, entry.mode ?? this.dmode);
|
|
638
|
+
// These do not follow a symbolic link that replaced the
|
|
639
|
+
// directory. A failure is not an error of the entry.
|
|
640
|
+
const times = this.times(entry);
|
|
641
|
+
if (times) {
|
|
642
|
+
await fs.lutimes(absolute, times.atime, times.mtime).catch(() => { });
|
|
643
|
+
}
|
|
644
|
+
const owner = this.owner(entry);
|
|
645
|
+
if (owner) {
|
|
646
|
+
await fs.lchown(absolute, owner.uid, owner.gid).catch(() => { });
|
|
606
647
|
}
|
|
607
|
-
this.reservations.reserve(paths, done => this[CHECKFS2](entry, done));
|
|
608
648
|
}
|
|
609
|
-
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
const parent = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.dirname(String(entry.absolute)));
|
|
627
|
-
if (parent !== this.cwd) {
|
|
628
|
-
return this[MKDIR](parent, this.dmode, er => {
|
|
629
|
-
if (er) {
|
|
630
|
-
this[ONERROR](er, entry);
|
|
631
|
-
done();
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
afterMakeParent();
|
|
649
|
+
async #file(entry, absolute, body, reader) {
|
|
650
|
+
const fs = this.#fs;
|
|
651
|
+
const handle = await fs.open(absolute, this.writeFlag(entry.size), entry.mode ?? this.fmode);
|
|
652
|
+
try {
|
|
653
|
+
if (reader)
|
|
654
|
+
await this.#pipe(entry, body, reader, handle);
|
|
655
|
+
else
|
|
656
|
+
for (const part of body)
|
|
657
|
+
await handle.write(part);
|
|
658
|
+
// Use the open file, so that a symbolic link that replaced the
|
|
659
|
+
// path is not followed. If that fails, use the path.
|
|
660
|
+
const times = this.times(entry);
|
|
661
|
+
if (times) {
|
|
662
|
+
const { atime, mtime } = times;
|
|
663
|
+
await handle.utimes(atime, mtime).catch(async (er) => {
|
|
664
|
+
await fs.utimes(absolute, atime, mtime).catch(() => {
|
|
665
|
+
throw er;
|
|
635
666
|
});
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
const owner = this.owner(entry);
|
|
670
|
+
if (owner) {
|
|
671
|
+
const { uid, gid } = owner;
|
|
672
|
+
await handle.chown(uid, gid).catch(async (er) => {
|
|
673
|
+
await fs.chown(absolute, uid, gid).catch(() => {
|
|
674
|
+
throw er;
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
catch (er) {
|
|
680
|
+
await handle.close().catch(() => { });
|
|
681
|
+
throw er;
|
|
682
|
+
}
|
|
683
|
+
await handle.close();
|
|
684
|
+
}
|
|
685
|
+
// Write the content of the entry as it arrives, through the
|
|
686
|
+
// transform stream if there is one.
|
|
687
|
+
async #pipe(entry, body, reader, handle) {
|
|
688
|
+
let i = 0;
|
|
689
|
+
const next = async () => {
|
|
690
|
+
if (i < body.length)
|
|
691
|
+
return body[i++];
|
|
692
|
+
try {
|
|
693
|
+
for (;;) {
|
|
694
|
+
const part = reader.readBody(entry);
|
|
695
|
+
if (part !== undefined)
|
|
696
|
+
return part;
|
|
697
|
+
await reader.fill();
|
|
636
698
|
}
|
|
637
699
|
}
|
|
638
|
-
|
|
700
|
+
catch (er) {
|
|
701
|
+
// The archive cannot be read.
|
|
702
|
+
throw this.fail(er);
|
|
703
|
+
}
|
|
639
704
|
};
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
if (st.isDirectory()) {
|
|
654
|
-
if (entry.type === 'Directory') {
|
|
655
|
-
const needChmod = this.chmod && entry.mode && (st.mode & 0o7777) !== entry.mode;
|
|
656
|
-
const afterChmod = (er) => this[MAKEFS](er ?? null, entry, done);
|
|
657
|
-
if (!needChmod) {
|
|
658
|
-
return afterChmod();
|
|
659
|
-
}
|
|
660
|
-
return node_fs_1.default.chmod(String(entry.absolute), Number(entry.mode), afterChmod);
|
|
661
|
-
}
|
|
662
|
-
// Not a dir entry, have to remove it.
|
|
663
|
-
// NB: the only way to end up with an entry that is the cwd
|
|
664
|
-
// itself, in such a way that == does not detect, is a
|
|
665
|
-
// tricky windows absolute path with UNC or 8.3 parts (and
|
|
666
|
-
// preservePaths:true, or else it will have been stripped).
|
|
667
|
-
// In that case, the user has opted out of path protections
|
|
668
|
-
// explicitly, so if they blow away the cwd, c'est la vie.
|
|
669
|
-
if (entry.absolute !== this.cwd) {
|
|
670
|
-
return node_fs_1.default.rmdir(String(entry.absolute), (er) => this[MAKEFS](er ?? null, entry, done));
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
// not a dir, and not reusable
|
|
674
|
-
// don't remove if the cwd, we want that error
|
|
675
|
-
if (entry.absolute === this.cwd) {
|
|
676
|
-
return this[MAKEFS](null, entry, done);
|
|
705
|
+
const tx = this.opt.transform?.(entry);
|
|
706
|
+
if (!tx) {
|
|
707
|
+
// Write one part while the next part is read.
|
|
708
|
+
let writing;
|
|
709
|
+
let failed;
|
|
710
|
+
try {
|
|
711
|
+
for (let part; (part = await next());) {
|
|
712
|
+
await writing;
|
|
713
|
+
if (failed)
|
|
714
|
+
break;
|
|
715
|
+
writing = handle.write(part).then(() => { }, error => {
|
|
716
|
+
failed = { error };
|
|
717
|
+
});
|
|
677
718
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
719
|
+
}
|
|
720
|
+
finally {
|
|
721
|
+
await writing;
|
|
722
|
+
}
|
|
723
|
+
if (failed)
|
|
724
|
+
throw failed.error;
|
|
725
|
+
return;
|
|
683
726
|
}
|
|
684
|
-
|
|
685
|
-
|
|
727
|
+
const writer = tx.writable.getWriter();
|
|
728
|
+
const out = tx.readable.getReader();
|
|
729
|
+
let failed;
|
|
730
|
+
// Stop the two streams. A read that waits gets the end of the
|
|
731
|
+
// stream, and a write that waits fails.
|
|
732
|
+
const stop = async (error) => {
|
|
733
|
+
failed ??= { error };
|
|
734
|
+
await out.cancel(error).catch(() => { });
|
|
735
|
+
await writer.abort(error).catch(() => { });
|
|
736
|
+
};
|
|
737
|
+
const feed = (async () => {
|
|
738
|
+
try {
|
|
739
|
+
for (let part; (part = await next());)
|
|
740
|
+
await writer.write(part);
|
|
741
|
+
await writer.close();
|
|
742
|
+
}
|
|
743
|
+
catch (er) {
|
|
744
|
+
await stop(er);
|
|
745
|
+
}
|
|
746
|
+
})();
|
|
747
|
+
try {
|
|
748
|
+
for (;;) {
|
|
749
|
+
const { done, value } = await out.read();
|
|
750
|
+
if (done)
|
|
751
|
+
break;
|
|
752
|
+
await handle.write(value);
|
|
753
|
+
}
|
|
686
754
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
if (er) {
|
|
690
|
-
this[ONERROR](er, entry);
|
|
691
|
-
done();
|
|
692
|
-
return;
|
|
755
|
+
catch (er) {
|
|
756
|
+
await stop(er);
|
|
693
757
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
case 'Link':
|
|
700
|
-
return this[HARDLINK](entry, done);
|
|
701
|
-
case 'SymbolicLink':
|
|
702
|
-
return this[SYMLINK](entry, done);
|
|
703
|
-
case 'Directory':
|
|
704
|
-
case 'GNUDumpDir':
|
|
705
|
-
return this[DIRECTORY](entry, done);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
[LINK](entry, linkpath, link, done) {
|
|
709
|
-
node_fs_1.default[link](linkpath, String(entry.absolute), er => {
|
|
710
|
-
if (er) {
|
|
711
|
-
this[ONERROR](er, entry);
|
|
712
|
-
}
|
|
713
|
-
else {
|
|
714
|
-
this[UNPEND]();
|
|
715
|
-
entry.resume();
|
|
716
|
-
}
|
|
717
|
-
done();
|
|
718
|
-
});
|
|
758
|
+
// The feed reads the archive, so it must end before the next
|
|
759
|
+
// entry is read.
|
|
760
|
+
await feed;
|
|
761
|
+
if (failed)
|
|
762
|
+
throw failed.error;
|
|
719
763
|
}
|
|
720
764
|
}
|
|
721
765
|
exports.Unpack = Unpack;
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
if (mkParent) {
|
|
750
|
-
return this[ONERROR](mkParent, entry);
|
|
766
|
+
/**
|
|
767
|
+
* Extracts the entries of an archive with sync file system
|
|
768
|
+
* functions, one entry at a time.
|
|
769
|
+
*/
|
|
770
|
+
class UnpackSync extends UnpackBase {
|
|
771
|
+
#fs;
|
|
772
|
+
#checkedCwd = false;
|
|
773
|
+
constructor(opt) {
|
|
774
|
+
super(opt);
|
|
775
|
+
this.#fs = this.opt.fs;
|
|
776
|
+
}
|
|
777
|
+
/** Extract the archive. Throws the first error that stops it. */
|
|
778
|
+
extract(input) {
|
|
779
|
+
const reader = new entries_js_1.TarReaderSync(input, this.readerOptions());
|
|
780
|
+
const { onEntry } = this.opt;
|
|
781
|
+
try {
|
|
782
|
+
for (const entry of reader) {
|
|
783
|
+
onEntry?.(entry);
|
|
784
|
+
if (entry.bodyUsed)
|
|
785
|
+
continue;
|
|
786
|
+
if (!this.check(entry))
|
|
787
|
+
continue;
|
|
788
|
+
try {
|
|
789
|
+
this.#extract(entry, reader);
|
|
790
|
+
}
|
|
791
|
+
catch (er) {
|
|
792
|
+
this.entryError(er, entry);
|
|
751
793
|
}
|
|
752
794
|
}
|
|
753
795
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
/* c8 ignore next */
|
|
758
|
-
(this.newer && st.mtime > (entry.mtime ?? st.mtime)))) {
|
|
759
|
-
return this[SKIP](entry);
|
|
760
|
-
}
|
|
761
|
-
if (lstatEr || this[ISREUSABLE](entry, st)) {
|
|
762
|
-
return this[MAKEFS](null, entry);
|
|
763
|
-
}
|
|
764
|
-
if (st.isDirectory()) {
|
|
765
|
-
if (entry.type === 'Directory') {
|
|
766
|
-
const needChmod = this.chmod && entry.mode && (st.mode & 0o7777) !== entry.mode;
|
|
767
|
-
const [er] = needChmod ?
|
|
768
|
-
callSync(() => {
|
|
769
|
-
node_fs_1.default.chmodSync(String(entry.absolute), Number(entry.mode));
|
|
770
|
-
})
|
|
771
|
-
: [];
|
|
772
|
-
return this[MAKEFS](er, entry);
|
|
773
|
-
}
|
|
774
|
-
// not a dir entry, have to remove it
|
|
775
|
-
const [er] = callSync(() => node_fs_1.default.rmdirSync(String(entry.absolute)));
|
|
776
|
-
this[MAKEFS](er, entry);
|
|
777
|
-
}
|
|
778
|
-
// not a dir, and not reusable.
|
|
779
|
-
// don't remove if it's the cwd, since we want that error.
|
|
780
|
-
const [er] = entry.absolute === this.cwd ?
|
|
781
|
-
[]
|
|
782
|
-
: callSync(() => unlinkFileSync(String(entry.absolute)));
|
|
783
|
-
this[MAKEFS](er, entry);
|
|
784
|
-
}
|
|
785
|
-
[FILE](entry, done) {
|
|
786
|
-
const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.fmode;
|
|
787
|
-
const oner = (er) => {
|
|
788
|
-
let closeError;
|
|
789
|
-
try {
|
|
790
|
-
node_fs_1.default.closeSync(fd);
|
|
796
|
+
catch (error) {
|
|
797
|
+
if (error && typeof error === 'object' && 'tarCode' in error) {
|
|
798
|
+
Object.assign(error, { cwd: this.cwd });
|
|
791
799
|
}
|
|
792
|
-
|
|
793
|
-
|
|
800
|
+
throw error;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
#mkdir(dir, mode) {
|
|
804
|
+
(0, mkdir_js_1.mkdirSync)(this.#fs, dir, this.mkdirOptions(mode));
|
|
805
|
+
}
|
|
806
|
+
#extract(entry, reader) {
|
|
807
|
+
const fs = this.#fs;
|
|
808
|
+
const absolute = entry.absolute;
|
|
809
|
+
const { cwd } = this;
|
|
810
|
+
if (!this.#checkedCwd) {
|
|
811
|
+
this.#mkdir(cwd, this.dmode);
|
|
812
|
+
this.#checkedCwd = true;
|
|
813
|
+
}
|
|
814
|
+
if (absolute !== cwd) {
|
|
815
|
+
const parent = this.dirname(absolute);
|
|
816
|
+
if (parent !== cwd)
|
|
817
|
+
this.#mkdir(parent, this.dmode);
|
|
818
|
+
}
|
|
819
|
+
// Remove what is at the path, if the entry cannot use it.
|
|
820
|
+
let st;
|
|
821
|
+
try {
|
|
822
|
+
st = fs.lstatSync(absolute);
|
|
823
|
+
}
|
|
824
|
+
catch { }
|
|
825
|
+
if (st && this.skip(entry, st))
|
|
826
|
+
return;
|
|
827
|
+
if (st && !this.isReusable(entry, st)) {
|
|
828
|
+
if (st.isDirectory() && dirTypes.has(entry.type)) {
|
|
829
|
+
if (this.chmod &&
|
|
830
|
+
entry.mode &&
|
|
831
|
+
(st.mode & 0o7777) !== entry.mode) {
|
|
832
|
+
fs.chmodSync(absolute, entry.mode);
|
|
833
|
+
}
|
|
794
834
|
}
|
|
795
|
-
if (
|
|
796
|
-
|
|
835
|
+
else if (absolute !== cwd) {
|
|
836
|
+
if (st.isDirectory())
|
|
837
|
+
fs.rmdirSync(absolute);
|
|
838
|
+
else
|
|
839
|
+
this.#unlink(absolute);
|
|
797
840
|
}
|
|
798
|
-
done();
|
|
799
|
-
};
|
|
800
|
-
let fd;
|
|
801
|
-
try {
|
|
802
|
-
fd = node_fs_1.default.openSync(String(entry.absolute), (0, get_write_flag_js_1.getWriteFlag)(entry.size), mode);
|
|
803
|
-
/* c8 ignore start - This is only a problem if the file was successfully
|
|
804
|
-
* statted, BUT failed to open. Testing this is annoying, and we
|
|
805
|
-
* already have ample testint for other uses of oner() methods.
|
|
806
|
-
*/
|
|
807
841
|
}
|
|
808
|
-
|
|
809
|
-
return
|
|
842
|
+
if (fileTypes.has(entry.type)) {
|
|
843
|
+
return this.#file(entry, absolute, reader);
|
|
844
|
+
}
|
|
845
|
+
if (dirTypes.has(entry.type))
|
|
846
|
+
return this.#directory(entry, absolute);
|
|
847
|
+
this.#ensureNoSymlink(this.linkParts(entry, absolute));
|
|
848
|
+
const linkpath = String(entry.linkpath);
|
|
849
|
+
if (entry.type === 'Link') {
|
|
850
|
+
fs.linkSync(this.resolve(cwd, linkpath), absolute);
|
|
851
|
+
}
|
|
852
|
+
else {
|
|
853
|
+
fs.symlinkSync(linkpath, absolute);
|
|
810
854
|
}
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
855
|
+
}
|
|
856
|
+
#unlink(path) {
|
|
857
|
+
const fs = this.#fs;
|
|
858
|
+
if (!this.win32)
|
|
859
|
+
return fs.unlinkSync(path);
|
|
860
|
+
const name = deleteName(path);
|
|
861
|
+
fs.renameSync(path, name);
|
|
862
|
+
fs.unlinkSync(name);
|
|
863
|
+
}
|
|
864
|
+
#ensureNoSymlink(parts) {
|
|
865
|
+
if (this.preservePaths)
|
|
866
|
+
return;
|
|
867
|
+
let t = this.cwd;
|
|
868
|
+
for (const p of parts) {
|
|
869
|
+
t = this.resolve(t, p);
|
|
870
|
+
let st;
|
|
871
|
+
try {
|
|
872
|
+
st = this.#fs.lstatSync(t);
|
|
873
|
+
}
|
|
874
|
+
catch {
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
if (st.isSymbolicLink())
|
|
878
|
+
throw this.symlinkError(t, parts);
|
|
816
879
|
}
|
|
817
|
-
|
|
880
|
+
}
|
|
881
|
+
#directory(entry, absolute) {
|
|
882
|
+
const fs = this.#fs;
|
|
883
|
+
this.#mkdir(absolute, entry.mode ?? this.dmode);
|
|
884
|
+
// These do not follow a symbolic link that replaced the
|
|
885
|
+
// directory. A failure is not an error of the entry.
|
|
886
|
+
const times = this.times(entry);
|
|
887
|
+
if (times) {
|
|
818
888
|
try {
|
|
819
|
-
|
|
889
|
+
fs.lutimesSync(absolute, times.atime, times.mtime);
|
|
820
890
|
}
|
|
821
|
-
catch
|
|
822
|
-
|
|
891
|
+
catch { }
|
|
892
|
+
}
|
|
893
|
+
const owner = this.owner(entry);
|
|
894
|
+
if (owner) {
|
|
895
|
+
try {
|
|
896
|
+
fs.lchownSync(absolute, owner.uid, owner.gid);
|
|
823
897
|
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
898
|
+
catch { }
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
#file(entry, absolute, reader) {
|
|
902
|
+
const fs = this.#fs;
|
|
903
|
+
const fd = fs.openSync(absolute, this.writeFlag(entry.size), entry.mode ?? this.fmode);
|
|
904
|
+
try {
|
|
905
|
+
const tx = this.opt.transform?.(entry);
|
|
906
|
+
for (;;) {
|
|
907
|
+
let part;
|
|
908
|
+
try {
|
|
909
|
+
part = reader.readBody(entry);
|
|
910
|
+
}
|
|
911
|
+
catch (er) {
|
|
912
|
+
// The archive cannot be read.
|
|
913
|
+
throw this.fail(er);
|
|
914
|
+
}
|
|
915
|
+
if (!part)
|
|
916
|
+
break;
|
|
917
|
+
fs.writeSync(fd, tx ? tx(part) : part);
|
|
918
|
+
}
|
|
919
|
+
// Use the open file, so that a symbolic link that replaced the
|
|
920
|
+
// path is not followed. If that fails, use the path.
|
|
921
|
+
const times = this.times(entry);
|
|
922
|
+
if (times) {
|
|
923
|
+
const { atime, mtime } = times;
|
|
832
924
|
try {
|
|
833
|
-
|
|
925
|
+
fs.futimesSync(fd, atime, mtime);
|
|
834
926
|
}
|
|
835
|
-
catch (
|
|
927
|
+
catch (er) {
|
|
836
928
|
try {
|
|
837
|
-
|
|
929
|
+
fs.utimesSync(absolute, atime, mtime);
|
|
838
930
|
}
|
|
839
931
|
catch {
|
|
840
|
-
er
|
|
932
|
+
throw er;
|
|
841
933
|
}
|
|
842
934
|
}
|
|
843
935
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
const gid =
|
|
936
|
+
const owner = this.owner(entry);
|
|
937
|
+
if (owner) {
|
|
938
|
+
const { uid, gid } = owner;
|
|
847
939
|
try {
|
|
848
|
-
|
|
940
|
+
fs.fchownSync(fd, uid, gid);
|
|
849
941
|
}
|
|
850
|
-
catch (
|
|
942
|
+
catch (er) {
|
|
851
943
|
try {
|
|
852
|
-
|
|
944
|
+
fs.chownSync(absolute, uid, gid);
|
|
853
945
|
}
|
|
854
946
|
catch {
|
|
855
|
-
|
|
947
|
+
throw er;
|
|
856
948
|
}
|
|
857
949
|
}
|
|
858
950
|
}
|
|
859
|
-
oner(er);
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
|
-
[DIRECTORY](entry, done) {
|
|
863
|
-
const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.dmode;
|
|
864
|
-
const er = this[MKDIR](String(entry.absolute), mode);
|
|
865
|
-
if (er) {
|
|
866
|
-
this[ONERROR](er, entry);
|
|
867
|
-
done();
|
|
868
|
-
return;
|
|
869
951
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
/* c8 ignore next */
|
|
874
|
-
}
|
|
875
|
-
catch { }
|
|
876
|
-
}
|
|
877
|
-
if (this[DOCHOWN](entry)) {
|
|
952
|
+
catch (er) {
|
|
953
|
+
// Close the file one time, and do not use the descriptor again:
|
|
954
|
+
// the system can give its number to a different file.
|
|
878
955
|
try {
|
|
879
|
-
|
|
956
|
+
fs.closeSync(fd);
|
|
880
957
|
}
|
|
881
958
|
catch { }
|
|
959
|
+
throw er;
|
|
882
960
|
}
|
|
883
|
-
|
|
884
|
-
entry.resume();
|
|
885
|
-
}
|
|
886
|
-
[MKDIR](dir, mode) {
|
|
887
|
-
try {
|
|
888
|
-
return (0, mkdir_js_1.mkdirSync)((0, normalize_windows_path_js_1.normalizeWindowsPath)(dir), {
|
|
889
|
-
uid: this.uid,
|
|
890
|
-
gid: this.gid,
|
|
891
|
-
processUid: this.processUid,
|
|
892
|
-
processGid: this.processGid,
|
|
893
|
-
umask: this.processUmask,
|
|
894
|
-
preserve: this.preservePaths,
|
|
895
|
-
unlink: this.unlink,
|
|
896
|
-
cwd: this.cwd,
|
|
897
|
-
mode: mode,
|
|
898
|
-
});
|
|
899
|
-
}
|
|
900
|
-
catch (er) {
|
|
901
|
-
return er;
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
[ENSURE_NO_SYMLINK](_entry, cwd, parts, done, onError) {
|
|
905
|
-
if (this.preservePaths || parts.length === 0)
|
|
906
|
-
return done();
|
|
907
|
-
let t = cwd;
|
|
908
|
-
for (const p of parts) {
|
|
909
|
-
t = node_path_1.default.resolve(t, p);
|
|
910
|
-
const [er, st] = callSync(() => node_fs_1.default.lstatSync(t));
|
|
911
|
-
if (er)
|
|
912
|
-
return done();
|
|
913
|
-
if (st.isSymbolicLink()) {
|
|
914
|
-
return onError(new symlink_error_js_1.SymlinkError(t, node_path_1.default.resolve(cwd, parts.join('/'))));
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
done();
|
|
918
|
-
}
|
|
919
|
-
[LINK](entry, linkpath, link, done) {
|
|
920
|
-
const linkSync = `${link}Sync`;
|
|
921
|
-
try {
|
|
922
|
-
node_fs_1.default[linkSync](linkpath, String(entry.absolute));
|
|
923
|
-
done();
|
|
924
|
-
entry.resume();
|
|
925
|
-
}
|
|
926
|
-
catch (er) {
|
|
927
|
-
return this[ONERROR](er, entry);
|
|
928
|
-
}
|
|
961
|
+
fs.closeSync(fd);
|
|
929
962
|
}
|
|
930
963
|
}
|
|
931
964
|
exports.UnpackSync = UnpackSync;
|