@procedures/archive 0.61.0 → 0.62.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/CHANGELOG.md +16 -0
- package/dist/walk.d.ts +3 -1
- package/dist/walk.d.ts.map +1 -1
- package/dist/walk.js +38 -40
- package/dist/walk.js.map +1 -1
- package/package.json +4 -3
- package/src/walk.ts +32 -33
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @procedures/archive
|
|
2
2
|
|
|
3
|
+
## 0.62.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fdb89bc: The path, glob and walk functions of three packages move to their home, `@mark1russell7/files` (roadmap CLI-125).
|
|
8
|
+
|
|
9
|
+
- `@procedures/fs`: `isInside` is a re-export of `@mark1russell7/files`. With `dot: true`, `fs.glob` uses `findEntriesAsync` of `@mark1russell7/files`, and its walk does not block the event loop.
|
|
10
|
+
- `@procedures/fs`: with `dot: true`, an absolute pattern under `cwd` matches. Before, it matched nothing. The other matches do not change.
|
|
11
|
+
- `@procedures/lib`: `expandHome` is a re-export of `@mark1russell7/files`. `findWorkspaceRoot` uses `findUp`.
|
|
12
|
+
- `@procedures/archive`: the walk of `archive.create` uses `walk` of `@mark1russell7/files`. `portableLinkTarget` uses `toPosix`. The limits and the error codes do not change.
|
|
13
|
+
- `@procedures/peer`: the range of `@mark1russell7/files` is `^0.0.4`, as in the other packages. The code does not change.
|
|
14
|
+
- Updated dependencies [14f61a7]
|
|
15
|
+
- Updated dependencies [fdb89bc]
|
|
16
|
+
- @procedures/client@0.62.0
|
|
17
|
+
- @procedures/fs@0.62.0
|
|
18
|
+
|
|
3
19
|
## 0.61.0
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/walk.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The walk of `archive.create`: each file, folder and symbolic link under the inputs, in a fixed
|
|
3
|
-
* order. The walk does not follow a link: the archive gets the link itself.
|
|
3
|
+
* order. The walk does not follow a link: the archive gets the link itself. The order and the
|
|
4
|
+
* entries come from `walk` of `@mark1russell7/files`. This module adds the limits of the archive,
|
|
5
|
+
* the link targets and the errors of the archive.
|
|
4
6
|
*/
|
|
5
7
|
/** One path for the archive. */
|
|
6
8
|
export interface WalkEntry {
|
package/dist/walk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,gCAAgC;AAChC,MAAM,WAAW,SAAS;IACxB,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED,sFAAsF;AACtF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACvC;AAID;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,CAElF;AAQD,+FAA+F;AAC/F,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAwB7G;AAED,oDAAoD;AACpD,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAEnE;AAED,gDAAgD;AAChD,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
package/dist/walk.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The walk of `archive.create`: each file, folder and symbolic link under the inputs, in a fixed
|
|
3
|
-
* order. The walk does not follow a link: the archive gets the link itself.
|
|
3
|
+
* order. The walk does not follow a link: the archive gets the link itself. The order and the
|
|
4
|
+
* entries come from `walk` of `@mark1russell7/files`. This module adds the limits of the archive,
|
|
5
|
+
* the link targets and the errors of the archive.
|
|
4
6
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import { join,
|
|
7
|
+
import { readdir, readlink } from "node:fs/promises";
|
|
8
|
+
import { join, relative, sep } from "node:path";
|
|
9
|
+
import { toPosix, walk as walkEntries } from "@mark1russell7/files";
|
|
7
10
|
import { ArchiveError } from "./errors.js";
|
|
8
11
|
const byName = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
9
12
|
/**
|
|
@@ -11,49 +14,44 @@ const byName = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
|
11
14
|
* for a link that Node made from `../a.txt`. On the other systems, a `\` is a part of a name.
|
|
12
15
|
*/
|
|
13
16
|
export function portableLinkTarget(target, separator = sep) {
|
|
14
|
-
return
|
|
17
|
+
return toPosix(target, separator);
|
|
18
|
+
}
|
|
19
|
+
/** This function tells if `error` is the error of `lstat`: the walk got a name that does not exist. */
|
|
20
|
+
function isLstatError(error) {
|
|
21
|
+
const failure = error;
|
|
22
|
+
return failure?.syscall === "lstat" && typeof failure.path === "string";
|
|
15
23
|
}
|
|
16
24
|
/** This function walks the names (relative to `base`) and gives each entry for the archive. */
|
|
17
25
|
export async function walk(base, names, options) {
|
|
18
26
|
const entries = [];
|
|
19
|
-
const seen = new Set();
|
|
20
27
|
let bytes = 0;
|
|
21
|
-
|
|
22
|
-
const path
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const children = (await readdir(path)).sort(byName);
|
|
42
|
-
for (const child of children)
|
|
43
|
-
await visit(`${name}/${child}`);
|
|
44
|
-
}
|
|
45
|
-
else if (stats.isFile()) {
|
|
46
|
-
bytes += stats.size;
|
|
47
|
-
if (bytes > options.maxBytes)
|
|
48
|
-
throw new ArchiveError("TOO_LARGE", `The files have more than ${options.maxBytes} bytes`, name);
|
|
49
|
-
entries.push({ ...common, kind: "file", size: stats.size });
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
throw new ArchiveError("UNSUPPORTED_ENTRY", `${path} is a special file (a socket, a device or a FIFO)`, name);
|
|
28
|
+
try {
|
|
29
|
+
for await (const { name, path, kind, stats } of walkEntries(base, names, { exclude: options.exclude })) {
|
|
30
|
+
if (entries.length >= options.maxEntries)
|
|
31
|
+
throw new ArchiveError("TOO_LARGE", `The archive gets more entries than the limit of ${options.maxEntries}`, name);
|
|
32
|
+
const common = { name, path, size: 0, mode: stats.mode & 0o7777, mtime: stats.mtime };
|
|
33
|
+
if (kind === "symlink") {
|
|
34
|
+
entries.push({ ...common, kind, linkTarget: portableLinkTarget(await readlink(path)) });
|
|
35
|
+
}
|
|
36
|
+
else if (kind === "directory") {
|
|
37
|
+
entries.push({ ...common, kind });
|
|
38
|
+
}
|
|
39
|
+
else if (kind === "file") {
|
|
40
|
+
bytes += stats.size;
|
|
41
|
+
if (bytes > options.maxBytes)
|
|
42
|
+
throw new ArchiveError("TOO_LARGE", `The files have more than ${options.maxBytes} bytes`, name);
|
|
43
|
+
entries.push({ ...common, kind, size: stats.size });
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new ArchiveError("UNSUPPORTED_ENTRY", `${path} is a special file (a socket, a device or a FIFO)`, name);
|
|
47
|
+
}
|
|
53
48
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (!isLstatError(error))
|
|
52
|
+
throw error;
|
|
53
|
+
throw new ArchiveError("UNSAFE_PATH", `${error.path} does not exist`, toPosix(relative(base, error.path)));
|
|
54
|
+
}
|
|
57
55
|
return entries;
|
|
58
56
|
}
|
|
59
57
|
/** The names of the content of a folder, sorted. */
|
package/dist/walk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAsB3C,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,C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,CAAC,GAAG,CAAC,CAAC,CAAC;AACxC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@procedures/archive",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.62.0",
|
|
5
5
|
"description": "Archives as procedures: make, list and extract tar.gz and zip, with a check of each path against zip slip and links out of the target.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"procedures",
|
|
@@ -67,8 +67,9 @@
|
|
|
67
67
|
"procedures": "./dist/register.js"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@
|
|
71
|
-
"@procedures/
|
|
70
|
+
"@mark1russell7/files": "^0.0.4",
|
|
71
|
+
"@procedures/client": "0.62.0",
|
|
72
|
+
"@procedures/fs": "0.62.0",
|
|
72
73
|
"tar": "^7.5.0",
|
|
73
74
|
"zod": "^4.6.5"
|
|
74
75
|
},
|
package/src/walk.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The walk of `archive.create`: each file, folder and symbolic link under the inputs, in a fixed
|
|
3
|
-
* order. The walk does not follow a link: the archive gets the link itself.
|
|
3
|
+
* order. The walk does not follow a link: the archive gets the link itself. The order and the
|
|
4
|
+
* entries come from `walk` of `@mark1russell7/files`. This module adds the limits of the archive,
|
|
5
|
+
* the link targets and the errors of the archive.
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
|
-
import {
|
|
7
|
-
import { join,
|
|
8
|
+
import { readdir, readlink } from "node:fs/promises";
|
|
9
|
+
import { join, relative, sep } from "node:path";
|
|
10
|
+
import { toPosix, walk as walkEntries } from "@mark1russell7/files";
|
|
8
11
|
import { ArchiveError } from "./errors.js";
|
|
9
12
|
|
|
10
13
|
/** One path for the archive. */
|
|
@@ -34,43 +37,39 @@ const byName = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);
|
|
|
34
37
|
* for a link that Node made from `../a.txt`. On the other systems, a `\` is a part of a name.
|
|
35
38
|
*/
|
|
36
39
|
export function portableLinkTarget(target: string, separator: string = sep): string {
|
|
37
|
-
return
|
|
40
|
+
return toPosix(target, separator);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** This function tells if `error` is the error of `lstat`: the walk got a name that does not exist. */
|
|
44
|
+
function isLstatError(error: unknown): error is NodeJS.ErrnoException & { path: string } {
|
|
45
|
+
const failure = error as NodeJS.ErrnoException | undefined;
|
|
46
|
+
return failure?.syscall === "lstat" && typeof failure.path === "string";
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
/** This function walks the names (relative to `base`) and gives each entry for the archive. */
|
|
41
50
|
export async function walk(base: string, names: readonly string[], options: WalkOptions): Promise<WalkEntry[]> {
|
|
42
51
|
const entries: WalkEntry[] = [];
|
|
43
|
-
const seen = new Set<string>();
|
|
44
52
|
let bytes = 0;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
try {
|
|
54
|
+
for await (const { name, path, kind, stats } of walkEntries(base, names, { exclude: options.exclude })) {
|
|
55
|
+
if (entries.length >= options.maxEntries) throw new ArchiveError("TOO_LARGE", `The archive gets more entries than the limit of ${options.maxEntries}`, name);
|
|
56
|
+
const common = { name, path, size: 0, mode: stats.mode & 0o7777, mtime: stats.mtime };
|
|
57
|
+
if (kind === "symlink") {
|
|
58
|
+
entries.push({ ...common, kind, linkTarget: portableLinkTarget(await readlink(path)) });
|
|
59
|
+
} else if (kind === "directory") {
|
|
60
|
+
entries.push({ ...common, kind });
|
|
61
|
+
} else if (kind === "file") {
|
|
62
|
+
bytes += stats.size;
|
|
63
|
+
if (bytes > options.maxBytes) throw new ArchiveError("TOO_LARGE", `The files have more than ${options.maxBytes} bytes`, name);
|
|
64
|
+
entries.push({ ...common, kind, size: stats.size });
|
|
65
|
+
} else {
|
|
66
|
+
throw new ArchiveError("UNSUPPORTED_ENTRY", `${path} is a special file (a socket, a device or a FIFO)`, name);
|
|
67
|
+
}
|
|
55
68
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
} else if (stats.isDirectory()) {
|
|
61
|
-
entries.push({ ...common, kind: "directory" });
|
|
62
|
-
const children = (await readdir(path)).sort(byName);
|
|
63
|
-
for (const child of children) await visit(`${name}/${child}`);
|
|
64
|
-
} else if (stats.isFile()) {
|
|
65
|
-
bytes += stats.size;
|
|
66
|
-
if (bytes > options.maxBytes) throw new ArchiveError("TOO_LARGE", `The files have more than ${options.maxBytes} bytes`, name);
|
|
67
|
-
entries.push({ ...common, kind: "file", size: stats.size });
|
|
68
|
-
} else {
|
|
69
|
-
throw new ArchiveError("UNSUPPORTED_ENTRY", `${path} is a special file (a socket, a device or a FIFO)`, name);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
for (const name of names) await visit(name);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (!isLstatError(error)) throw error;
|
|
71
|
+
throw new ArchiveError("UNSAFE_PATH", `${error.path} does not exist`, toPosix(relative(base, error.path)));
|
|
72
|
+
}
|
|
74
73
|
return entries;
|
|
75
74
|
}
|
|
76
75
|
|