stage-browser 0.0.0-stage → 0.1.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 +136 -2
- package/build/icon.icns +0 -0
- package/build/icon.png +0 -0
- package/dist/bin/stage.js +111 -0
- package/dist/main/cli-args.js +28 -0
- package/dist/main/context-menu.js +68 -0
- package/dist/main/context.js +2 -0
- package/dist/main/extensions.js +78 -0
- package/dist/main/ipc.js +90 -0
- package/dist/main/main.js +279 -0
- package/dist/main/menu.js +140 -0
- package/dist/main/reveal.js +155 -0
- package/dist/main/selftest.js +490 -0
- package/dist/main/store.js +85 -0
- package/dist/main/suggest.js +43 -0
- package/dist/main/tabs.js +324 -0
- package/dist/main/url.js +38 -0
- package/dist/main/window.js +68 -0
- package/dist/preload/extension-compat.js +163 -0
- package/dist/preload/ui-preload.js +33 -0
- package/dist/shared/contract.js +6 -0
- package/dist/ui/app.js +653 -0
- package/dist/ui/index.html +41 -0
- package/dist/ui/mock.js +479 -0
- package/dist/ui/newtab.html +69 -0
- package/dist/ui/styles.css +410 -0
- package/node_modules/@types/chrome/LICENSE +21 -0
- package/node_modules/@types/chrome/README.md +15 -0
- package/node_modules/@types/chrome/chrome-cast/index.d.ts +1156 -0
- package/node_modules/@types/chrome/har-format/index.d.ts +6 -0
- package/node_modules/@types/chrome/index.d.ts +13786 -0
- package/node_modules/@types/chrome/package.json +99 -0
- package/node_modules/@types/filesystem/LICENSE +21 -0
- package/node_modules/@types/filesystem/README.md +15 -0
- package/node_modules/@types/filesystem/index.d.ts +564 -0
- package/node_modules/@types/filesystem/package.json +26 -0
- package/node_modules/@types/filewriter/LICENSE +21 -0
- package/node_modules/@types/filewriter/README.md +15 -0
- package/node_modules/@types/filewriter/index.d.ts +166 -0
- package/node_modules/@types/filewriter/package.json +25 -0
- package/node_modules/@types/har-format/LICENSE +21 -0
- package/node_modules/@types/har-format/README.md +15 -0
- package/node_modules/@types/har-format/index.d.ts +938 -0
- package/node_modules/@types/har-format/package.json +31 -0
- package/node_modules/adm-zip/LICENSE +21 -0
- package/node_modules/adm-zip/README.md +90 -0
- package/node_modules/adm-zip/adm-zip.js +1020 -0
- package/node_modules/adm-zip/headers/entryHeader.js +396 -0
- package/node_modules/adm-zip/headers/index.js +2 -0
- package/node_modules/adm-zip/headers/mainHeader.js +177 -0
- package/node_modules/adm-zip/methods/deflater.js +33 -0
- package/node_modules/adm-zip/methods/index.js +3 -0
- package/node_modules/adm-zip/methods/inflater.js +64 -0
- package/node_modules/adm-zip/methods/zipcrypto.js +175 -0
- package/node_modules/adm-zip/package.json +56 -0
- package/node_modules/adm-zip/types.d.ts +223 -0
- package/node_modules/adm-zip/util/constants.js +142 -0
- package/node_modules/adm-zip/util/decoder.js +5 -0
- package/node_modules/adm-zip/util/errors.js +66 -0
- package/node_modules/adm-zip/util/fattr.js +76 -0
- package/node_modules/adm-zip/util/index.js +5 -0
- package/node_modules/adm-zip/util/utils.js +481 -0
- package/node_modules/adm-zip/zipEntry.js +415 -0
- package/node_modules/adm-zip/zipFile.js +466 -0
- package/node_modules/debug/LICENSE +20 -0
- package/node_modules/debug/README.md +481 -0
- package/node_modules/debug/package.json +64 -0
- package/node_modules/debug/src/browser.js +272 -0
- package/node_modules/debug/src/common.js +292 -0
- package/node_modules/debug/src/index.js +10 -0
- package/node_modules/debug/src/node.js +263 -0
- package/node_modules/electron-chrome-web-store/README.md +143 -0
- package/node_modules/electron-chrome-web-store/dist/chrome-web-store.preload.js +299 -0
- package/node_modules/electron-chrome-web-store/dist/cjs/browser/index.js +1674 -0
- package/node_modules/electron-chrome-web-store/dist/esm/browser/index.mjs +950 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/api.d.ts +2 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/crx3.d.ts +20 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/id.d.ts +9 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/index.d.ts +62 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/installer.d.ts +29 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/loader.d.ts +18 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/types.d.ts +21 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/updater.d.ts +6 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/utils.d.ts +4 -0
- package/node_modules/electron-chrome-web-store/dist/types/common/constants.d.ts +44 -0
- package/node_modules/electron-chrome-web-store/dist/types/renderer/chrome-web-store.preload.d.ts +1 -0
- package/node_modules/electron-chrome-web-store/package.json +43 -0
- package/node_modules/ms/index.js +162 -0
- package/node_modules/ms/license.md +21 -0
- package/node_modules/ms/package.json +38 -0
- package/node_modules/ms/readme.md +59 -0
- package/node_modules/pbf/LICENSE +27 -0
- package/node_modules/pbf/README.md +293 -0
- package/node_modules/pbf/bin/pbf +17 -0
- package/node_modules/pbf/compile.js +441 -0
- package/node_modules/pbf/dist/pbf-dev.js +838 -0
- package/node_modules/pbf/dist/pbf.js +1 -0
- package/node_modules/pbf/index.d.ts +206 -0
- package/node_modules/pbf/index.js +830 -0
- package/node_modules/pbf/package.json +63 -0
- package/node_modules/protocol-buffers-schema/.travis.yml +7 -0
- package/node_modules/protocol-buffers-schema/LICENSE +21 -0
- package/node_modules/protocol-buffers-schema/README.md +122 -0
- package/node_modules/protocol-buffers-schema/example.js +11 -0
- package/node_modules/protocol-buffers-schema/example.proto +13 -0
- package/node_modules/protocol-buffers-schema/index.js +6 -0
- package/node_modules/protocol-buffers-schema/package.json +31 -0
- package/node_modules/protocol-buffers-schema/parse.js +769 -0
- package/node_modules/protocol-buffers-schema/stringify.js +206 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.proto +11 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.json +99 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.json +125 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.json +42 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.json +32 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.json +167 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.json +33 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/no-tags.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.json +41 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.json +364 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.proto +72 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.json +47 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/pheromon-trajectories.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.json +55 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.proto +17 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.proto +5 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.json +108 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/valid-packed.proto +35 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.proto +13 -0
- package/node_modules/protocol-buffers-schema/test/index.js +157 -0
- package/node_modules/protocol-buffers-schema/tokenize.js +56 -0
- package/node_modules/resolve-protobuf-schema/.travis.yml +3 -0
- package/node_modules/resolve-protobuf-schema/LICENSE +21 -0
- package/node_modules/resolve-protobuf-schema/README.md +49 -0
- package/node_modules/resolve-protobuf-schema/index.js +50 -0
- package/node_modules/resolve-protobuf-schema/package.json +25 -0
- package/node_modules/resolve-protobuf-schema/test/a.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/b.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/c.proto +3 -0
- package/node_modules/resolve-protobuf-schema/test/index.js +49 -0
- package/package.json +64 -4
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const pth = require("path");
|
|
2
|
+
|
|
3
|
+
module.exports = function (/*String*/ path, /*Utils object*/ { fs }) {
|
|
4
|
+
var _path = path || "",
|
|
5
|
+
_obj = newAttr(),
|
|
6
|
+
_stat = null;
|
|
7
|
+
|
|
8
|
+
function newAttr() {
|
|
9
|
+
return {
|
|
10
|
+
directory: false,
|
|
11
|
+
readonly: false,
|
|
12
|
+
hidden: false,
|
|
13
|
+
executable: false,
|
|
14
|
+
mtime: 0,
|
|
15
|
+
atime: 0
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (_path && fs.existsSync(_path)) {
|
|
20
|
+
_stat = fs.statSync(_path);
|
|
21
|
+
_obj.directory = _stat.isDirectory();
|
|
22
|
+
_obj.mtime = _stat.mtime;
|
|
23
|
+
_obj.atime = _stat.atime;
|
|
24
|
+
_obj.executable = (0o111 & _stat.mode) !== 0; // file is executable who ever har right not just owner
|
|
25
|
+
_obj.readonly = (0o200 & _stat.mode) === 0; // readonly if owner has no write right
|
|
26
|
+
_obj.hidden = pth.basename(_path)[0] === ".";
|
|
27
|
+
} else {
|
|
28
|
+
console.warn("Invalid path: " + _path);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
get directory() {
|
|
33
|
+
return _obj.directory;
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
get readOnly() {
|
|
37
|
+
return _obj.readonly;
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
get hidden() {
|
|
41
|
+
return _obj.hidden;
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
get mtime() {
|
|
45
|
+
return _obj.mtime;
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
get atime() {
|
|
49
|
+
return _obj.atime;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
get executable() {
|
|
53
|
+
return _obj.executable;
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
decodeAttributes: function () {},
|
|
57
|
+
|
|
58
|
+
encodeAttributes: function () {},
|
|
59
|
+
|
|
60
|
+
toJSON: function () {
|
|
61
|
+
return {
|
|
62
|
+
path: _path,
|
|
63
|
+
isDirectory: _obj.directory,
|
|
64
|
+
isReadOnly: _obj.readonly,
|
|
65
|
+
isHidden: _obj.hidden,
|
|
66
|
+
isExecutable: _obj.executable,
|
|
67
|
+
mTime: _obj.mtime,
|
|
68
|
+
aTime: _obj.atime
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
toString: function () {
|
|
73
|
+
return JSON.stringify(this.toJSON(), null, "\t");
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
};
|
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
const fsystem = require("fs");
|
|
2
|
+
const pth = require("path");
|
|
3
|
+
const Constants = require("./constants");
|
|
4
|
+
const Errors = require("./errors");
|
|
5
|
+
const isWin = typeof process === "object" && "win32" === process.platform;
|
|
6
|
+
|
|
7
|
+
const is_Obj = (obj) => typeof obj === "object" && obj !== null;
|
|
8
|
+
|
|
9
|
+
// generate CRC32 lookup table
|
|
10
|
+
const crcTable = new Uint32Array(256).map((t, c) => {
|
|
11
|
+
for (let k = 0; k < 8; k++) {
|
|
12
|
+
if ((c & 1) !== 0) {
|
|
13
|
+
c = 0xedb88320 ^ (c >>> 1);
|
|
14
|
+
} else {
|
|
15
|
+
c >>>= 1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return c >>> 0;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// UTILS functions
|
|
22
|
+
|
|
23
|
+
function Utils(opts) {
|
|
24
|
+
this.sep = pth.sep;
|
|
25
|
+
this.fs = fsystem;
|
|
26
|
+
|
|
27
|
+
if (is_Obj(opts)) {
|
|
28
|
+
// custom filesystem
|
|
29
|
+
if (is_Obj(opts.fs) && typeof opts.fs.statSync === "function") {
|
|
30
|
+
this.fs = opts.fs;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = Utils;
|
|
36
|
+
|
|
37
|
+
// INSTANTIABLE functions
|
|
38
|
+
|
|
39
|
+
Utils.prototype.makeDir = function (/*String*/ folder) {
|
|
40
|
+
const self = this;
|
|
41
|
+
|
|
42
|
+
// Sync - make directories tree
|
|
43
|
+
function mkdirSync(/*String*/ fpath) {
|
|
44
|
+
let resolvedPath = fpath.split(self.sep)[0];
|
|
45
|
+
fpath.split(self.sep).forEach(function (name) {
|
|
46
|
+
if (!name || name.substr(-1, 1) === ":") return;
|
|
47
|
+
resolvedPath += self.sep + name;
|
|
48
|
+
var stat;
|
|
49
|
+
try {
|
|
50
|
+
stat = self.fs.statSync(resolvedPath);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
if (e.message && e.message.startsWith('ENOENT')) {
|
|
53
|
+
self.fs.mkdirSync(resolvedPath);
|
|
54
|
+
} else {
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (stat && stat.isFile()) throw Errors.FILE_IN_THE_WAY(`"${resolvedPath}"`);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
mkdirSync(folder);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
Utils.prototype.writeFileTo = function (/*String*/ path, /*Buffer*/ content, /*Boolean*/ overwrite, /*Number*/ attr) {
|
|
66
|
+
const self = this;
|
|
67
|
+
if (self.fs.existsSync(path)) {
|
|
68
|
+
if (!overwrite) return false; // cannot overwrite
|
|
69
|
+
|
|
70
|
+
var stat = self.fs.statSync(path);
|
|
71
|
+
if (stat.isDirectory()) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
var folder = pth.dirname(path);
|
|
76
|
+
if (!self.fs.existsSync(folder)) {
|
|
77
|
+
self.makeDir(folder);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var fd;
|
|
81
|
+
try {
|
|
82
|
+
fd = self.fs.openSync(path, "w", 0o666); // 0666
|
|
83
|
+
} catch (e) {
|
|
84
|
+
self.fs.chmodSync(path, 0o666);
|
|
85
|
+
fd = self.fs.openSync(path, "w", 0o666);
|
|
86
|
+
}
|
|
87
|
+
if (fd) {
|
|
88
|
+
try {
|
|
89
|
+
self.fs.writeSync(fd, content, 0, content.length, 0);
|
|
90
|
+
} finally {
|
|
91
|
+
self.fs.closeSync(fd);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
self.fs.chmodSync(path, attr || 0o666);
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
Utils.prototype.writeFileToAsync = function (/*String*/ path, /*Buffer*/ content, /*Boolean*/ overwrite, /*Number*/ attr, /*Function*/ callback) {
|
|
99
|
+
if (typeof attr === "function") {
|
|
100
|
+
callback = attr;
|
|
101
|
+
attr = undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const self = this;
|
|
105
|
+
|
|
106
|
+
self.fs.exists(path, function (exist) {
|
|
107
|
+
if (exist && !overwrite) return callback(false);
|
|
108
|
+
|
|
109
|
+
self.fs.stat(path, function (err, stat) {
|
|
110
|
+
if (exist && stat && stat.isDirectory()) {
|
|
111
|
+
return callback(false);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
var folder = pth.dirname(path);
|
|
115
|
+
self.fs.exists(folder, function (exists) {
|
|
116
|
+
if (!exists) {
|
|
117
|
+
// makeDir is synchronous and can throw (e.g. EACCES); report failure
|
|
118
|
+
// rather than letting it escape this callback as an uncaught exception
|
|
119
|
+
try {
|
|
120
|
+
self.makeDir(folder);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
return callback(false);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// write the content to an open descriptor, then apply the attributes
|
|
127
|
+
const writeToFd = function (fd) {
|
|
128
|
+
self.fs.write(fd, content, 0, content.length, 0, function (writeErr) {
|
|
129
|
+
self.fs.close(fd, function () {
|
|
130
|
+
// surface write failures instead of silently reporting success (issue #402)
|
|
131
|
+
if (writeErr) return callback(false);
|
|
132
|
+
self.fs.chmod(path, attr || 0o666, function () {
|
|
133
|
+
callback(true);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
self.fs.open(path, "w", 0o666, function (err, fd) {
|
|
140
|
+
if (err) {
|
|
141
|
+
// the target may exist but be read-only: make it writable and retry once
|
|
142
|
+
self.fs.chmod(path, 0o666, function () {
|
|
143
|
+
self.fs.open(path, "w", 0o666, function (retryErr, fd) {
|
|
144
|
+
// Previously the retry error was ignored and an undefined fd was
|
|
145
|
+
// passed to fs.write, throwing an uncaught ERR_INVALID_ARG_TYPE that
|
|
146
|
+
// crashed the process (issues #470, #459, #402). Report failure instead.
|
|
147
|
+
if (retryErr || !fd) return callback(false);
|
|
148
|
+
writeToFd(fd);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
} else if (fd) {
|
|
152
|
+
writeToFd(fd);
|
|
153
|
+
} else {
|
|
154
|
+
callback(false);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// Guard extraction against writing through a symlink that already exists inside
|
|
163
|
+
// the target directory. sanitize() only proves the textual path stays under the
|
|
164
|
+
// root; it cannot see that a component on disk is a symlink pointing elsewhere,
|
|
165
|
+
// so open()/mkdir() would follow it and write outside the root. Walk every path
|
|
166
|
+
// component strictly below root and reject any that is a symlink. Components at
|
|
167
|
+
// or above root are the caller's own choice and are left untouched, so a root
|
|
168
|
+
// that itself lives under a symlink (e.g. /tmp on macOS) still extracts.
|
|
169
|
+
Utils.prototype.assertPathSafe = function (/*String*/ root, /*String*/ target) {
|
|
170
|
+
const self = this;
|
|
171
|
+
if (typeof self.fs.lstatSync !== "function") return;
|
|
172
|
+
|
|
173
|
+
const resolvedRoot = pth.resolve(root);
|
|
174
|
+
const resolvedTarget = pth.resolve(target);
|
|
175
|
+
if (resolvedTarget === resolvedRoot) return;
|
|
176
|
+
|
|
177
|
+
const rel = pth.relative(resolvedRoot, resolvedTarget);
|
|
178
|
+
// Not under root: sanitize() is responsible for that case; nothing to walk.
|
|
179
|
+
if (!rel || rel === ".." || rel.startsWith(".." + pth.sep) || pth.isAbsolute(rel)) return;
|
|
180
|
+
|
|
181
|
+
let cur = resolvedRoot;
|
|
182
|
+
for (const part of rel.split(pth.sep)) {
|
|
183
|
+
if (!part || part === ".") continue;
|
|
184
|
+
cur = pth.join(cur, part);
|
|
185
|
+
let stat;
|
|
186
|
+
try {
|
|
187
|
+
stat = self.fs.lstatSync(cur);
|
|
188
|
+
} catch (e) {
|
|
189
|
+
break; // component does not exist yet: nothing below it can be a symlink
|
|
190
|
+
}
|
|
191
|
+
if (stat.isSymbolicLink()) throw Errors.FILE_IN_THE_WAY(`"${cur}"`);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
Utils.prototype.findFiles = function (/*String*/ path) {
|
|
196
|
+
const self = this;
|
|
197
|
+
const canLstat = typeof self.fs.lstatSync === "function";
|
|
198
|
+
const rootReal = self.fs.realpathSync(path);
|
|
199
|
+
|
|
200
|
+
// A symlink whose target lies outside the folder being archived must not be
|
|
201
|
+
// followed: statSync would dereference it and copy the target's contents into
|
|
202
|
+
// the archive, disclosing files outside the root (GHSA-wx42-xcp7-pgr4). Allow
|
|
203
|
+
// symlinks that resolve to a location inside the root, reject any that escape.
|
|
204
|
+
function escapesRoot(/*String*/ p) {
|
|
205
|
+
if (!canLstat) return false;
|
|
206
|
+
if (!self.fs.lstatSync(p).isSymbolicLink()) return false;
|
|
207
|
+
let real;
|
|
208
|
+
try {
|
|
209
|
+
real = self.fs.realpathSync(p);
|
|
210
|
+
} catch (e) {
|
|
211
|
+
return true; // dangling or unresolvable symlink: do not follow
|
|
212
|
+
}
|
|
213
|
+
return !(real === rootReal || real.startsWith(rootReal + pth.sep));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function findSync(/*String*/ dir, /*RegExp*/ pattern, /*Boolean*/ recursive, /*Set*/ visited) {
|
|
217
|
+
if (typeof pattern === "boolean") {
|
|
218
|
+
recursive = pattern;
|
|
219
|
+
pattern = undefined;
|
|
220
|
+
}
|
|
221
|
+
let files = [];
|
|
222
|
+
self.fs.readdirSync(dir).forEach(function (file) {
|
|
223
|
+
const path = pth.join(dir, file);
|
|
224
|
+
|
|
225
|
+
if (escapesRoot(path)) return;
|
|
226
|
+
|
|
227
|
+
const stat = self.fs.statSync(path);
|
|
228
|
+
|
|
229
|
+
if (!pattern || pattern.test(path)) {
|
|
230
|
+
files.push(pth.normalize(path) + (stat.isDirectory() ? self.sep : ""));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (stat.isDirectory() && recursive) {
|
|
234
|
+
// Descend by resolved real path and skip directories we have already
|
|
235
|
+
// visited. This stops a symlink that points back to an ancestor from
|
|
236
|
+
// recursing forever until the path fails with ELOOP / ENAMETOOLONG
|
|
237
|
+
// (issue #541).
|
|
238
|
+
const realDir = self.fs.realpathSync(path);
|
|
239
|
+
if (!visited.has(realDir)) {
|
|
240
|
+
visited.add(realDir);
|
|
241
|
+
files = files.concat(findSync(path, pattern, recursive, visited));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
return files;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return findSync(path, undefined, true, new Set([rootReal]));
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Callback for showing if everything was done.
|
|
253
|
+
*
|
|
254
|
+
* @callback filelistCallback
|
|
255
|
+
* @param {Error} err - Error object
|
|
256
|
+
* @param {string[]} list - was request fully completed
|
|
257
|
+
*/
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
* @param {string} dir
|
|
262
|
+
* @param {filelistCallback} cb
|
|
263
|
+
*/
|
|
264
|
+
Utils.prototype.findFilesAsync = function (dir, cb) {
|
|
265
|
+
const self = this;
|
|
266
|
+
const results = [];
|
|
267
|
+
let finished = false;
|
|
268
|
+
const finish = function (err) {
|
|
269
|
+
if (finished) return;
|
|
270
|
+
finished = true;
|
|
271
|
+
cb(err, err ? undefined : results);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const canLstat = typeof self.fs.lstat === "function";
|
|
275
|
+
let rootReal = null;
|
|
276
|
+
|
|
277
|
+
// Reject a symlink whose target escapes the root being archived, so its
|
|
278
|
+
// contents are not dereferenced and copied into the archive
|
|
279
|
+
// (GHSA-wx42-xcp7-pgr4). A symlink resolving to a location inside the root is
|
|
280
|
+
// allowed; a dangling or escaping one is skipped. Calls back (err, escapes).
|
|
281
|
+
const escapesRoot = function (file, cb) {
|
|
282
|
+
if (!canLstat) return cb(null, false);
|
|
283
|
+
self.fs.lstat(file, function (err, lst) {
|
|
284
|
+
if (err) return cb(err);
|
|
285
|
+
if (!lst || !lst.isSymbolicLink()) return cb(null, false);
|
|
286
|
+
self.fs.realpath(file, function (err, real) {
|
|
287
|
+
if (err) return cb(null, true); // dangling: do not follow
|
|
288
|
+
cb(null, !(real === rootReal || real.startsWith(rootReal + pth.sep)));
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// Descend by resolved real path and skip directories already visited, so a
|
|
294
|
+
// symlink pointing back to an ancestor cannot recurse forever (issue #541).
|
|
295
|
+
const walk = function (dir, visited, done) {
|
|
296
|
+
self.fs.readdir(dir, function (err, list) {
|
|
297
|
+
if (err) return done(err);
|
|
298
|
+
let pending = list.length;
|
|
299
|
+
if (!pending) return done();
|
|
300
|
+
list.forEach(function (name) {
|
|
301
|
+
const file = pth.join(dir, name);
|
|
302
|
+
escapesRoot(file, function (err, escapes) {
|
|
303
|
+
if (err) return done(err);
|
|
304
|
+
if (escapes) {
|
|
305
|
+
if (!--pending) done();
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
self.fs.stat(file, function (err, stat) {
|
|
309
|
+
if (err) return done(err);
|
|
310
|
+
if (!stat) {
|
|
311
|
+
if (!--pending) done();
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
results.push(pth.normalize(file) + (stat.isDirectory() ? self.sep : ""));
|
|
315
|
+
if (!stat.isDirectory()) {
|
|
316
|
+
if (!--pending) done();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
self.fs.realpath(file, function (err, realDir) {
|
|
320
|
+
if (err) return done(err);
|
|
321
|
+
if (visited.has(realDir)) {
|
|
322
|
+
if (!--pending) done();
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
visited.add(realDir);
|
|
326
|
+
walk(file, visited, function (err) {
|
|
327
|
+
if (err) return done(err);
|
|
328
|
+
if (!--pending) done();
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
self.fs.realpath(dir, function (err, realDir) {
|
|
338
|
+
if (err) return finish(err);
|
|
339
|
+
rootReal = realDir;
|
|
340
|
+
walk(dir, new Set([realDir]), finish);
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
Utils.prototype.getAttributes = function () {};
|
|
345
|
+
|
|
346
|
+
Utils.prototype.setAttributes = function () {};
|
|
347
|
+
|
|
348
|
+
// STATIC functions
|
|
349
|
+
|
|
350
|
+
// crc32 single update (it is part of crc32)
|
|
351
|
+
Utils.crc32update = function (crc, byte) {
|
|
352
|
+
return crcTable[(crc ^ byte) & 0xff] ^ (crc >>> 8);
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
Utils.crc32 = function (buf) {
|
|
356
|
+
if (typeof buf === "string") {
|
|
357
|
+
buf = Buffer.from(buf, "utf8");
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
let len = buf.length;
|
|
361
|
+
let crc = ~0;
|
|
362
|
+
for (let off = 0; off < len; ) crc = Utils.crc32update(crc, buf[off++]);
|
|
363
|
+
// xor and cast as uint32 number
|
|
364
|
+
return ~crc >>> 0;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
Utils.methodToString = function (/*Number*/ method) {
|
|
368
|
+
switch (method) {
|
|
369
|
+
case Constants.STORED:
|
|
370
|
+
return "STORED (" + method + ")";
|
|
371
|
+
case Constants.DEFLATED:
|
|
372
|
+
return "DEFLATED (" + method + ")";
|
|
373
|
+
default:
|
|
374
|
+
return "UNSUPPORTED (" + method + ")";
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* removes ".." style path elements
|
|
380
|
+
* @param {string} path - fixable path
|
|
381
|
+
* @returns string - fixed filepath
|
|
382
|
+
*/
|
|
383
|
+
Utils.canonical = function (/*string*/ path) {
|
|
384
|
+
if (!path) return "";
|
|
385
|
+
// trick normalize think path is absolute
|
|
386
|
+
const safeSuffix = pth.posix.normalize("/" + path.split("\\").join("/"));
|
|
387
|
+
return pth.join(".", safeSuffix);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* fix file names in achive
|
|
392
|
+
* @param {string} path - fixable path
|
|
393
|
+
* @returns string - fixed filepath
|
|
394
|
+
*/
|
|
395
|
+
|
|
396
|
+
Utils.zipnamefix = function (path) {
|
|
397
|
+
if (!path) return "";
|
|
398
|
+
// trick normalize think path is absolute
|
|
399
|
+
const safeSuffix = pth.posix.normalize("/" + path.split("\\").join("/"));
|
|
400
|
+
return pth.posix.join(".", safeSuffix);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
*
|
|
405
|
+
* @param {Array} arr
|
|
406
|
+
* @param {function} callback
|
|
407
|
+
* @returns
|
|
408
|
+
*/
|
|
409
|
+
Utils.findLast = function (arr, callback) {
|
|
410
|
+
if (!Array.isArray(arr)) throw new TypeError("arr is not array");
|
|
411
|
+
|
|
412
|
+
const len = arr.length >>> 0;
|
|
413
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
414
|
+
if (callback(arr[i], i, arr)) {
|
|
415
|
+
return arr[i];
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return void 0;
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// make absolute paths taking prefix as root folder
|
|
422
|
+
Utils.sanitize = function (/*string*/ prefix, /*string*/ name) {
|
|
423
|
+
prefix = pth.resolve(pth.normalize(prefix));
|
|
424
|
+
var parts = name.split("/");
|
|
425
|
+
for (var i = 0, l = parts.length; i < l; i++) {
|
|
426
|
+
var path = pth.normalize(pth.join(prefix, parts.slice(i, l).join(pth.sep)));
|
|
427
|
+
if (path === prefix || path.startsWith(prefix + pth.sep)) {
|
|
428
|
+
return path;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return pth.normalize(pth.join(prefix, pth.basename(name)));
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
// converts buffer, Uint8Array, string types to buffer
|
|
435
|
+
Utils.toBuffer = function toBuffer(/*buffer, Uint8Array, string*/ input, /* function */ encoder) {
|
|
436
|
+
if (Buffer.isBuffer(input)) {
|
|
437
|
+
return input;
|
|
438
|
+
} else if (input instanceof Uint8Array) {
|
|
439
|
+
return Buffer.from(input);
|
|
440
|
+
} else {
|
|
441
|
+
// expect string all other values are invalid and return empty buffer
|
|
442
|
+
return typeof input === "string" ? encoder(input) : Buffer.alloc(0);
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
Utils.readBigUInt64LE = function (/*Buffer*/ buffer, /*int*/ index) {
|
|
447
|
+
const lo = buffer.readUInt32LE(index);
|
|
448
|
+
const hi = buffer.readUInt32LE(index + 4);
|
|
449
|
+
const value = hi * 0x100000000 + lo;
|
|
450
|
+
// The result is a JS number, so values above 2^53 - 1 cannot be represented
|
|
451
|
+
// exactly. These are zip64 sizes/offsets/counts used as buffer indices; a
|
|
452
|
+
// silently rounded value would misparse the archive. Reject instead.
|
|
453
|
+
if (value > Number.MAX_SAFE_INTEGER) {
|
|
454
|
+
throw Errors.ZIP64_VALUE_TOO_LARGE();
|
|
455
|
+
}
|
|
456
|
+
return value;
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
Utils.writeBigUInt64LE = function (/*Buffer*/ buffer, /*Number*/ value, /*int*/ index) {
|
|
460
|
+
const lo = value >>> 0;
|
|
461
|
+
const hi = Math.floor(value / 0x100000000) >>> 0;
|
|
462
|
+
buffer.writeUInt32LE(lo, index);
|
|
463
|
+
buffer.writeUInt32LE(hi, index + 4);
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
Utils.fromDOS2Date = function (val) {
|
|
467
|
+
return new Date(((val >> 25) & 0x7f) + 1980, Math.max(((val >> 21) & 0x0f) - 1, 0), Math.max((val >> 16) & 0x1f, 1), (val >> 11) & 0x1f, (val >> 5) & 0x3f, (val & 0x1f) << 1);
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
Utils.fromDate2DOS = function (val) {
|
|
471
|
+
let date = 0;
|
|
472
|
+
let time = 0;
|
|
473
|
+
if (val.getFullYear() > 1979) {
|
|
474
|
+
date = (((val.getFullYear() - 1980) & 0x7f) << 9) | ((val.getMonth() + 1) << 5) | val.getDate();
|
|
475
|
+
time = (val.getHours() << 11) | (val.getMinutes() << 5) | (val.getSeconds() >> 1);
|
|
476
|
+
}
|
|
477
|
+
return (date << 16) | time;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
Utils.isWin = isWin; // Do we have windows system
|
|
481
|
+
Utils.crcTable = crcTable;
|