@fnndsc/fond 0.6.2 → 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 +0 -6
- package/dist/errorStack.js +0 -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
|
@@ -0,0 +1,777 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SAFE_SUFFIX = void 0;
|
|
37
|
+
exports.wireName_place = wireName_place;
|
|
38
|
+
exports.namePart_judge = namePart_judge;
|
|
39
|
+
exports.privateTemp_write = privateTemp_write;
|
|
40
|
+
exports.suffix_safe = suffix_safe;
|
|
41
|
+
exports.trustedPath_resolve = trustedPath_resolve;
|
|
42
|
+
exports.trustedRoot_settle = trustedRoot_settle;
|
|
43
|
+
exports.ownFolder_settle = ownFolder_settle;
|
|
44
|
+
exports.ownFile_read = ownFile_read;
|
|
45
|
+
exports.bytes_writeAll = bytes_writeAll;
|
|
46
|
+
exports.ownFile_write = ownFile_write;
|
|
47
|
+
exports.ownFile_take = ownFile_take;
|
|
48
|
+
/**
|
|
49
|
+
* @file Placing a name that came from elsewhere inside a folder on this host.
|
|
50
|
+
*
|
|
51
|
+
* A file name that arrives over a wire, or out of a listing another system
|
|
52
|
+
* made, is a claim about where to write. Joined to a folder as it comes, a
|
|
53
|
+
* name of `../../x`, an absolute one, or one that passes through a link
|
|
54
|
+
* already on this disk writes wherever it says. `wireName_place` gives back
|
|
55
|
+
* the place inside the folder, or the reason there is none.
|
|
56
|
+
*
|
|
57
|
+
* The check is made before the write and the disk can change between the
|
|
58
|
+
* two; it closes what a name can ask for, not a race with a second program
|
|
59
|
+
* on the same host.
|
|
60
|
+
*
|
|
61
|
+
* Key components:
|
|
62
|
+
* - wireName_place: a name from elsewhere placed inside its folder, or why not.
|
|
63
|
+
* - ownFolder_settle, ownFile_read, ownFile_write, ownFile_take: owner-only folders and files of this account.
|
|
64
|
+
* - privateTemp_write: a private temporary file for an edit.
|
|
65
|
+
*
|
|
66
|
+
* Typical usage:
|
|
67
|
+
* ```ts
|
|
68
|
+
* const placed: HostPlace = wireName_place(folder, name);
|
|
69
|
+
* if (placed.ok) ownFile_write(held.path, 'berth-1.json', text);
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* Dependencies: node:fs, node:path; fond's one record writer for owner-only files.
|
|
73
|
+
*
|
|
74
|
+
* @module
|
|
75
|
+
*/
|
|
76
|
+
const node_crypto_1 = require("node:crypto");
|
|
77
|
+
const node_fs_1 = require("node:fs");
|
|
78
|
+
const node_os_1 = require("node:os");
|
|
79
|
+
const path = __importStar(require("node:path"));
|
|
80
|
+
const recordFile_js_1 = require("./recordFile.js");
|
|
81
|
+
/** A path that could not be looked at: neither there nor proved missing. */
|
|
82
|
+
class Uninspectable extends Error {
|
|
83
|
+
/** The file system's code for why. */
|
|
84
|
+
constructor(code) {
|
|
85
|
+
super(code);
|
|
86
|
+
this.code = code;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Whether a path exists, as itself: a link counts, wherever it leads.
|
|
91
|
+
*
|
|
92
|
+
* Only the file system saying `ENOENT` means it is not there. Any other
|
|
93
|
+
* answer (no permission to look, a part that is not a folder, an I/O
|
|
94
|
+
* error) is not knowing, and not knowing is not absence.
|
|
95
|
+
*
|
|
96
|
+
* @param target - The path.
|
|
97
|
+
* @returns True when something is there, false when the file system says nothing is.
|
|
98
|
+
* @throws {Uninspectable} When it could not be looked at.
|
|
99
|
+
*/
|
|
100
|
+
function path_stands(target) {
|
|
101
|
+
try {
|
|
102
|
+
(0, node_fs_1.lstatSync)(target);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
const code = error.code;
|
|
107
|
+
if (code === 'ENOENT')
|
|
108
|
+
return false;
|
|
109
|
+
throw new Uninspectable(code ?? 'unknown');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The real path of the deepest part of a path that exists, with the rest
|
|
114
|
+
* appended as written.
|
|
115
|
+
*
|
|
116
|
+
* @param target - An absolute path.
|
|
117
|
+
* @returns The path with every link in its existing part followed; `dangling` when a link in it leads nowhere; `uninspectable` when a part of it could not be looked at.
|
|
118
|
+
*/
|
|
119
|
+
function existingPart_resolve(target) {
|
|
120
|
+
let existing = target;
|
|
121
|
+
const rest = [];
|
|
122
|
+
try {
|
|
123
|
+
while (!path_stands(existing)) {
|
|
124
|
+
const parent = path.dirname(existing);
|
|
125
|
+
if (parent === existing)
|
|
126
|
+
break;
|
|
127
|
+
rest.unshift(path.basename(existing));
|
|
128
|
+
existing = parent;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
return { failed: 'uninspectable', code: error instanceof Uninspectable ? error.code : 'EIO' };
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return path.join((0, node_fs_1.realpathSync)(existing), ...rest);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
const code = error.code ?? 'EIO';
|
|
139
|
+
return code === 'ENOENT' ? { failed: 'dangling' } : { failed: 'uninspectable', code };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Whether one path is another or lies under it.
|
|
144
|
+
*
|
|
145
|
+
* @param inner - The path asked about.
|
|
146
|
+
* @param outer - The folder.
|
|
147
|
+
* @returns True when `inner` is `outer` or inside it.
|
|
148
|
+
*/
|
|
149
|
+
function path_within(inner, outer) {
|
|
150
|
+
const relative = path.relative(outer, inner);
|
|
151
|
+
if (relative === '')
|
|
152
|
+
return true;
|
|
153
|
+
// A name may itself begin with two dots (`..cache`); only the part `..` leaves.
|
|
154
|
+
return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Whether a name that arrived is an absolute path: by POSIX's rules everywhere, and on Windows also by its own
|
|
158
|
+
* (a drive, a share) or a drive letter with no folder after it (`C:x`).
|
|
159
|
+
*
|
|
160
|
+
* @param name - The name as it arrived.
|
|
161
|
+
* @returns True when it is a path, not a name.
|
|
162
|
+
*/
|
|
163
|
+
function wireName_isAbsolute(name) {
|
|
164
|
+
return path.posix.isAbsolute(name) || (process.platform === 'win32' && (path.win32.isAbsolute(name) || /^[A-Za-z]:/.test(name)));
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Why the parts of a name that arrived are not each a plain name on this platform, or one this machine keeps for
|
|
168
|
+
* its own unfinished files; the first part refused says it.
|
|
169
|
+
*
|
|
170
|
+
* @param shown - The name as it is quoted to the operator.
|
|
171
|
+
* @param parts - Its parts, in order.
|
|
172
|
+
* @returns Null when every part is plain, else the reason.
|
|
173
|
+
*/
|
|
174
|
+
function wireParts_judge(shown, parts) {
|
|
175
|
+
for (const part of parts) {
|
|
176
|
+
const judged = namePart_judge(part, process.platform);
|
|
177
|
+
if (judged !== null)
|
|
178
|
+
return `${shown} ${judged}`;
|
|
179
|
+
if (part.startsWith('.mise-part-'))
|
|
180
|
+
return `${shown}: a name this machine keeps for its own unfinished files`;
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Places a name from another system inside a folder on this host.
|
|
186
|
+
*
|
|
187
|
+
* The name may have folders of its own (`anat/t1.nii`), under either
|
|
188
|
+
* separator. It is refused when it is empty, holds a NUL, is absolute by
|
|
189
|
+
* either system's rules, has an empty, `.` or `..` part, or when the place
|
|
190
|
+
* it comes to, with every link already on this disk followed, is not
|
|
191
|
+
* inside the folder, or when a part of it could not be looked at.
|
|
192
|
+
*
|
|
193
|
+
* @param folder - The folder the name belongs in.
|
|
194
|
+
* @param name - The name as it arrived.
|
|
195
|
+
* @returns The absolute place inside the folder, or the reason it has none.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* wireName_place('/data/in', 'anat/t1.nii'); // { ok: true, place: '/data/in/anat/t1.nii' }
|
|
200
|
+
* wireName_place('/data/in', '../x'); // { ok: false, reason: "'../x' has a '..' part" }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
function wireName_place(folder, name) {
|
|
204
|
+
const shown = JSON.stringify(name);
|
|
205
|
+
if (name.length === 0)
|
|
206
|
+
return { ok: false, reason: 'an empty name' };
|
|
207
|
+
if (wireName_isAbsolute(name))
|
|
208
|
+
return { ok: false, reason: `${shown} is an absolute path, not a name` };
|
|
209
|
+
const parts = name.split(/[\\/]/);
|
|
210
|
+
const judged = wireParts_judge(shown, parts);
|
|
211
|
+
if (judged !== null)
|
|
212
|
+
return { ok: false, reason: judged };
|
|
213
|
+
const root = path.resolve(folder);
|
|
214
|
+
const place = path.join(root, ...parts);
|
|
215
|
+
if (!path_within(place, root) || place === root)
|
|
216
|
+
return { ok: false, reason: `${shown} does not stay inside ${root}` };
|
|
217
|
+
const realRoot = existingPart_resolve(root);
|
|
218
|
+
const realPlace = existingPart_resolve(place);
|
|
219
|
+
for (const resolved of [realRoot, realPlace]) {
|
|
220
|
+
if (typeof resolved === 'string')
|
|
221
|
+
continue;
|
|
222
|
+
if (resolved.failed === 'dangling')
|
|
223
|
+
return { ok: false, reason: `${shown} passes through a link that leads nowhere` };
|
|
224
|
+
return { ok: false, reason: `${shown} passes through a place that could not be looked at (${resolved.code ?? 'EIO'})`, unseen: resolved.code ?? 'EIO' };
|
|
225
|
+
}
|
|
226
|
+
if (typeof realRoot !== 'string' || typeof realPlace !== 'string')
|
|
227
|
+
return { ok: false, reason: `${shown} could not be placed` };
|
|
228
|
+
if (!path_within(realPlace, realRoot) || realPlace === realRoot) {
|
|
229
|
+
return { ok: false, reason: `${shown} passes through a link that leads outside ${root}` };
|
|
230
|
+
}
|
|
231
|
+
return { ok: true, place };
|
|
232
|
+
}
|
|
233
|
+
/** Names Windows keeps for devices, with or without an extension. */
|
|
234
|
+
const WINDOWS_DEVICE = /^(con|prn|aux|nul|com[0-9¹²³]|lpt[0-9¹²³])(\..*)?$/i;
|
|
235
|
+
/**
|
|
236
|
+
* Whether one part of a name that arrived is an ordinary file or folder name on this platform: not empty, not `.`
|
|
237
|
+
* or `..`, no NUL; on Windows also no reserved device name, no `:` (a drive or an alternate data stream), none of
|
|
238
|
+
* `<>"|?*`, no trailing dot or space. An ordinary colon in a POSIX name is allowed.
|
|
239
|
+
*
|
|
240
|
+
* @param part - One part.
|
|
241
|
+
* @param platform - The platform the file is written on.
|
|
242
|
+
* @returns Null when it is ordinary, else why not.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* namePart_judge('T:map.nii', 'linux'); // null
|
|
247
|
+
* namePart_judge('CON', 'win32'); // 'has "CON", a name Windows keeps for a device'
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
function namePart_judge(part, platform) {
|
|
251
|
+
const shown = JSON.stringify(part);
|
|
252
|
+
if (part === '')
|
|
253
|
+
return 'has an empty part';
|
|
254
|
+
if (part === '.' || part === '..')
|
|
255
|
+
return `has a '${part}' part`;
|
|
256
|
+
if (part.includes('\0'))
|
|
257
|
+
return 'holds a NUL';
|
|
258
|
+
if (platform !== 'win32')
|
|
259
|
+
return null;
|
|
260
|
+
if (WINDOWS_DEVICE.test(part))
|
|
261
|
+
return `has ${shown}, a name Windows keeps for a device`;
|
|
262
|
+
if (/[<>:"|?*]/.test(part) || /[\u0000-\u001f]/.test(part))
|
|
263
|
+
return `has ${shown}, which holds a character Windows does not allow in a name`;
|
|
264
|
+
if (/[. ]$/.test(part))
|
|
265
|
+
return `has ${shown}, which ends with a dot or a space (Windows drops them)`;
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
/** A name a private temporary file may take: a plain name, never a path, `..` or NUL. */
|
|
269
|
+
const PRIVATE_NAME = /^(?!\.\.?$)[A-Za-z0-9._+-]{1,64}$/;
|
|
270
|
+
/** A folder prefix: a plain name, under the temporary folder. */
|
|
271
|
+
const PRIVATE_PREFIX = /^[A-Za-z0-9_+-][A-Za-z0-9._+-]{0,31}$/;
|
|
272
|
+
/** A file suffix a caller may ask for (`.mise`, `.json`): a dot and a few plain characters. */
|
|
273
|
+
exports.SAFE_SUFFIX = /^\.[A-Za-z0-9_+-]{1,16}$/;
|
|
274
|
+
/**
|
|
275
|
+
* Writes a private temporary file.
|
|
276
|
+
*
|
|
277
|
+
* @param prefix - The folder's prefix under the system's temporary folder (`chell-edit-`).
|
|
278
|
+
* @param name - The file's name inside it: a plain name (no separator, `..` or NUL), else refused.
|
|
279
|
+
* @param data - What it holds: text or bytes.
|
|
280
|
+
* @returns The file, its folder, and how to remove them.
|
|
281
|
+
* @throws {Error} When the name or the prefix is not a plain name, the data neither text nor bytes, or the file cannot be written (the folder is then removed).
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* const temp: PrivateTemp = privateTemp_write('chell-config-', 'config.tmp', bytes);
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
function privateTemp_write(prefix, name, data) {
|
|
289
|
+
// Each checked as the string it must be before anything is made: a test coerces, a name that is not a string is not one.
|
|
290
|
+
if (typeof name !== 'string' || !PRIVATE_NAME.test(name))
|
|
291
|
+
throw new Error(`a private temporary file's name is a plain name: ${JSON.stringify(name)}`);
|
|
292
|
+
if (typeof data !== 'string' && !(data instanceof Uint8Array))
|
|
293
|
+
throw new Error('a private temporary file holds text or bytes');
|
|
294
|
+
if (typeof prefix !== 'string' || !PRIVATE_PREFIX.test(prefix))
|
|
295
|
+
throw new Error(`a private temporary folder's prefix is a plain name: ${JSON.stringify(prefix)}`);
|
|
296
|
+
const folder = (0, node_fs_1.mkdtempSync)(path.join((0, node_os_1.tmpdir)(), prefix));
|
|
297
|
+
const file = path.join(folder, name);
|
|
298
|
+
try {
|
|
299
|
+
for (const [at, mode, write] of [[folder, 0o700, true], [file, 0o600, false]]) {
|
|
300
|
+
(0, node_fs_1.chmodSync)(at, mode);
|
|
301
|
+
if (write)
|
|
302
|
+
(0, node_fs_1.writeFileSync)(file, data, { flag: 'wx', mode: 0o600 });
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
// A folder half made (a full disk mid-write, say) is not left behind.
|
|
307
|
+
(0, node_fs_1.rmSync)(folder, { recursive: true, force: true });
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
return { folder, path: file, folder_remove: () => { (0, node_fs_1.rmSync)(folder, { recursive: true, force: true }); } };
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* A suffix as asked, when it is a safe one; else the default.
|
|
314
|
+
*
|
|
315
|
+
* @param asked - The suffix asked for (a remote surface's, an operand's).
|
|
316
|
+
* @param fallback - What is used otherwise.
|
|
317
|
+
* @returns The suffix.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* suffix_safe('../x', '.txt'); // '.txt'
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
function suffix_safe(asked, fallback) {
|
|
325
|
+
return asked !== undefined && exports.SAFE_SUFFIX.test(asked) ? asked : fallback;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* This account's uid.
|
|
329
|
+
*
|
|
330
|
+
* @returns The uid, or null where the platform has none (then no ownership is asked).
|
|
331
|
+
*/
|
|
332
|
+
function uid_get() {
|
|
333
|
+
return typeof process.getuid === 'function' ? process.getuid() : null;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* An error's code, read off the object (an error made in another realm is no `instanceof Error` here).
|
|
337
|
+
*
|
|
338
|
+
* @param error - What was thrown.
|
|
339
|
+
* @returns Its code, or 'unknown'.
|
|
340
|
+
*/
|
|
341
|
+
function errorCode_read(error) {
|
|
342
|
+
const code = typeof error === 'object' && error !== null && 'code' in error ? error.code : undefined;
|
|
343
|
+
return typeof code === 'string' ? code : 'unknown';
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* A refusal for a failed filesystem call: absence when the error is ENOENT, else the code.
|
|
347
|
+
*
|
|
348
|
+
* @param place - The path.
|
|
349
|
+
* @param error - What was thrown.
|
|
350
|
+
* @param doing - What failed, for the words.
|
|
351
|
+
* @returns The refusal.
|
|
352
|
+
*/
|
|
353
|
+
function fsRefusal_make(place, error, doing) {
|
|
354
|
+
const code = errorCode_read(error);
|
|
355
|
+
if (code === 'ENOENT')
|
|
356
|
+
return { ok: false, reason: `${place}: not there`, missing: true };
|
|
357
|
+
if (code === 'ELOOP')
|
|
358
|
+
return { ok: false, reason: `${place}: a link` };
|
|
359
|
+
return { ok: false, reason: `${place}: ${doing} failed (${code})` };
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Whether a folder on the way to an owner-only place is one no other account can replace what is under it in:
|
|
363
|
+
* root's or this account's, and writable by group or others only when it is root's and sticky (`/tmp`).
|
|
364
|
+
*
|
|
365
|
+
* @param stats - The folder's lstat.
|
|
366
|
+
* @param uid - This account's uid.
|
|
367
|
+
* @returns True when it is trusted.
|
|
368
|
+
*/
|
|
369
|
+
function ancestor_isTrusted(stats, uid) {
|
|
370
|
+
if (!stats.isDirectory())
|
|
371
|
+
return false;
|
|
372
|
+
if (stats.uid !== 0 && stats.uid !== uid)
|
|
373
|
+
return false;
|
|
374
|
+
const opened = (stats.mode & 0o022) !== 0;
|
|
375
|
+
return !opened || (stats.uid === 0 && (stats.mode & 0o1000) !== 0);
|
|
376
|
+
}
|
|
377
|
+
/** The most links a trusted walk follows. */
|
|
378
|
+
const LINK_HOPS_MAX = 40;
|
|
379
|
+
/**
|
|
380
|
+
* Takes one name of a trusted walk: a trusted folder is entered; a link is followed (its folder is trusted, so no
|
|
381
|
+
* other account can change it), its target's names put first; anything else ends the walk.
|
|
382
|
+
*
|
|
383
|
+
* @param place - Where the walk is.
|
|
384
|
+
* @param name - The next name.
|
|
385
|
+
* @param uid - This account's uid.
|
|
386
|
+
* @returns Where the walk goes on from, or why it stops.
|
|
387
|
+
*/
|
|
388
|
+
function walkStep_take(place, name, uid) {
|
|
389
|
+
if (name === '.' || name.length === 0)
|
|
390
|
+
return place;
|
|
391
|
+
if (name === '..')
|
|
392
|
+
return { ...place, at: path.dirname(place.at) };
|
|
393
|
+
const next = path.join(place.at, name);
|
|
394
|
+
let stats;
|
|
395
|
+
try {
|
|
396
|
+
stats = (0, node_fs_1.lstatSync)(next);
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
const refused = fsRefusal_make(next, error, 'lstat');
|
|
400
|
+
// Not there: where the walk stood (a trusted folder, every link before resolved) and the names still to go.
|
|
401
|
+
return refused.missing === true ? { ...refused, stoppedAt: place.at, stillToGo: [name, ...place.rest] } : refused;
|
|
402
|
+
}
|
|
403
|
+
if (stats.isSymbolicLink())
|
|
404
|
+
return walkLink_follow(place, next, stats, uid);
|
|
405
|
+
if (!ancestor_isTrusted(stats, uid))
|
|
406
|
+
return { ok: false, reason: `${next}: ${stats.isDirectory() ? 'open to other accounts' : 'not a folder'}` };
|
|
407
|
+
return { ...place, at: next };
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Follows a link a trusted walk came to: its target's names put before the names still to go, from `/` when the
|
|
411
|
+
* target is absolute, else from the folder the link stands in. Refused past the most links a walk follows, and for a
|
|
412
|
+
* link another account owns.
|
|
413
|
+
*
|
|
414
|
+
* @param place - Where the walk is: the trusted folder the link stands in.
|
|
415
|
+
* @param next - The link's path.
|
|
416
|
+
* @param stats - The link's lstat.
|
|
417
|
+
* @param uid - This account's uid.
|
|
418
|
+
* @returns Where the walk goes on from, or why it stops.
|
|
419
|
+
*/
|
|
420
|
+
function walkLink_follow(place, next, stats, uid) {
|
|
421
|
+
if (place.hops >= LINK_HOPS_MAX)
|
|
422
|
+
return { ok: false, reason: `${next}: too many links` };
|
|
423
|
+
// In a shared sticky folder (`/tmp`) an entry is its owner's to replace: a link is followed only when it is
|
|
424
|
+
// root's or this account's.
|
|
425
|
+
if (stats.uid !== 0 && stats.uid !== uid)
|
|
426
|
+
return { ok: false, reason: `${next}: a link of another account's` };
|
|
427
|
+
let link;
|
|
428
|
+
try {
|
|
429
|
+
link = (0, node_fs_1.readlinkSync)(next);
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
return fsRefusal_make(next, error, 'readlink');
|
|
433
|
+
}
|
|
434
|
+
const at = path.isAbsolute(link) ? path.parse(link).root : place.at;
|
|
435
|
+
return { at, rest: [...link.split(path.sep), ...place.rest], hops: place.hops + 1 };
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Whether a path as spelled names `..`.
|
|
439
|
+
*
|
|
440
|
+
* @param spelled - The path.
|
|
441
|
+
* @returns True when it does.
|
|
442
|
+
*/
|
|
443
|
+
function spelling_climbs(spelled) {
|
|
444
|
+
return spelled.split(/[\\/]/).includes('..');
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Resolves a folder's path through trusted folders only: from `/` (itself trusted), each name as spelled, every
|
|
448
|
+
* folder root's or this account's and not open to others (unless root's and sticky), every link found in such a
|
|
449
|
+
* folder followed the same way. No folder another account could change is passed through, by any spelling.
|
|
450
|
+
*
|
|
451
|
+
* @param folder - The folder.
|
|
452
|
+
* @param uid - This account's uid.
|
|
453
|
+
* @returns The resolved path, or why not (`missing` when a name on the way is not there).
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
* ```ts
|
|
457
|
+
* const walked: OwnFolder | OwnRefusal = trustedPath_resolve('/home/me/.local/state/porter', uid);
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
460
|
+
function trustedPath_resolve(folder, uid = uid_get()) {
|
|
461
|
+
// `..` as spelled would be folded away before any link on the way is walked: refused, not guessed at.
|
|
462
|
+
if (spelling_climbs(folder))
|
|
463
|
+
return { ok: false, reason: `${folder}: names '..'` };
|
|
464
|
+
const absolute = path.resolve(folder);
|
|
465
|
+
if (uid === null) {
|
|
466
|
+
try {
|
|
467
|
+
return { ok: true, path: (0, node_fs_1.realpathSync)(absolute) };
|
|
468
|
+
}
|
|
469
|
+
catch (error) {
|
|
470
|
+
return fsRefusal_make(absolute, error, 'realpath');
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const root = path.parse(absolute).root;
|
|
474
|
+
let rootStats;
|
|
475
|
+
try {
|
|
476
|
+
rootStats = (0, node_fs_1.lstatSync)(root);
|
|
477
|
+
}
|
|
478
|
+
catch (error) {
|
|
479
|
+
return fsRefusal_make(root, error, 'lstat');
|
|
480
|
+
}
|
|
481
|
+
if (!ancestor_isTrusted(rootStats, uid))
|
|
482
|
+
return { ok: false, reason: `${root}: open to other accounts` };
|
|
483
|
+
let place = { at: root, rest: absolute.slice(root.length).split(path.sep), hops: 0 };
|
|
484
|
+
while (place.rest.length > 0) {
|
|
485
|
+
const [name, ...rest] = place.rest;
|
|
486
|
+
const stepped = walkStep_take({ ...place, rest }, name, uid);
|
|
487
|
+
if ('ok' in stepped)
|
|
488
|
+
return stepped;
|
|
489
|
+
place = stepped;
|
|
490
|
+
}
|
|
491
|
+
return { ok: true, path: place.at };
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Holds a host's state root: its path resolved through trusted folders only, and the root itself, when it is there,
|
|
495
|
+
* root's or this account's and not writable by group or others, sticky or not (a shared `/tmp` is a fine place to
|
|
496
|
+
* pass through and no place to keep state in). A root not made yet, below trusted folders, is a first start: its
|
|
497
|
+
* path is the resolved folder that is there joined with the names still to make.
|
|
498
|
+
*
|
|
499
|
+
* @param folder - The state root.
|
|
500
|
+
* @param uid - This account's uid (a test's seam).
|
|
501
|
+
* @returns The root's resolved path, or the first thing on the way another account could change.
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* ```ts
|
|
505
|
+
* const root: OwnFolder | OwnRefusal = trustedRoot_settle(stateDir);
|
|
506
|
+
* if (root.ok) host_start(root.path);
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
function trustedRoot_settle(folder, uid = uid_get()) {
|
|
510
|
+
const walked = trustedPath_resolve(folder, uid);
|
|
511
|
+
if (walked.ok) {
|
|
512
|
+
let stats;
|
|
513
|
+
try {
|
|
514
|
+
stats = (0, node_fs_1.lstatSync)(walked.path);
|
|
515
|
+
}
|
|
516
|
+
catch (error) {
|
|
517
|
+
return fsRefusal_make(walked.path, error, 'lstat');
|
|
518
|
+
}
|
|
519
|
+
if (uid !== null && stats.uid !== 0 && stats.uid !== uid)
|
|
520
|
+
return { ok: false, reason: `${walked.path}: another account's` };
|
|
521
|
+
if ((stats.mode & 0o022) !== 0)
|
|
522
|
+
return { ok: false, reason: `${walked.path}: open to other accounts` };
|
|
523
|
+
return walked;
|
|
524
|
+
}
|
|
525
|
+
if (walked.missing !== true || walked.stoppedAt === undefined || walked.stillToGo === undefined)
|
|
526
|
+
return walked;
|
|
527
|
+
// Not there yet: the folder the walk stood in (every link before it resolved, so a link to nothing is never taken
|
|
528
|
+
// for the place it names), held as a root is, and the names still to make. Those are plain names, made below it.
|
|
529
|
+
const toMake = walked.stillToGo.filter((name) => name.length > 0 && name !== '.');
|
|
530
|
+
if (toMake.includes('..'))
|
|
531
|
+
return { ok: false, reason: `${folder}: names '..' past ${walked.stoppedAt}` };
|
|
532
|
+
const stood = trustedRoot_settle(walked.stoppedAt, uid);
|
|
533
|
+
return stood.ok ? { ok: true, path: path.join(stood.path, ...toMake) } : stood;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Holds a folder only this account can use: its parent resolved through trusted folders only
|
|
537
|
+
* (`trustedPath_resolve`); the folder itself a real directory, not a link, this account's, with no group or other
|
|
538
|
+
* bits. Once that holds, no other account can swap the folder or write in it, so its resolved path is as good as a
|
|
539
|
+
* handle: every later use names `path`, never the spelling it was asked by.
|
|
540
|
+
*
|
|
541
|
+
* @param folder - The folder.
|
|
542
|
+
* @param create - Make it (0700) when it is missing; a reader passes false and a missing folder is refused.
|
|
543
|
+
* @param uid - This account's uid (a test's seam).
|
|
544
|
+
* @returns Held with its path, or why not (`missing` when it, or its parent, is simply not there).
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```ts
|
|
548
|
+
* const held: OwnFolder | OwnRefusal = ownFolder_settle(berthDir, true);
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
function ownFolder_settle(folder, create, uid = uid_get()) {
|
|
552
|
+
if (spelling_climbs(folder))
|
|
553
|
+
return { ok: false, reason: `${folder}: names '..'` };
|
|
554
|
+
const absolute = path.resolve(folder);
|
|
555
|
+
const parent = trustedPath_resolve(path.dirname(absolute), uid);
|
|
556
|
+
if (!parent.ok)
|
|
557
|
+
return { ...parent, reason: `${absolute}: ${parent.reason}` };
|
|
558
|
+
const target = path.join(parent.path, path.basename(absolute));
|
|
559
|
+
let stats;
|
|
560
|
+
try {
|
|
561
|
+
stats = (0, node_fs_1.lstatSync)(target);
|
|
562
|
+
}
|
|
563
|
+
catch (error) {
|
|
564
|
+
if (!create || errorCode_read(error) !== 'ENOENT')
|
|
565
|
+
return fsRefusal_make(target, error, 'lstat');
|
|
566
|
+
try {
|
|
567
|
+
(0, node_fs_1.mkdirSync)(target, { mode: 0o700 });
|
|
568
|
+
stats = (0, node_fs_1.lstatSync)(target);
|
|
569
|
+
}
|
|
570
|
+
catch (made) {
|
|
571
|
+
return { ok: false, reason: `${target}: could not be made (${errorCode_read(made)})` };
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return ownFolder_judge(target, stats, uid);
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Whether a folder's lstat is one only this account can use.
|
|
578
|
+
*
|
|
579
|
+
* @param target - The folder.
|
|
580
|
+
* @param stats - Its lstat.
|
|
581
|
+
* @param uid - This account's uid.
|
|
582
|
+
* @returns Held with its path, or why not.
|
|
583
|
+
*/
|
|
584
|
+
function ownFolder_judge(target, stats, uid) {
|
|
585
|
+
if (stats.isSymbolicLink())
|
|
586
|
+
return { ok: false, reason: `${target}: a link` };
|
|
587
|
+
if (!stats.isDirectory())
|
|
588
|
+
return { ok: false, reason: `${target}: not a folder` };
|
|
589
|
+
if (uid !== null && stats.uid !== uid)
|
|
590
|
+
return { ok: false, reason: `${target}: another account's` };
|
|
591
|
+
if ((stats.mode & 0o077) !== 0)
|
|
592
|
+
return { ok: false, reason: `${target}: wider than 0700` };
|
|
593
|
+
return { ok: true, path: target };
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Whether a file's stat is one of this account's own: a regular file of this uid with no group or other bits.
|
|
597
|
+
*
|
|
598
|
+
* @param file - The file.
|
|
599
|
+
* @param stats - Its stat or lstat.
|
|
600
|
+
* @param uid - This account's uid.
|
|
601
|
+
* @returns Null when it is, else why not.
|
|
602
|
+
*/
|
|
603
|
+
function ownFile_judge(file, stats, uid) {
|
|
604
|
+
if (stats.isSymbolicLink())
|
|
605
|
+
return { ok: false, reason: `${file}: a link, left as it is` };
|
|
606
|
+
if (!stats.isFile())
|
|
607
|
+
return { ok: false, reason: `${file}: not a regular file, left as it is` };
|
|
608
|
+
if (uid !== null && stats.uid !== uid)
|
|
609
|
+
return { ok: false, reason: `${file}: another account's, left as it is` };
|
|
610
|
+
if ((stats.mode & 0o177) !== 0)
|
|
611
|
+
return { ok: false, reason: `${file}: wider than 0600, left as it is` };
|
|
612
|
+
return null;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Reads an owner-only file in a held folder: opened without following a link, a regular file of this account's
|
|
616
|
+
* with no group or other bits, at most `maxBytes` (more is refused).
|
|
617
|
+
*
|
|
618
|
+
* @param file - The file, named under a held folder's `path`.
|
|
619
|
+
* @param maxBytes - The most it may hold.
|
|
620
|
+
* @param uid - This account's uid (a test's seam).
|
|
621
|
+
* @returns Its text, or why not (`missing` when it is not there).
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* const read: OwnRead = ownFile_read(join(held.path, 'berth-0123.json'), 64 * 1024);
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
function ownFile_read(file, maxBytes, uid = uid_get()) {
|
|
629
|
+
let handle;
|
|
630
|
+
try {
|
|
631
|
+
handle = (0, node_fs_1.openSync)(file, node_fs_1.constants.O_RDONLY | node_fs_1.constants.O_NOFOLLOW | node_fs_1.constants.O_NONBLOCK);
|
|
632
|
+
}
|
|
633
|
+
catch (error) {
|
|
634
|
+
return fsRefusal_make(file, error, 'open');
|
|
635
|
+
}
|
|
636
|
+
try {
|
|
637
|
+
const refused = ownFile_judge(file, (0, node_fs_1.fstatSync)(handle), uid);
|
|
638
|
+
if (refused !== null)
|
|
639
|
+
return refused;
|
|
640
|
+
const buffer = Buffer.alloc(maxBytes + 1);
|
|
641
|
+
let filled = 0;
|
|
642
|
+
for (;;) {
|
|
643
|
+
const got = (0, node_fs_1.readSync)(handle, buffer, filled, buffer.length - filled, null);
|
|
644
|
+
if (got === 0)
|
|
645
|
+
break;
|
|
646
|
+
filled += got;
|
|
647
|
+
if (filled > maxBytes)
|
|
648
|
+
return { ok: false, reason: `${file}: larger than ${String(maxBytes)} bytes` };
|
|
649
|
+
}
|
|
650
|
+
return { ok: true, text: buffer.subarray(0, filled).toString('utf8') };
|
|
651
|
+
}
|
|
652
|
+
catch (error) {
|
|
653
|
+
return fsRefusal_make(file, error, 'read');
|
|
654
|
+
}
|
|
655
|
+
finally {
|
|
656
|
+
(0, node_fs_1.closeSync)(handle);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Writes every byte of a buffer on an open descriptor, however many calls it takes.
|
|
661
|
+
*
|
|
662
|
+
* @param handle - The descriptor.
|
|
663
|
+
* @param bytes - What to write.
|
|
664
|
+
* @param write - The write call (a test's seam).
|
|
665
|
+
* @throws {Error} When a write makes no progress.
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* ```ts
|
|
669
|
+
* bytes_writeAll(handle, Buffer.from(text, 'utf8'));
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
672
|
+
function bytes_writeAll(handle, bytes, write = node_fs_1.writeSync) {
|
|
673
|
+
let done = 0;
|
|
674
|
+
while (done < bytes.length) {
|
|
675
|
+
const wrote = write(handle, bytes, done, bytes.length - done);
|
|
676
|
+
if (wrote <= 0)
|
|
677
|
+
throw new Error(`a write made no progress at byte ${String(done)} of ${String(bytes.length)}`);
|
|
678
|
+
done += wrote;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Writes an owner-only file in a held folder, atomically: a fresh temporary file (`O_EXCL|O_NOFOLLOW`, 0600), every
|
|
683
|
+
* byte written, synced, renamed over the name. A standing entry that is not this account's regular 0600 file (a
|
|
684
|
+
* link, another account's, wider) is refused and left as it is, its target untouched; a failed write leaves the
|
|
685
|
+
* standing record as it was.
|
|
686
|
+
*
|
|
687
|
+
* @param folder - The held folder's `path`.
|
|
688
|
+
* @param name - The file's name in it (a plain name).
|
|
689
|
+
* @param text - What it holds.
|
|
690
|
+
* @param uid - This account's uid (a test's seam).
|
|
691
|
+
* @param write - The write call (a test's seam).
|
|
692
|
+
* @returns Held, or why not.
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```ts
|
|
696
|
+
* ownFile_write(held.path, 'berth-0123456789abcdef.json', JSON.stringify(record));
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
699
|
+
function ownFile_write(folder, name, text, uid = uid_get(), write) {
|
|
700
|
+
if (!PRIVATE_NAME.test(name))
|
|
701
|
+
return { ok: false, reason: `${JSON.stringify(name)}: not a plain name` };
|
|
702
|
+
const target = path.join(folder, name);
|
|
703
|
+
const standing = standing_judge(target, uid);
|
|
704
|
+
if (standing !== null)
|
|
705
|
+
return standing;
|
|
706
|
+
// The one writer of a program's own records, after this function's own checks of what stands at the name.
|
|
707
|
+
try {
|
|
708
|
+
(0, recordFile_js_1.recordFile_write)(target, text, write === undefined ? { mode: 0o600 } : {
|
|
709
|
+
mode: 0o600,
|
|
710
|
+
bytes_write(handle, bytes, offset, length) { return write(handle, bytes, offset, length); },
|
|
711
|
+
});
|
|
712
|
+
return { ok: true };
|
|
713
|
+
}
|
|
714
|
+
catch (error) {
|
|
715
|
+
return { ok: false, reason: `${target}: could not be written (${error instanceof Error && !('code' in error) ? error.message : errorCode_read(error)})` };
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Whether what stands at a name may be replaced or taken: nothing, or this account's regular 0600 file.
|
|
720
|
+
*
|
|
721
|
+
* @param target - The name's path.
|
|
722
|
+
* @param uid - This account's uid.
|
|
723
|
+
* @returns Null when it may, else why not (`missing` is not returned: absence is fine).
|
|
724
|
+
*/
|
|
725
|
+
function standing_judge(target, uid) {
|
|
726
|
+
try {
|
|
727
|
+
return ownFile_judge(target, (0, node_fs_1.lstatSync)(target), uid);
|
|
728
|
+
}
|
|
729
|
+
catch (error) {
|
|
730
|
+
return errorCode_read(error) === 'ENOENT' ? null : fsRefusal_make(target, error, 'lstat');
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Takes an owner-only file: judged where it stands (a link, another account's or a wider file is refused and left
|
|
735
|
+
* as it is), then renamed aside (atomic), read and the aside name removed. What is taken is never put back; a note
|
|
736
|
+
* taken by two readers is had by one.
|
|
737
|
+
*
|
|
738
|
+
* @param folder - The held folder's `path`.
|
|
739
|
+
* @param name - The file's name.
|
|
740
|
+
* @param maxBytes - The most it may hold.
|
|
741
|
+
* @param uid - This account's uid (a test's seam).
|
|
742
|
+
* @returns Its text, or why not.
|
|
743
|
+
*
|
|
744
|
+
* @example
|
|
745
|
+
* ```ts
|
|
746
|
+
* const note: OwnRead = ownFile_take(held.path, 'closing-0123.json', 4096);
|
|
747
|
+
* ```
|
|
748
|
+
*/
|
|
749
|
+
function ownFile_take(folder, name, maxBytes, uid = uid_get()) {
|
|
750
|
+
if (!PRIVATE_NAME.test(name))
|
|
751
|
+
return { ok: false, reason: `${JSON.stringify(name)}: not a plain name` };
|
|
752
|
+
const file = path.join(folder, name);
|
|
753
|
+
let standing;
|
|
754
|
+
try {
|
|
755
|
+
standing = (0, node_fs_1.lstatSync)(file);
|
|
756
|
+
}
|
|
757
|
+
catch (error) {
|
|
758
|
+
return fsRefusal_make(file, error, 'lstat');
|
|
759
|
+
}
|
|
760
|
+
const refused = ownFile_judge(file, standing, uid);
|
|
761
|
+
if (refused !== null)
|
|
762
|
+
return refused;
|
|
763
|
+
const aside = path.join(folder, `.${name}.${(0, node_crypto_1.randomBytes)(6).toString('hex')}.taken`);
|
|
764
|
+
try {
|
|
765
|
+
(0, node_fs_1.renameSync)(file, aside);
|
|
766
|
+
}
|
|
767
|
+
catch (error) {
|
|
768
|
+
return fsRefusal_make(file, error, 'rename');
|
|
769
|
+
}
|
|
770
|
+
try {
|
|
771
|
+
return ownFile_read(aside, maxBytes, uid);
|
|
772
|
+
}
|
|
773
|
+
finally {
|
|
774
|
+
(0, node_fs_1.rmSync)(aside, { force: true });
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
//# sourceMappingURL=hostPlace.js.map
|