@fnndsc/fond 0.6.1 → 0.7.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 +1 -3
- package/dist/errorStack.d.ts +10 -6
- package/dist/errorStack.js +12 -9
- package/dist/errorStack.js.map +1 -1
- package/dist/heldWriter.d.ts +130 -0
- package/dist/heldWriter.js +539 -0
- package/dist/heldWriter.js.map +1 -0
- package/dist/homePath.d.ts +60 -0
- package/dist/homePath.js +117 -0
- package/dist/homePath.js.map +1 -0
- package/dist/hostPlace.d.ts +275 -0
- package/dist/hostPlace.js +777 -0
- package/dist/hostPlace.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/dist/placedPath.d.ts +250 -0
- package/dist/placedPath.js +757 -0
- package/dist/placedPath.js.map +1 -0
- package/dist/publication.d.ts +43 -0
- package/dist/publication.js +55 -0
- package/dist/publication.js.map +1 -0
- package/dist/recordFile.d.ts +61 -0
- package/dist/recordFile.js +258 -0
- package/dist/recordFile.js.map +1 -0
- package/dist/vfs/contract.js +19 -5
- package/dist/vfs/contract.js.map +1 -1
- package/dist/vfs/dispatcher.d.ts +222 -13
- package/dist/vfs/dispatcher.js +483 -73
- package/dist/vfs/dispatcher.js.map +1 -1
- package/dist/vfs/memory.d.ts +107 -3
- package/dist/vfs/memory.js +198 -24
- package/dist/vfs/memory.js.map +1 -1
- package/dist/vfs/naming.d.ts +97 -0
- package/dist/vfs/naming.js +122 -0
- package/dist/vfs/naming.js.map +1 -0
- package/dist/vfs/outcome.d.ts +72 -2
- package/dist/vfs/outcome.js +84 -3
- package/dist/vfs/outcome.js.map +1 -1
- package/dist/vfs/provider.d.ts +191 -6
- package/dist/vfs/render.d.ts +7 -0
- package/dist/vfs/render.js +16 -13
- package/dist/vfs/render.js.map +1 -1
- package/package.json +1 -1
package/dist/vfs/dispatcher.js
CHANGED
|
@@ -12,11 +12,55 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}) : (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
o[k2] = m[k];
|
|
25
|
+
}));
|
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
+
}) : function(o, v) {
|
|
29
|
+
o["default"] = v;
|
|
30
|
+
});
|
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
+
var ownKeys = function(o) {
|
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
+
var ar = [];
|
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
return ownKeys(o);
|
|
39
|
+
};
|
|
40
|
+
return function (mod) {
|
|
41
|
+
if (mod && mod.__esModule) return mod;
|
|
42
|
+
var result = {};
|
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
15
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
49
|
exports.VFSDispatcher = void 0;
|
|
17
50
|
const result_js_1 = require("../result.js");
|
|
18
51
|
const errorStack_js_1 = require("../errorStack.js");
|
|
52
|
+
const path = __importStar(require("path"));
|
|
19
53
|
const outcome_js_1 = require("./outcome.js");
|
|
54
|
+
/**
|
|
55
|
+
* A path in the one spelling mounts are matched by: from the root, with no
|
|
56
|
+
* `.`, `..`, doubled or trailing slash.
|
|
57
|
+
*
|
|
58
|
+
* @param pathStr - The path as written.
|
|
59
|
+
* @returns The same path, canonical.
|
|
60
|
+
*/
|
|
61
|
+
function path_canonicalize(pathStr) {
|
|
62
|
+
return path.posix.resolve("/", pathStr);
|
|
63
|
+
}
|
|
20
64
|
/**
|
|
21
65
|
* The fallback when none is given: it holds nothing, and says so by name
|
|
22
66
|
* rather than answering with an empty folder.
|
|
@@ -30,6 +74,9 @@ const VFS_FALLBACK_NONE = {
|
|
|
30
74
|
async cp(src) {
|
|
31
75
|
return (0, outcome_js_1.vfs_fail)("ENOENT", `cp: no mount serves ${src}`);
|
|
32
76
|
},
|
|
77
|
+
holder_prove(where) {
|
|
78
|
+
return Promise.resolve((0, outcome_js_1.vfs_fail)("EIO", `cannot prove what holds ${where}: nothing serves this path`));
|
|
79
|
+
},
|
|
33
80
|
};
|
|
34
81
|
/**
|
|
35
82
|
* Routes filesystem requests to the mount that owns each path, or to the
|
|
@@ -91,6 +138,41 @@ class VFSDispatcher {
|
|
|
91
138
|
const match = this.providers.find((p) => absolutePath === p.prefix || absolutePath.startsWith(p.prefix + "/"));
|
|
92
139
|
return match || this.defaultProvider;
|
|
93
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Where a path stands for the session that owns this tree.
|
|
143
|
+
*
|
|
144
|
+
* `outside`: no mount serves it and the fallback holds nothing, so the
|
|
145
|
+
* path is not this tree's at all. `absent`: the mount that owns it has
|
|
146
|
+
* proved nothing is there (`absence_prove`). `unknown`: anything else,
|
|
147
|
+
* a mount that cannot prove absence, a proof that failed, or a path
|
|
148
|
+
* above a mount.
|
|
149
|
+
*
|
|
150
|
+
* A caller that would look somewhere else for a file (the engine's own
|
|
151
|
+
* disk) may do so on `outside` or `absent`, and never on `unknown`: a
|
|
152
|
+
* read that failed is not a file that is missing.
|
|
153
|
+
*
|
|
154
|
+
* @param pathStr - The absolute path.
|
|
155
|
+
* @returns Where it stands.
|
|
156
|
+
*/
|
|
157
|
+
async path_standing(pathStr) {
|
|
158
|
+
const target = path_canonicalize(pathStr);
|
|
159
|
+
const provider = this.provider_get(target);
|
|
160
|
+
if (provider === this.defaultProvider && !this.path_isVirtual(target)) {
|
|
161
|
+
if (provider === VFS_FALLBACK_NONE)
|
|
162
|
+
return 'outside';
|
|
163
|
+
}
|
|
164
|
+
else if (provider === this.defaultProvider) {
|
|
165
|
+
return 'unknown';
|
|
166
|
+
}
|
|
167
|
+
if (provider.absence_prove === undefined)
|
|
168
|
+
return 'unknown';
|
|
169
|
+
try {
|
|
170
|
+
return (await provider.absence_prove(target)) ? 'absent' : 'unknown';
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return 'unknown';
|
|
174
|
+
}
|
|
175
|
+
}
|
|
94
176
|
/**
|
|
95
177
|
* Whether a path belongs to a mount rather than to the fallback.
|
|
96
178
|
*
|
|
@@ -140,56 +222,9 @@ class VFSDispatcher {
|
|
|
140
222
|
async list(pathStr, options) {
|
|
141
223
|
const absolutePath = pathStr.startsWith("/") ? pathStr : "/" + pathStr;
|
|
142
224
|
const cleanPath = absolutePath.endsWith("/") && absolutePath.length > 1 ? absolutePath.slice(0, -1) : absolutePath;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (children.length > 0) {
|
|
147
|
-
const segmentIndex = cleanPath === "/" ? 1 : cleanPath.split("/").length;
|
|
148
|
-
const virtualSubdirs = new Set();
|
|
149
|
-
for (const p of children) {
|
|
150
|
-
const segments = p.prefix.split("/");
|
|
151
|
-
const nextSegment = segments[segmentIndex];
|
|
152
|
-
if (nextSegment) {
|
|
153
|
-
virtualSubdirs.add(nextSegment);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
if (virtualSubdirs.size > 0) {
|
|
157
|
-
const vfsItems = Array.from(virtualSubdirs).map((name) => ({
|
|
158
|
-
name,
|
|
159
|
-
type: "vfs",
|
|
160
|
-
size: 0,
|
|
161
|
-
owner: "root",
|
|
162
|
-
date: new Date().toISOString(),
|
|
163
|
-
}));
|
|
164
|
-
// The fallback may hold real items in this folder too: list them beside the mounts
|
|
165
|
-
let resolvedPathStr = pathStr;
|
|
166
|
-
if (this.pathResolver) {
|
|
167
|
-
try {
|
|
168
|
-
resolvedPathStr = await this.pathResolver(pathStr);
|
|
169
|
-
}
|
|
170
|
-
catch (e) {
|
|
171
|
-
// Deliberate absorption: for a read-only listing, the logical
|
|
172
|
-
// path is a valid fallback (the provider lists what it can);
|
|
173
|
-
// contrast cp(), where a guessed path could write wrongly.
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
// The store holding nothing here is an answer: the mounts are the
|
|
177
|
-
// listing, and what the store said is not left to fail the command.
|
|
178
|
-
const mark = errorStack_js_1.errorStack.checkpoint_mark();
|
|
179
|
-
const fallbackResult = await this.defaultProvider.list(resolvedPathStr, options);
|
|
180
|
-
if (!fallbackResult.ok)
|
|
181
|
-
errorStack_js_1.errorStack.checkpoint_drain(mark);
|
|
182
|
-
if (fallbackResult.ok && fallbackResult.value) {
|
|
183
|
-
const fallbackItems = fallbackResult.value;
|
|
184
|
-
for (const item of fallbackItems) {
|
|
185
|
-
if (!virtualSubdirs.has(item.name)) {
|
|
186
|
-
vfsItems.push(item);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return (0, result_js_1.Ok)(vfsItems);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
225
|
+
const virtualSubdirs = this.mountNames_below(cleanPath);
|
|
226
|
+
if (virtualSubdirs.size > 0)
|
|
227
|
+
return this.mountFolder_list(pathStr, virtualSubdirs, options);
|
|
193
228
|
const provider = this.provider_get(pathStr);
|
|
194
229
|
if (provider === this.defaultProvider && this.pathResolver) {
|
|
195
230
|
try {
|
|
@@ -202,9 +237,100 @@ class VFSDispatcher {
|
|
|
202
237
|
}
|
|
203
238
|
return provider.list(pathStr, options);
|
|
204
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* The names the mounts below a folder add to it: for each mount whose
|
|
242
|
+
* prefix lies under the folder, the prefix's next segment after it.
|
|
243
|
+
*
|
|
244
|
+
* @param cleanPath - The folder, absolute, with no trailing `/`.
|
|
245
|
+
* @returns The names, none when no mount lies under it.
|
|
246
|
+
*/
|
|
247
|
+
mountNames_below(cleanPath) {
|
|
248
|
+
const prefixParent = cleanPath === "/" ? "/" : cleanPath + "/";
|
|
249
|
+
const children = this.providers.filter((p) => p.prefix.startsWith(prefixParent));
|
|
250
|
+
const virtualSubdirs = new Set();
|
|
251
|
+
if (children.length === 0)
|
|
252
|
+
return virtualSubdirs;
|
|
253
|
+
const segmentIndex = cleanPath === "/" ? 1 : cleanPath.split("/").length;
|
|
254
|
+
for (const p of children) {
|
|
255
|
+
const segments = p.prefix.split("/");
|
|
256
|
+
const nextSegment = segments[segmentIndex];
|
|
257
|
+
if (nextSegment) {
|
|
258
|
+
virtualSubdirs.add(nextSegment);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return virtualSubdirs;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Lists a folder that holds mounts: each mount's name, then what the store
|
|
265
|
+
* holds there under any other name. The store is asked by the path the
|
|
266
|
+
* resolver gives, or by the path as asked when it gives none.
|
|
267
|
+
*
|
|
268
|
+
* @param pathStr - The folder, as it was asked.
|
|
269
|
+
* @param virtualSubdirs - The names the mounts below it add.
|
|
270
|
+
* @param options - Sort controls.
|
|
271
|
+
* @returns The mounts' names and the store's rows.
|
|
272
|
+
*/
|
|
273
|
+
async mountFolder_list(pathStr, virtualSubdirs, options) {
|
|
274
|
+
const vfsItems = Array.from(virtualSubdirs).map((name) => ({
|
|
275
|
+
name,
|
|
276
|
+
type: "vfs",
|
|
277
|
+
size: 0,
|
|
278
|
+
owner: "root",
|
|
279
|
+
date: new Date().toISOString(),
|
|
280
|
+
}));
|
|
281
|
+
// The fallback may hold real items in this folder too: list them beside the mounts
|
|
282
|
+
let resolvedPathStr = pathStr;
|
|
283
|
+
if (this.pathResolver) {
|
|
284
|
+
try {
|
|
285
|
+
resolvedPathStr = await this.pathResolver(pathStr);
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
// Deliberate absorption: for a read-only listing, the logical
|
|
289
|
+
// path is a valid fallback (the provider lists what it can);
|
|
290
|
+
// contrast cp(), where a guessed path could write wrongly.
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
for (const item of await this.storeRows_beside(resolvedPathStr, options)) {
|
|
294
|
+
if (!virtualSubdirs.has(item.name))
|
|
295
|
+
vfsItems.push(item);
|
|
296
|
+
}
|
|
297
|
+
return (0, result_js_1.Ok)(vfsItems);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* What the store holds at a folder of mounts, listed beside the mounts.
|
|
301
|
+
* The store holding nothing there, by its own proof (`holder_prove`), is
|
|
302
|
+
* an answer, as is a session with no store. Any other failure to read it
|
|
303
|
+
* stays on the error stack as the listing's diagnostic, so a listing that
|
|
304
|
+
* could not read the store is never taken for a whole one.
|
|
305
|
+
*
|
|
306
|
+
* @param at - The folder, as the store is asked it.
|
|
307
|
+
* @param options - Sort controls.
|
|
308
|
+
* @returns The store's rows there; none when it holds none or could not be read.
|
|
309
|
+
*/
|
|
310
|
+
async storeRows_beside(at, options) {
|
|
311
|
+
if (this.defaultProvider === VFS_FALLBACK_NONE)
|
|
312
|
+
return [];
|
|
313
|
+
const mark = errorStack_js_1.errorStack.checkpoint_mark();
|
|
314
|
+
const listed = await this.defaultProvider.list(at, options);
|
|
315
|
+
if (listed.ok)
|
|
316
|
+
return listed.value;
|
|
317
|
+
const proofMark = errorStack_js_1.errorStack.checkpoint_mark();
|
|
318
|
+
let absent = false;
|
|
319
|
+
try {
|
|
320
|
+
const proof = await this.defaultProvider.holder_prove?.(at);
|
|
321
|
+
absent = proof?.ok === true && proof.value.kind === 'absent';
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
absent = false;
|
|
325
|
+
}
|
|
326
|
+
errorStack_js_1.errorStack.checkpoint_drain(absent ? mark : proofMark);
|
|
327
|
+
return [];
|
|
328
|
+
}
|
|
205
329
|
/**
|
|
206
330
|
* The path a provider is asked with: as given for a mount, and through
|
|
207
|
-
* the path resolver for the fallback, when one is registered. An
|
|
331
|
+
* the path resolver for the fallback, when one is registered. An entry
|
|
332
|
+
* (what rm, rmdir and a rename's source act on) has only its folder
|
|
333
|
+
* resolved (the root is the root): a link it names is the link, never what it points at. An
|
|
208
334
|
* operation never proceeds on a guessed path: a path that does not
|
|
209
335
|
* resolve fails the operation.
|
|
210
336
|
*
|
|
@@ -212,12 +338,16 @@ class VFSDispatcher {
|
|
|
212
338
|
* @param pathStr - The path as asked.
|
|
213
339
|
* @param what - How a resolution failure names the path (`source path`, `path`).
|
|
214
340
|
* @param operation - The verb, for the failure's words.
|
|
341
|
+
* @param entry - The last part names the entry itself, unresolved.
|
|
215
342
|
* @returns The path to ask with, or why the operation cannot proceed.
|
|
216
343
|
*/
|
|
217
|
-
async pathFor_provider(provider, pathStr, what, operation) {
|
|
344
|
+
async pathFor_provider(provider, pathStr, what, operation, entry = false) {
|
|
218
345
|
if (provider !== this.defaultProvider || !this.pathResolver)
|
|
219
346
|
return (0, outcome_js_1.vfs_ok)(pathStr);
|
|
347
|
+
const at = path_canonicalize(pathStr);
|
|
220
348
|
try {
|
|
349
|
+
if (entry)
|
|
350
|
+
return (0, outcome_js_1.vfs_ok)(at === '/' ? at : path.posix.join(await this.pathResolver(path.posix.dirname(at)), path.posix.basename(at)));
|
|
221
351
|
return (0, outcome_js_1.vfs_ok)(await this.pathResolver(pathStr));
|
|
222
352
|
}
|
|
223
353
|
catch (e) {
|
|
@@ -226,22 +356,129 @@ class VFSDispatcher {
|
|
|
226
356
|
}
|
|
227
357
|
}
|
|
228
358
|
/**
|
|
229
|
-
*
|
|
359
|
+
* The mount that owns a path, or none.
|
|
360
|
+
*
|
|
361
|
+
* {@link provider_get} answers the fallback for whatever no mount claims,
|
|
362
|
+
* and that includes a path that is only a parent of mounts (`/net` above
|
|
363
|
+
* `/net/pacs`), which the fallback has no folder behind. Such a path has
|
|
364
|
+
* no owner: nothing can be copied out of it or into it.
|
|
365
|
+
*
|
|
366
|
+
* @param pathStr - The absolute path.
|
|
367
|
+
* @returns The owning mount or the fallback; null for a parent of mounts.
|
|
368
|
+
*/
|
|
369
|
+
owner_find(pathStr) {
|
|
370
|
+
const provider = this.provider_get(pathStr);
|
|
371
|
+
return provider === this.defaultProvider && this.path_isVirtual(pathStr) ? null : provider;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Copies within a mount, or out of a mount that offers it into the
|
|
375
|
+
* fallback; any other pair of mounts answers `EXDEV`.
|
|
376
|
+
*
|
|
377
|
+
* A mount's `cp` is given two paths and treats both as its own, so a copy
|
|
378
|
+
* handed to the source's mount with a destination it does not own writes
|
|
379
|
+
* somewhere nobody asked for. Who owns each path is settled here, before
|
|
380
|
+
* either mount is asked anything, and again once the paths are resolved,
|
|
381
|
+
* since a resolver can answer a path another mount owns:
|
|
230
382
|
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
383
|
+
* - both paths in one mount: it copies, or refuses its own destination;
|
|
384
|
+
* - the source in a mount that declares `copiesOut`, the destination in
|
|
385
|
+
* the fallback: the source's mount copies, the destination resolved as
|
|
386
|
+
* the fallback resolves its own paths;
|
|
387
|
+
* - anything else, a parent of mounts on either side included: `EXDEV`.
|
|
388
|
+
*
|
|
389
|
+
* @param asked - Source path.
|
|
390
|
+
* @param askedDest - Destination path.
|
|
233
391
|
* @param options - Copy options.
|
|
234
392
|
* @returns Done, or why not.
|
|
235
393
|
*/
|
|
236
|
-
async cp(
|
|
237
|
-
|
|
238
|
-
|
|
394
|
+
async cp(asked, askedDest, options) {
|
|
395
|
+
// One spelling for every question: `/./etc/x` and `/etc/x` are one path,
|
|
396
|
+
// and a mount is found by its prefix, letter for letter.
|
|
397
|
+
const src = path_canonicalize(asked);
|
|
398
|
+
const dest = path_canonicalize(askedDest);
|
|
399
|
+
const source = this.owner_find(src);
|
|
400
|
+
const destination = this.owner_find(dest);
|
|
401
|
+
if (source === null)
|
|
402
|
+
return (0, outcome_js_1.vfs_fail)('EXDEV', `cp: ${src} is a folder of mounts, and holds nothing of its own to copy`);
|
|
403
|
+
if (destination === null)
|
|
404
|
+
return (0, outcome_js_1.vfs_fail)('EXDEV', `cp: ${dest} is a folder of mounts, and nothing is copied into it`);
|
|
405
|
+
const offered = source === destination || (source.copiesOut === true && destination === this.defaultProvider);
|
|
406
|
+
if (!offered) {
|
|
407
|
+
return (0, outcome_js_1.vfs_fail)('EXDEV', `cp: ${src} and ${dest}: they are on different mounts, and no copy between them is offered`);
|
|
408
|
+
}
|
|
409
|
+
const from = await this.pathFor_provider(source, src, 'source path', 'cp');
|
|
239
410
|
if (!from.ok)
|
|
240
411
|
return from;
|
|
241
|
-
const to = await this.pathFor_provider(
|
|
412
|
+
const to = await this.pathFor_provider(destination, dest, 'destination path', 'cp');
|
|
242
413
|
if (!to.ok)
|
|
243
414
|
return to;
|
|
244
|
-
|
|
415
|
+
const fromPath = path_canonicalize(from.value);
|
|
416
|
+
const toPath = path_canonicalize(to.value);
|
|
417
|
+
if (this.owner_find(fromPath) !== source)
|
|
418
|
+
return (0, outcome_js_1.vfs_fail)('EXDEV', `cp: ${src} resolves to ${fromPath}, which another mount owns`);
|
|
419
|
+
if (this.owner_find(toPath) !== destination)
|
|
420
|
+
return (0, outcome_js_1.vfs_fail)('EXDEV', `cp: ${dest} resolves to ${toPath}, which another mount owns`);
|
|
421
|
+
return source.cp(fromPath, toPath, this.copyOptions_bind(options, destination, fromPath));
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* A copy's options with the check the mount asks of every path it would
|
|
425
|
+
* write: inside the source `EINVAL`, not the mount's own `EXDEV`, then the caller's.
|
|
426
|
+
*
|
|
427
|
+
* @param options - The copy's options, as asked.
|
|
428
|
+
* @param destination - The mount the destination belongs to.
|
|
429
|
+
* @param fromPath - The source, resolved and canonical.
|
|
430
|
+
* @returns The options, the check bound.
|
|
431
|
+
*/
|
|
432
|
+
copyOptions_bind(options, destination, fromPath) {
|
|
433
|
+
const inside = fromPath === '/' ? '/' : `${fromPath}/`;
|
|
434
|
+
const final_check = (final) => {
|
|
435
|
+
const at = path_canonicalize(final);
|
|
436
|
+
if (at === fromPath || at.startsWith(inside))
|
|
437
|
+
return (0, outcome_js_1.vfs_fail)('EINVAL', `cp: cannot copy ${fromPath} to ${at}: a destination inside what is copied`);
|
|
438
|
+
const refused = this.finalOwner_refuse(destination, at, 'cp');
|
|
439
|
+
if (refused !== null)
|
|
440
|
+
return refused;
|
|
441
|
+
return options.finalPath_check === undefined ? (0, outcome_js_1.vfs_ok)(true) : options.finalPath_check(final);
|
|
442
|
+
};
|
|
443
|
+
return {
|
|
444
|
+
...options,
|
|
445
|
+
finalPath_check(final) {
|
|
446
|
+
return final_check(final);
|
|
447
|
+
},
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* The refusal of a path a copy or a move would write that is not the
|
|
452
|
+
* mount's own: below a folder of mounts, or another mount's.
|
|
453
|
+
*
|
|
454
|
+
* @param provider - The mount that writes.
|
|
455
|
+
* @param at - The path it would write, canonical.
|
|
456
|
+
* @param operation - The verb, for the words.
|
|
457
|
+
* @returns `EXDEV`, or null when the path is the mount's own.
|
|
458
|
+
*/
|
|
459
|
+
finalOwner_refuse(provider, at, operation) {
|
|
460
|
+
const ownerless = this.ownerless_find(at);
|
|
461
|
+
if (ownerless !== null)
|
|
462
|
+
return (0, outcome_js_1.vfs_fail)('EXDEV', `${operation}: ${ownerless} is a folder of mounts, and nothing is written into it`);
|
|
463
|
+
if (this.provider_get(at) === provider)
|
|
464
|
+
return null;
|
|
465
|
+
return (0, outcome_js_1.vfs_fail)('EXDEV', `${operation}: ${at} is another mount's, and nothing is written there`);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Whether the mount that owns a destination honours `intoFolder`
|
|
469
|
+
* (`intoFolderOffered`); a path no mount owns takes nothing.
|
|
470
|
+
*
|
|
471
|
+
* @param pathStr - The destination.
|
|
472
|
+
* @returns True when its mount declares it.
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```ts
|
|
476
|
+
* if (!dispatcher.intoFolder_offered('/proc/tags/qc')) refuse();
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
intoFolder_offered(pathStr) {
|
|
480
|
+
const owner = this.owner_find(path_canonicalize(pathStr));
|
|
481
|
+
return owner !== null && owner.intoFolderOffered === true;
|
|
245
482
|
}
|
|
246
483
|
/**
|
|
247
484
|
* Reads a file whole, as text, through the provider that owns it.
|
|
@@ -299,14 +536,17 @@ class VFSDispatcher {
|
|
|
299
536
|
*
|
|
300
537
|
* @param pathStr - The absolute path of the file.
|
|
301
538
|
* @param content - The new content, whole.
|
|
539
|
+
* @param options - What becomes of a file already there.
|
|
302
540
|
* @returns Done, or why not.
|
|
303
541
|
*/
|
|
304
|
-
async write(pathStr, content) {
|
|
542
|
+
async write(pathStr, content, options) {
|
|
305
543
|
const provider = this.provider_get(pathStr);
|
|
306
544
|
if (!provider.write)
|
|
307
545
|
return (0, outcome_js_1.vfs_fail)('EROFS');
|
|
308
546
|
const at = await this.pathFor_provider(provider, pathStr, 'path', 'write');
|
|
309
|
-
|
|
547
|
+
if (!at.ok)
|
|
548
|
+
return at;
|
|
549
|
+
return options === undefined ? provider.write(at.value, content) : provider.write(at.value, content, options);
|
|
310
550
|
}
|
|
311
551
|
/**
|
|
312
552
|
* Makes a folder, through the provider that owns its path.
|
|
@@ -345,7 +585,9 @@ class VFSDispatcher {
|
|
|
345
585
|
return at.ok ? provider.mkdirTree(at.value) : at;
|
|
346
586
|
}
|
|
347
587
|
/**
|
|
348
|
-
* Removes an empty folder, through the provider that owns it
|
|
588
|
+
* Removes an empty folder, through the provider that owns it, as asked
|
|
589
|
+
* and as resolved: a path that resolves into another mount, or one no
|
|
590
|
+
* mount owns, answers `EXDEV`.
|
|
349
591
|
*
|
|
350
592
|
* @param pathStr - The absolute path of the folder.
|
|
351
593
|
* @returns Done, or why not.
|
|
@@ -354,30 +596,197 @@ class VFSDispatcher {
|
|
|
354
596
|
const provider = this.provider_get(pathStr);
|
|
355
597
|
if (!provider.rmdir)
|
|
356
598
|
return (0, outcome_js_1.vfs_fail)('EROFS');
|
|
357
|
-
const at = await this.
|
|
599
|
+
const at = await this.removalPath_resolve(provider, pathStr, 'rmdir');
|
|
358
600
|
return at.ok ? provider.rmdir(at.value) : at;
|
|
359
601
|
}
|
|
360
602
|
/**
|
|
361
|
-
* Renames within one mount; a rename across mounts answers `EXDEV
|
|
603
|
+
* Renames within one mount; a rename across mounts answers `EXDEV`, and
|
|
604
|
+
* so does one with an operand no mount owns (a parent of mounts, or a
|
|
605
|
+
* path below one), as asked or as resolved: such a path is handed to the
|
|
606
|
+
* fallback only for want of an owner, and nothing behind it is a folder.
|
|
607
|
+
* The source is the entry itself (a link is the link); a link at the end
|
|
608
|
+
* of the destination is followed.
|
|
362
609
|
*
|
|
363
610
|
* @param src - The absolute path now.
|
|
364
|
-
* @param dest - The absolute path it takes.
|
|
611
|
+
* @param dest - The absolute path it takes, or with `mvNaming` a folder it goes into.
|
|
612
|
+
* @param options - How the mount names the entry; passed through as given.
|
|
365
613
|
* @returns Done, or why not.
|
|
366
614
|
*/
|
|
367
|
-
async rename(src, dest) {
|
|
615
|
+
async rename(src, dest, options) {
|
|
368
616
|
const provider = this.provider_get(src);
|
|
369
617
|
if (provider !== this.provider_get(dest))
|
|
370
618
|
return (0, outcome_js_1.vfs_fail)('EXDEV');
|
|
371
619
|
if (!provider.rename)
|
|
372
620
|
return (0, outcome_js_1.vfs_fail)('EROFS');
|
|
373
|
-
const
|
|
621
|
+
const asked = this.mutationOwnerless_refuse(src, 'mv') ?? this.mutationOwnerless_refuse(dest, 'mv');
|
|
622
|
+
if (asked !== null)
|
|
623
|
+
return asked;
|
|
624
|
+
const from = await this.pathFor_provider(provider, src, 'source path', 'mv', true);
|
|
374
625
|
if (!from.ok)
|
|
375
626
|
return from;
|
|
376
627
|
const to = await this.pathFor_provider(provider, dest, 'destination path', 'mv');
|
|
377
|
-
|
|
628
|
+
if (!to.ok)
|
|
629
|
+
return to;
|
|
630
|
+
// A resolver can answer a path another mount owns, or one no mount owns;
|
|
631
|
+
// and a path as spelled (`/work/../mnt/team/x`) can name another mount's
|
|
632
|
+
// than the one its spelling picked. Each is owned by its canonical name.
|
|
633
|
+
const operands = [[src, from.value], [dest, to.value]];
|
|
634
|
+
for (const [operand, resolved] of operands) {
|
|
635
|
+
const refused = this.mutationOwnerless_refuse(resolved, 'mv') ?? this.ownerElsewhere_refuse(provider, operand, resolved, 'mv');
|
|
636
|
+
if (refused !== null)
|
|
637
|
+
return refused;
|
|
638
|
+
}
|
|
639
|
+
if (options === undefined)
|
|
640
|
+
return provider.rename(from.value, to.value);
|
|
641
|
+
// A naming that derives the entry's path in the mount: that path is checked once settled.
|
|
642
|
+
const final_check = (final) => this.finalOwner_refuse(provider, path_canonicalize(final), 'mv') ?? (options.finalPath_check === undefined ? (0, outcome_js_1.vfs_ok)(true) : options.finalPath_check(final));
|
|
643
|
+
return provider.rename(from.value, to.value, {
|
|
644
|
+
...options,
|
|
645
|
+
finalPath_check(final) {
|
|
646
|
+
return final_check(final);
|
|
647
|
+
},
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* The nearest path, at or above a path, that no provider owns (a parent of
|
|
652
|
+
* mounts), on the walk up a proof of the path would make. A mount proves
|
|
653
|
+
* within itself, so only a path the fallback owns walks up to the root.
|
|
654
|
+
*
|
|
655
|
+
* @param pathStr - The path.
|
|
656
|
+
* @returns That path, or null when every step has an owner.
|
|
657
|
+
*/
|
|
658
|
+
ownerless_find(pathStr) {
|
|
659
|
+
const target = path_canonicalize(pathStr);
|
|
660
|
+
if (this.owner_find(target) === null)
|
|
661
|
+
return target;
|
|
662
|
+
if (this.provider_get(target) !== this.defaultProvider)
|
|
663
|
+
return null;
|
|
664
|
+
for (let at = path.posix.dirname(target); at !== '/'; at = path.posix.dirname(at)) {
|
|
665
|
+
if (this.owner_find(at) === null)
|
|
666
|
+
return at;
|
|
667
|
+
}
|
|
668
|
+
return null;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Whether what holds a path is proved before an act on it: where the
|
|
672
|
+
* owning mount offers a proof, and where no mount owns the path or a step
|
|
673
|
+
* above it (there the proof answers an error). False for a mount with its
|
|
674
|
+
* own verbs and no proof (the tag projection): it is asked directly.
|
|
675
|
+
*
|
|
676
|
+
* @param pathStr - The path.
|
|
677
|
+
* @returns True when {@link holder_prove} decides.
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
* ```ts
|
|
681
|
+
* if (!dispatcher.holderProof_offered(target)) return dispatcher.rm(target);
|
|
682
|
+
* ```
|
|
683
|
+
*/
|
|
684
|
+
holderProof_offered(pathStr) {
|
|
685
|
+
return this.ownerless_find(pathStr) !== null || this.provider_get(pathStr).holder_prove !== undefined;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Proves what holds a path, through the mount that owns it, resolved as
|
|
689
|
+
* the act it decides is resolved (the same provider, the same
|
|
690
|
+
* `pathFor_provider`), so a proof and the act it allows are about one
|
|
691
|
+
* place: the entry itself for rm, rmdir and a rename's source (`entry`),
|
|
692
|
+
* a link at the end followed for anything else. A path no provider owns,
|
|
693
|
+
* or one whose proof would walk up through a parent of mounts, is an
|
|
694
|
+
* error: mount names are not an absence. So is one that resolves to a
|
|
695
|
+
* path another mount owns (`EXDEV`): the provider chosen for the path as
|
|
696
|
+
* asked holds nothing of that path's.
|
|
697
|
+
*
|
|
698
|
+
* @param pathStr - The absolute path.
|
|
699
|
+
* @param options - Whether the last part names the entry itself.
|
|
700
|
+
* @returns What holds it, or why that could not be proved.
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```ts
|
|
704
|
+
* const proof: VfsOutcome<HolderProof> = await dispatcher.holder_prove('/home/ada/x', { entry: true });
|
|
705
|
+
* ```
|
|
706
|
+
*/
|
|
707
|
+
async holder_prove(pathStr, options = {}) {
|
|
708
|
+
const unowned = this.ownerless_refuse(pathStr);
|
|
709
|
+
if (unowned !== null)
|
|
710
|
+
return unowned;
|
|
711
|
+
const provider = this.provider_get(pathStr);
|
|
712
|
+
if (!provider.holder_prove)
|
|
713
|
+
return (0, outcome_js_1.vfs_fail)('EROFS', `cannot prove what holds ${path_canonicalize(pathStr)}: its mount offers no proof`);
|
|
714
|
+
const at = await this.pathFor_provider(provider, pathStr, 'path', 'prove', options.entry === true);
|
|
715
|
+
if (!at.ok)
|
|
716
|
+
return at;
|
|
717
|
+
const resolved = this.ownerless_refuse(at.value) ?? this.ownerElsewhere_refuse(provider, pathStr, at.value, 'prove');
|
|
718
|
+
return resolved ?? provider.holder_prove(at.value);
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* The refusal of a path that resolves to one another mount owns: the
|
|
722
|
+
* provider chosen for the path as asked would be handed a path it does
|
|
723
|
+
* not own, and would answer for its own map (an absence, a removal of
|
|
724
|
+
* nothing) instead of the owner's.
|
|
725
|
+
*
|
|
726
|
+
* @param provider - The provider chosen for the path as asked.
|
|
727
|
+
* @param asked - The path as asked.
|
|
728
|
+
* @param resolved - The path it resolved to.
|
|
729
|
+
* @param operation - The verb, for the words.
|
|
730
|
+
* @returns `EXDEV`, or null when the resolved path is the provider's own.
|
|
731
|
+
*/
|
|
732
|
+
ownerElsewhere_refuse(provider, asked, resolved, operation) {
|
|
733
|
+
const canonical = path_canonicalize(resolved);
|
|
734
|
+
if (this.provider_get(canonical) === provider)
|
|
735
|
+
return null;
|
|
736
|
+
const spelled = path_canonicalize(asked) === canonical ? `${asked} is` : `${path_canonicalize(asked)} resolves to`;
|
|
737
|
+
return (0, outcome_js_1.vfs_fail)('EXDEV', `${operation}: ${spelled} ${canonical}, which another mount owns`);
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* The path a removal hands its provider, the entry itself (only its folder
|
|
741
|
+
* resolved: a link is removed, never what it points at), owned as rename's operands are:
|
|
742
|
+
* no operand a parent of mounts (or below one), as asked or as resolved,
|
|
743
|
+
* and the resolved path the same provider's own.
|
|
744
|
+
*
|
|
745
|
+
* @param provider - The provider chosen for the path as asked.
|
|
746
|
+
* @param pathStr - The path as asked.
|
|
747
|
+
* @param operation - The verb (`rm`, `rmdir`).
|
|
748
|
+
* @returns The path to ask with, or why the removal is not asked (`EXDEV`, `EIO`).
|
|
749
|
+
*/
|
|
750
|
+
async removalPath_resolve(provider, pathStr, operation) {
|
|
751
|
+
const asked = this.mutationOwnerless_refuse(pathStr, operation);
|
|
752
|
+
if (asked !== null)
|
|
753
|
+
return asked;
|
|
754
|
+
const at = await this.pathFor_provider(provider, pathStr, 'path', operation, true);
|
|
755
|
+
if (!at.ok)
|
|
756
|
+
return at;
|
|
757
|
+
return this.mutationOwnerless_refuse(at.value, operation) ?? this.ownerElsewhere_refuse(provider, pathStr, at.value, operation) ?? at;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* The refusal of a rename or a removal with an operand no mount owns: a
|
|
761
|
+
* parent of mounts, or a path below one that the fallback would be handed
|
|
762
|
+
* for want of an owner. Nothing is moved out of one or into one, or removed.
|
|
763
|
+
*
|
|
764
|
+
* @param pathStr - An operand, as asked or as resolved.
|
|
765
|
+
* @param operation - The verb (`mv`, `rm`, `rmdir`).
|
|
766
|
+
* @returns `EXDEV`, or null when every step up has an owner.
|
|
767
|
+
*/
|
|
768
|
+
mutationOwnerless_refuse(pathStr, operation) {
|
|
769
|
+
const ownerless = this.ownerless_find(pathStr);
|
|
770
|
+
if (ownerless === null)
|
|
771
|
+
return null;
|
|
772
|
+
const nothing = operation === 'mv' ? 'moved out of it or into it' : 'removed from it';
|
|
773
|
+
return (0, outcome_js_1.vfs_fail)('EXDEV', `${operation}: ${ownerless} is a folder of mounts, and nothing is ${nothing}`);
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* The refusal of a proof that would read a parent of mounts as a folder.
|
|
777
|
+
*
|
|
778
|
+
* @param pathStr - The path asked, or the one it resolved to.
|
|
779
|
+
* @returns The failure, or null when every step up has an owner.
|
|
780
|
+
*/
|
|
781
|
+
ownerless_refuse(pathStr) {
|
|
782
|
+
const ownerless = this.ownerless_find(pathStr);
|
|
783
|
+
if (ownerless === null)
|
|
784
|
+
return null;
|
|
785
|
+
return (0, outcome_js_1.vfs_fail)('EIO', `cannot prove what holds ${path_canonicalize(pathStr)}: ${ownerless} is a folder of mounts, and nothing of its own is proved there`);
|
|
378
786
|
}
|
|
379
787
|
/**
|
|
380
|
-
* Removes a file or a link, through the provider that owns it
|
|
788
|
+
* Removes a file or a link, through the provider that owns it, as asked
|
|
789
|
+
* and as resolved (`EXDEV` otherwise, as {@link rmdir}).
|
|
381
790
|
*
|
|
382
791
|
* @param pathStr - The absolute path of the entry.
|
|
383
792
|
* @returns Done, or why not.
|
|
@@ -386,7 +795,7 @@ class VFSDispatcher {
|
|
|
386
795
|
const provider = this.provider_get(pathStr);
|
|
387
796
|
if (!provider.rm)
|
|
388
797
|
return (0, outcome_js_1.vfs_fail)('EROFS');
|
|
389
|
-
const at = await this.
|
|
798
|
+
const at = await this.removalPath_resolve(provider, pathStr, 'rm');
|
|
390
799
|
return at.ok ? provider.rm(at.value) : at;
|
|
391
800
|
}
|
|
392
801
|
/**
|
|
@@ -400,7 +809,8 @@ class VFSDispatcher {
|
|
|
400
809
|
}
|
|
401
810
|
/**
|
|
402
811
|
* Removes a folder and everything under it in one step, where the
|
|
403
|
-
* owning provider can; elsewhere `EROFS`, and `rm -r` walks instead.
|
|
812
|
+
* owning provider can; elsewhere `EROFS`, and `rm -r` walks instead. Owned
|
|
813
|
+
* as asked and as resolved (`EXDEV` otherwise, as {@link rmdir}).
|
|
404
814
|
*
|
|
405
815
|
* @param pathStr - The absolute path of the folder.
|
|
406
816
|
* @returns Done, or why not.
|
|
@@ -409,7 +819,7 @@ class VFSDispatcher {
|
|
|
409
819
|
const provider = this.provider_get(pathStr);
|
|
410
820
|
if (!provider.rmTree)
|
|
411
821
|
return (0, outcome_js_1.vfs_fail)('EROFS');
|
|
412
|
-
const at = await this.
|
|
822
|
+
const at = await this.removalPath_resolve(provider, pathStr, 'rm');
|
|
413
823
|
return at.ok ? provider.rmTree(at.value) : at;
|
|
414
824
|
}
|
|
415
825
|
/**
|