@procedures/archive 0.7.0 → 0.8.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/CHANGELOG.md +30 -0
- package/README.md +9 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +5 -0
- package/dist/module.js.map +1 -1
- package/dist/root.d.ts +7 -32
- package/dist/root.d.ts.map +1 -1
- package/dist/root.js +9 -107
- package/dist/root.js.map +1 -1
- package/package.json +3 -2
- package/src/module.ts +5 -0
- package/src/root.ts +10 -114
package/dist/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAQL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAQL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAyI5B;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,eAAkG,CAAC;eAEhH,aAAa;AAE5B,8CAA8C;AAC9C,MAAM,WAAW,oBAAoB;IACnC,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,8DAA8D;IAC9D,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,eAAe,CAevF;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,GAAE,iBAAsC,EAAE,OAAO,GAAE,oBAAyB,GAAG,IAAI,CAEpI"}
|
package/dist/module.js
CHANGED
|
@@ -83,6 +83,8 @@ function archiveProcedures(settings) {
|
|
|
83
83
|
shorts: { source: "s", format: "f" },
|
|
84
84
|
output: "json",
|
|
85
85
|
effects: READS_WRITES_FS,
|
|
86
|
+
// A root of the host examines the archive, the source, the base folder and each file
|
|
87
|
+
fsRoot: { cwd: "cwd", paths: ["output", "source"], names: ["files"] },
|
|
86
88
|
})
|
|
87
89
|
.handler(async (input) => archiveCreate(input, settings))
|
|
88
90
|
.build();
|
|
@@ -97,6 +99,8 @@ function archiveProcedures(settings) {
|
|
|
97
99
|
shorts: { format: "f" },
|
|
98
100
|
output: "json",
|
|
99
101
|
effects: READS_WRITES_FS,
|
|
102
|
+
// The checks of the entries keep the extract in the target
|
|
103
|
+
fsRoot: { paths: ["archive", "target"] },
|
|
100
104
|
})
|
|
101
105
|
.handler(async (input) => archiveExtract(input, settings))
|
|
102
106
|
.build();
|
|
@@ -111,6 +115,7 @@ function archiveProcedures(settings) {
|
|
|
111
115
|
shorts: { format: "f" },
|
|
112
116
|
output: "json",
|
|
113
117
|
effects: READS_FS,
|
|
118
|
+
fsRoot: { paths: ["archive"] },
|
|
114
119
|
})
|
|
115
120
|
.handler(async (input) => archiveList(input, settings))
|
|
116
121
|
.build();
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,UAAU,GAKX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO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AAC,wBAAwB,IAAI,sCAAsC,CAAC,CAAC;IACzI,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,CAAC;QAC5F,MAAM,IAAI,SAAS,CAAC,wDAAwD,CAAC,CAAC;IAChF,CAAC;IACD,iGAAiG;IACjG,MAAM,QAAQ,GAAoB,EAAE,GAAG,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACxH,OAAO,YAAY,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,QAAQ,GAAsB,kBAAkB,EAAE,OAAO,GAAyB,EAAE;IAC5H,eAAe,CAAC,QAAQ,EAAE,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC"}
|
package/dist/root.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The root of the archive procedures: one folder that confines each path (roadmap R33).
|
|
3
3
|
*
|
|
4
|
-
* The rules are the rules of
|
|
4
|
+
* The rules are the rules of `@procedures/fs/root`, the rules of `createFsModule({ root })`:
|
|
5
5
|
* - A relative path starts at the root, not at the working folder of the process.
|
|
6
6
|
* - A path outside the root gives `FORBIDDEN` with the reason `outside-root`. This includes a
|
|
7
7
|
* path that goes up with `..`, an absolute path outside the root, a path on another drive, and
|
|
@@ -10,39 +10,14 @@
|
|
|
10
10
|
* uses the real path of the nearest existing ancestor. So a symlinked parent folder cannot
|
|
11
11
|
* lead a write or a `mkdir` out of the root.
|
|
12
12
|
*
|
|
13
|
-
* On Windows, the comparison ignores the case of the letters, and `/` and `\` are the same.
|
|
13
|
+
* On Windows, the comparison ignores the case of the letters, and `/` and `\` are the same. This
|
|
14
|
+
* file adds only `placesOf()`, the paths of one call of an archive procedure.
|
|
14
15
|
*/
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
export
|
|
18
|
-
/**
|
|
19
|
-
* This function tells if `path` is `folder` or a path in `folder`. The two paths are absolute.
|
|
20
|
-
* On Windows, the case of the letters is not significant.
|
|
21
|
-
*/
|
|
22
|
-
export declare function isInside(folder: string, path: string): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* This function gives the real path of an absolute path. For a path that does not exist, it
|
|
25
|
-
* gives the real path of the nearest existing ancestor and the rest of the path. A symlink whose
|
|
26
|
-
* target does not exist leads to its target, because a write follows it.
|
|
27
|
-
*/
|
|
28
|
-
export declare function realPathOf(path: string, links?: number): Promise<string>;
|
|
29
|
-
/** A root: the absolute path that the host gave, and its real path. */
|
|
30
|
-
export interface ResolvedRoot {
|
|
31
|
-
folder: string;
|
|
32
|
-
real: string;
|
|
33
|
-
}
|
|
34
|
-
/** This function gives the absolute path and the real path of a root. The root must exist. */
|
|
16
|
+
import type { ProcedurePath } from "@procedures/client";
|
|
17
|
+
import { type ResolvedRoot } from "@procedures/fs/root";
|
|
18
|
+
export { OUTSIDE_ROOT, inRoot, isInside, isOutsideRoot, outsideRoot, realPathIsInside, realPathOf, type ResolvedRoot } from "@procedures/fs/root";
|
|
19
|
+
/** This function gives the absolute path and the real path of a root of the archive procedures. The root must exist. */
|
|
35
20
|
export declare function resolveRoot(root: string): Promise<ResolvedRoot>;
|
|
36
|
-
/** The `FORBIDDEN` error for a path outside the root. */
|
|
37
|
-
export declare function outsideRoot(procedure: ProcedurePath, message: string): InvocationError;
|
|
38
|
-
/** True for the `FORBIDDEN` error of a path outside the root. */
|
|
39
|
-
export declare function isOutsideRoot(error: unknown): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* This function gives the absolute path of `path` in the root. A relative path starts at the
|
|
42
|
-
* root. The real path decides: a path whose real path is outside the real path of the root gives
|
|
43
|
-
* `FORBIDDEN` with the reason `outside-root`.
|
|
44
|
-
*/
|
|
45
|
-
export declare function inRoot(root: ResolvedRoot, path: string, procedure: ProcedurePath): Promise<string>;
|
|
46
21
|
/** The paths of one call of a procedure. */
|
|
47
22
|
export interface Places {
|
|
48
23
|
/** The root of the call, or undefined for a module without a root. */
|
package/dist/root.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAwC,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE9F,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAElJ,wHAAwH;AACxH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAE/D;AAED,4CAA4C;AAC5C,MAAM,WAAW,MAAM;IACrB,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,SAAS,CAAC;IACxC;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACtC;AAED,wGAAwG;AACxG,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAIlG"}
|
package/dist/root.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The root of the archive procedures: one folder that confines each path (roadmap R33).
|
|
3
3
|
*
|
|
4
|
-
* The rules are the rules of
|
|
4
|
+
* The rules are the rules of `@procedures/fs/root`, the rules of `createFsModule({ root })`:
|
|
5
5
|
* - A relative path starts at the root, not at the working folder of the process.
|
|
6
6
|
* - A path outside the root gives `FORBIDDEN` with the reason `outside-root`. This includes a
|
|
7
7
|
* path that goes up with `..`, an absolute path outside the root, a path on another drive, and
|
|
@@ -10,113 +10,15 @@
|
|
|
10
10
|
* uses the real path of the nearest existing ancestor. So a symlinked parent folder cannot
|
|
11
11
|
* lead a write or a `mkdir` out of the root.
|
|
12
12
|
*
|
|
13
|
-
* On Windows, the comparison ignores the case of the letters, and `/` and `\` are the same.
|
|
13
|
+
* On Windows, the comparison ignores the case of the letters, and `/` and `\` are the same. This
|
|
14
|
+
* file adds only `placesOf()`, the paths of one call of an archive procedure.
|
|
14
15
|
*/
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
const MAX_LINKS = 40;
|
|
22
|
-
/**
|
|
23
|
-
* This function tells if `path` is `folder` or a path in `folder`. The two paths are absolute.
|
|
24
|
-
* On Windows, the case of the letters is not significant.
|
|
25
|
-
*/
|
|
26
|
-
export function isInside(folder, path) {
|
|
27
|
-
const rel = relative(folder, path);
|
|
28
|
-
return rel === "" || (!isAbsolute(rel) && rel !== ".." && !rel.startsWith(`..${sep}`));
|
|
29
|
-
}
|
|
30
|
-
/** True for the error of a path that does not exist. */
|
|
31
|
-
function isMissing(error) {
|
|
32
|
-
const code = error.code;
|
|
33
|
-
return code === "ENOENT" || code === "ENOTDIR";
|
|
34
|
-
}
|
|
35
|
-
/** The target of a symlink, or undefined when the path is not a symlink or does not exist. */
|
|
36
|
-
async function linkTarget(path) {
|
|
37
|
-
try {
|
|
38
|
-
return await readlink(path);
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
// EINVAL: the path is not a symlink
|
|
42
|
-
const code = error.code;
|
|
43
|
-
if (code === "EINVAL" || isMissing(error))
|
|
44
|
-
return undefined;
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* This function gives the real path of an absolute path. For a path that does not exist, it
|
|
50
|
-
* gives the real path of the nearest existing ancestor and the rest of the path. A symlink whose
|
|
51
|
-
* target does not exist leads to its target, because a write follows it.
|
|
52
|
-
*/
|
|
53
|
-
export async function realPathOf(path, links = 0) {
|
|
54
|
-
const rest = [];
|
|
55
|
-
let current = path;
|
|
56
|
-
for (;;) {
|
|
57
|
-
try {
|
|
58
|
-
return join(await realpath(current), ...rest);
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
if (!isMissing(error))
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
const target = await linkTarget(current);
|
|
65
|
-
if (target !== undefined) {
|
|
66
|
-
if (links >= MAX_LINKS) {
|
|
67
|
-
const loop = new Error(`Too many symlinks in the path ${path}`);
|
|
68
|
-
loop.code = "ELOOP";
|
|
69
|
-
throw loop;
|
|
70
|
-
}
|
|
71
|
-
return join(await realPathOf(resolve(dirname(current), target), links + 1), ...rest);
|
|
72
|
-
}
|
|
73
|
-
const parent = dirname(current);
|
|
74
|
-
// No ancestor exists, for example a drive that is not there
|
|
75
|
-
if (parent === current)
|
|
76
|
-
return join(current, ...rest);
|
|
77
|
-
rest.unshift(basename(current));
|
|
78
|
-
current = parent;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/** This function gives the absolute path and the real path of a root. The root must exist. */
|
|
82
|
-
export async function resolveRoot(root) {
|
|
83
|
-
const folder = resolve(root);
|
|
84
|
-
try {
|
|
85
|
-
return { folder, real: await realpath(folder) };
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
if (!isMissing(error))
|
|
89
|
-
throw error;
|
|
90
|
-
const missing = new Error(`The root of the archive procedures does not exist: ${folder}`);
|
|
91
|
-
missing.code = "ENOENT";
|
|
92
|
-
throw missing;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/** The `FORBIDDEN` error for a path outside the root. */
|
|
96
|
-
export function outsideRoot(procedure, message) {
|
|
97
|
-
return new InvocationError("FORBIDDEN", `${procedure.join(".")}: ${message}`, procedure, OUTSIDE_ROOT);
|
|
98
|
-
}
|
|
99
|
-
/** True for the `FORBIDDEN` error of a path outside the root. */
|
|
100
|
-
export function isOutsideRoot(error) {
|
|
101
|
-
return error instanceof InvocationError && error.code === "FORBIDDEN" && error.reason === OUTSIDE_ROOT;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* This function gives the absolute path of `path` in the root. A relative path starts at the
|
|
105
|
-
* root. The real path decides: a path whose real path is outside the real path of the root gives
|
|
106
|
-
* `FORBIDDEN` with the reason `outside-root`.
|
|
107
|
-
*/
|
|
108
|
-
export async function inRoot(root, path, procedure) {
|
|
109
|
-
const absolute = resolve(root.folder, path);
|
|
110
|
-
const real = await realPathOf(absolute);
|
|
111
|
-
// A path counts as inside by its given form or by its real form. On Windows, the two forms of a
|
|
112
|
-
// folder can differ by more than the links: a short 8.3 name (RUNNER~1) has a long real name.
|
|
113
|
-
if (!isInside(root.folder, absolute) && !isInside(root.real, absolute) && !isInside(root.real, real)) {
|
|
114
|
-
throw outsideRoot(procedure, `the path ${JSON.stringify(path)} is outside the root ${root.folder}`);
|
|
115
|
-
}
|
|
116
|
-
if (!isInside(root.real, real)) {
|
|
117
|
-
throw outsideRoot(procedure, `the path ${JSON.stringify(path)} leads out of the root ${root.folder} through a symlink`);
|
|
118
|
-
}
|
|
119
|
-
return absolute;
|
|
16
|
+
import { resolve } from "node:path";
|
|
17
|
+
import { inRoot, resolveRoot as resolveFsRoot } from "@procedures/fs/root";
|
|
18
|
+
export { OUTSIDE_ROOT, inRoot, isInside, isOutsideRoot, outsideRoot, realPathIsInside, realPathOf } from "@procedures/fs/root";
|
|
19
|
+
/** This function gives the absolute path and the real path of a root of the archive procedures. The root must exist. */
|
|
20
|
+
export function resolveRoot(root) {
|
|
21
|
+
return resolveFsRoot(root, "the archive procedures");
|
|
120
22
|
}
|
|
121
23
|
/** This function gives the paths of one call. With a root, the root must exist when the call starts. */
|
|
122
24
|
export async function placesOf(root, procedure) {
|
package/dist/root.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.js","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"root.js","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,WAAW,IAAI,aAAa,EAAqB,MAAM,qBAAqB,CAAC;AAE9F,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAC;AAElJ,wHAAwH;AACxH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,aAAa,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAAC;AACvD,CAAC;AAcD,wGAAwG;AACxG,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAwB,EAAE,SAAwB;IAC/E,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;IACzF,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC;AAChF,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.8.1",
|
|
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",
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
"procedures": "./dist/register.js"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@procedures/client": "0.
|
|
65
|
+
"@procedures/client": "0.8.1",
|
|
66
|
+
"@procedures/fs": "0.8.1",
|
|
66
67
|
"tar": "^7.5.0",
|
|
67
68
|
"zod": "^4.6.5"
|
|
68
69
|
},
|
package/src/module.ts
CHANGED
|
@@ -115,6 +115,8 @@ function archiveProcedures(settings: ArchiveSettings): AnyProcedure[] {
|
|
|
115
115
|
shorts: { source: "s", format: "f" },
|
|
116
116
|
output: "json",
|
|
117
117
|
effects: READS_WRITES_FS,
|
|
118
|
+
// A root of the host examines the archive, the source, the base folder and each file
|
|
119
|
+
fsRoot: { cwd: "cwd", paths: ["output", "source"], names: ["files"] },
|
|
118
120
|
})
|
|
119
121
|
.handler(async (input: ArchiveCreateInput): Promise<ArchiveCreateOutput> => archiveCreate(input, settings))
|
|
120
122
|
.build();
|
|
@@ -130,6 +132,8 @@ function archiveProcedures(settings: ArchiveSettings): AnyProcedure[] {
|
|
|
130
132
|
shorts: { format: "f" },
|
|
131
133
|
output: "json",
|
|
132
134
|
effects: READS_WRITES_FS,
|
|
135
|
+
// The checks of the entries keep the extract in the target
|
|
136
|
+
fsRoot: { paths: ["archive", "target"] },
|
|
133
137
|
})
|
|
134
138
|
.handler(async (input: ArchiveExtractInput): Promise<ArchiveExtractOutput> => archiveExtract(input, settings))
|
|
135
139
|
.build();
|
|
@@ -145,6 +149,7 @@ function archiveProcedures(settings: ArchiveSettings): AnyProcedure[] {
|
|
|
145
149
|
shorts: { format: "f" },
|
|
146
150
|
output: "json",
|
|
147
151
|
effects: READS_FS,
|
|
152
|
+
fsRoot: { paths: ["archive"] },
|
|
148
153
|
})
|
|
149
154
|
.handler(async (input: ArchiveListInput): Promise<ArchiveListOutput> => archiveList(input, settings))
|
|
150
155
|
.build();
|
package/src/root.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The root of the archive procedures: one folder that confines each path (roadmap R33).
|
|
3
3
|
*
|
|
4
|
-
* The rules are the rules of
|
|
4
|
+
* The rules are the rules of `@procedures/fs/root`, the rules of `createFsModule({ root })`:
|
|
5
5
|
* - A relative path starts at the root, not at the working folder of the process.
|
|
6
6
|
* - A path outside the root gives `FORBIDDEN` with the reason `outside-root`. This includes a
|
|
7
7
|
* path that goes up with `..`, an absolute path outside the root, a path on another drive, and
|
|
@@ -10,123 +10,19 @@
|
|
|
10
10
|
* uses the real path of the nearest existing ancestor. So a symlinked parent folder cannot
|
|
11
11
|
* lead a write or a `mkdir` out of the root.
|
|
12
12
|
*
|
|
13
|
-
* On Windows, the comparison ignores the case of the letters, and `/` and `\` are the same.
|
|
13
|
+
* On Windows, the comparison ignores the case of the letters, and `/` and `\` are the same. This
|
|
14
|
+
* file adds only `placesOf()`, the paths of one call of an archive procedure.
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
17
|
+
import { resolve } from "node:path";
|
|
18
|
+
import type { ProcedurePath } from "@procedures/client";
|
|
19
|
+
import { inRoot, resolveRoot as resolveFsRoot, type ResolvedRoot } from "@procedures/fs/root";
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
export const OUTSIDE_ROOT = "outside-root";
|
|
21
|
+
export { OUTSIDE_ROOT, inRoot, isInside, isOutsideRoot, outsideRoot, realPathIsInside, realPathOf, type ResolvedRoot } from "@procedures/fs/root";
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* This function tells if `path` is `folder` or a path in `folder`. The two paths are absolute.
|
|
28
|
-
* On Windows, the case of the letters is not significant.
|
|
29
|
-
*/
|
|
30
|
-
export function isInside(folder: string, path: string): boolean {
|
|
31
|
-
const rel = relative(folder, path);
|
|
32
|
-
return rel === "" || (!isAbsolute(rel) && rel !== ".." && !rel.startsWith(`..${sep}`));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** True for the error of a path that does not exist. */
|
|
36
|
-
function isMissing(error: unknown): boolean {
|
|
37
|
-
const code = (error as NodeJS.ErrnoException).code;
|
|
38
|
-
return code === "ENOENT" || code === "ENOTDIR";
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** The target of a symlink, or undefined when the path is not a symlink or does not exist. */
|
|
42
|
-
async function linkTarget(path: string): Promise<string | undefined> {
|
|
43
|
-
try {
|
|
44
|
-
return await readlink(path);
|
|
45
|
-
} catch (error) {
|
|
46
|
-
// EINVAL: the path is not a symlink
|
|
47
|
-
const code = (error as NodeJS.ErrnoException).code;
|
|
48
|
-
if (code === "EINVAL" || isMissing(error)) return undefined;
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* This function gives the real path of an absolute path. For a path that does not exist, it
|
|
55
|
-
* gives the real path of the nearest existing ancestor and the rest of the path. A symlink whose
|
|
56
|
-
* target does not exist leads to its target, because a write follows it.
|
|
57
|
-
*/
|
|
58
|
-
export async function realPathOf(path: string, links = 0): Promise<string> {
|
|
59
|
-
const rest: string[] = [];
|
|
60
|
-
let current = path;
|
|
61
|
-
for (;;) {
|
|
62
|
-
try {
|
|
63
|
-
return join(await realpath(current), ...rest);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
if (!isMissing(error)) throw error;
|
|
66
|
-
}
|
|
67
|
-
const target = await linkTarget(current);
|
|
68
|
-
if (target !== undefined) {
|
|
69
|
-
if (links >= MAX_LINKS) {
|
|
70
|
-
const loop = new Error(`Too many symlinks in the path ${path}`) as NodeJS.ErrnoException;
|
|
71
|
-
loop.code = "ELOOP";
|
|
72
|
-
throw loop;
|
|
73
|
-
}
|
|
74
|
-
return join(await realPathOf(resolve(dirname(current), target), links + 1), ...rest);
|
|
75
|
-
}
|
|
76
|
-
const parent = dirname(current);
|
|
77
|
-
// No ancestor exists, for example a drive that is not there
|
|
78
|
-
if (parent === current) return join(current, ...rest);
|
|
79
|
-
rest.unshift(basename(current));
|
|
80
|
-
current = parent;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** A root: the absolute path that the host gave, and its real path. */
|
|
85
|
-
export interface ResolvedRoot {
|
|
86
|
-
folder: string;
|
|
87
|
-
real: string;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** This function gives the absolute path and the real path of a root. The root must exist. */
|
|
91
|
-
export async function resolveRoot(root: string): Promise<ResolvedRoot> {
|
|
92
|
-
const folder = resolve(root);
|
|
93
|
-
try {
|
|
94
|
-
return { folder, real: await realpath(folder) };
|
|
95
|
-
} catch (error) {
|
|
96
|
-
if (!isMissing(error)) throw error;
|
|
97
|
-
const missing = new Error(`The root of the archive procedures does not exist: ${folder}`) as NodeJS.ErrnoException;
|
|
98
|
-
missing.code = "ENOENT";
|
|
99
|
-
throw missing;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** The `FORBIDDEN` error for a path outside the root. */
|
|
104
|
-
export function outsideRoot(procedure: ProcedurePath, message: string): InvocationError {
|
|
105
|
-
return new InvocationError("FORBIDDEN", `${procedure.join(".")}: ${message}`, procedure, OUTSIDE_ROOT);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** True for the `FORBIDDEN` error of a path outside the root. */
|
|
109
|
-
export function isOutsideRoot(error: unknown): boolean {
|
|
110
|
-
return error instanceof InvocationError && error.code === "FORBIDDEN" && error.reason === OUTSIDE_ROOT;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* This function gives the absolute path of `path` in the root. A relative path starts at the
|
|
115
|
-
* root. The real path decides: a path whose real path is outside the real path of the root gives
|
|
116
|
-
* `FORBIDDEN` with the reason `outside-root`.
|
|
117
|
-
*/
|
|
118
|
-
export async function inRoot(root: ResolvedRoot, path: string, procedure: ProcedurePath): Promise<string> {
|
|
119
|
-
const absolute = resolve(root.folder, path);
|
|
120
|
-
const real = await realPathOf(absolute);
|
|
121
|
-
// A path counts as inside by its given form or by its real form. On Windows, the two forms of a
|
|
122
|
-
// folder can differ by more than the links: a short 8.3 name (RUNNER~1) has a long real name.
|
|
123
|
-
if (!isInside(root.folder, absolute) && !isInside(root.real, absolute) && !isInside(root.real, real)) {
|
|
124
|
-
throw outsideRoot(procedure, `the path ${JSON.stringify(path)} is outside the root ${root.folder}`);
|
|
125
|
-
}
|
|
126
|
-
if (!isInside(root.real, real)) {
|
|
127
|
-
throw outsideRoot(procedure, `the path ${JSON.stringify(path)} leads out of the root ${root.folder} through a symlink`);
|
|
128
|
-
}
|
|
129
|
-
return absolute;
|
|
23
|
+
/** This function gives the absolute path and the real path of a root of the archive procedures. The root must exist. */
|
|
24
|
+
export function resolveRoot(root: string): Promise<ResolvedRoot> {
|
|
25
|
+
return resolveFsRoot(root, "the archive procedures");
|
|
130
26
|
}
|
|
131
27
|
|
|
132
28
|
/** The paths of one call of a procedure. */
|