swarm-deploy 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.md +680 -49
- package/RELEASING.md +2 -2
- package/SECURITY.md +2 -3
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +79 -22
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +19 -29
- package/dist/client.js +46 -55
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +4 -0
- package/dist/errors.js.map +1 -1
- package/dist/files.d.ts +13 -28
- package/dist/files.js +13 -78
- package/dist/files.js.map +1 -1
- package/dist/hooks-module.d.ts +9 -0
- package/dist/hooks-module.js +118 -0
- package/dist/hooks-module.js.map +1 -0
- package/dist/hooks.d.ts +69 -0
- package/dist/hooks.js +88 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/release.d.ts +26 -0
- package/dist/release.js +419 -0
- package/dist/release.js.map +1 -0
- package/dist/server.d.ts +86 -0
- package/dist/server.js +405 -53
- package/dist/server.js.map +1 -1
- package/dist/storage/commit-journal.d.ts +39 -2
- package/dist/storage/commit-journal.js +140 -2
- package/dist/storage/commit-journal.js.map +1 -1
- package/dist/storage/commit-store.d.ts +69 -8
- package/dist/storage/commit-store.js +374 -22
- package/dist/storage/commit-store.js.map +1 -1
- package/dist/storage/layout.js +7 -1
- package/dist/storage/layout.js.map +1 -1
- package/dist/storage/link-store.d.ts +70 -0
- package/dist/storage/link-store.js +363 -0
- package/dist/storage/link-store.js.map +1 -0
- package/dist/storage/recovery.d.ts +2 -1
- package/dist/storage/recovery.js +8 -1
- package/dist/storage/recovery.js.map +1 -1
- package/dist/storage/retention.d.ts +41 -21
- package/dist/storage/retention.js +162 -8
- package/dist/storage/retention.js.map +1 -1
- package/dist/storage/tar-session-store.d.ts +36 -5
- package/dist/storage/tar-session-store.js +283 -55
- package/dist/storage/tar-session-store.js.map +1 -1
- package/dist/storage/tree-fs.d.ts +44 -0
- package/dist/storage/tree-fs.js +580 -0
- package/dist/storage/tree-fs.js.map +1 -0
- package/dist/storage/tree-staging.d.ts +9 -0
- package/dist/storage/tree-staging.js +64 -0
- package/dist/storage/tree-staging.js.map +1 -0
- package/dist/storage/types.d.ts +15 -0
- package/dist/symlinks.d.ts +36 -0
- package/dist/symlinks.js +128 -0
- package/dist/symlinks.js.map +1 -0
- package/dist/tar-protocol/controls.d.ts +25 -0
- package/dist/tar-protocol/controls.js +108 -2
- package/dist/tar-protocol/controls.js.map +1 -1
- package/dist/tar-protocol/direct-wire.d.ts +3 -3
- package/dist/tar-protocol/direct-wire.js +2 -2
- package/dist/tar-protocol/direct-wire.js.map +1 -1
- package/dist/tar-protocol/manifest.d.ts +13 -1
- package/dist/tar-protocol/manifest.js +26 -1
- package/dist/tar-protocol/manifest.js.map +1 -1
- package/dist/tar-protocol/tree-extract.d.ts +37 -0
- package/dist/tar-protocol/tree-extract.js +240 -0
- package/dist/tar-protocol/tree-extract.js.map +1 -0
- package/dist/tar-protocol/tree-manifest.d.ts +45 -0
- package/dist/tar-protocol/tree-manifest.js +277 -0
- package/dist/tar-protocol/tree-manifest.js.map +1 -0
- package/dist/tar-protocol/tree-path.d.ts +15 -0
- package/dist/tar-protocol/tree-path.js +68 -0
- package/dist/tar-protocol/tree-path.js.map +1 -0
- package/dist/tar-protocol/tree.d.ts +68 -0
- package/dist/tar-protocol/tree.js +269 -0
- package/dist/tar-protocol/tree.js.map +1 -0
- package/dist/tar-protocol/ustar.d.ts +14 -0
- package/dist/tar-protocol/ustar.js +81 -1
- package/dist/tar-protocol/ustar.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/package.json +3 -1
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LinkStore = void 0;
|
|
7
|
+
const b4a_1 = __importDefault(require("b4a"));
|
|
8
|
+
const error_code_js_1 = require("../error-code.js");
|
|
9
|
+
const _fs_1 = __importDefault(require("#fs"));
|
|
10
|
+
const _path_1 = __importDefault(require("#path"));
|
|
11
|
+
const sodium_native_1 = __importDefault(require("sodium-native"));
|
|
12
|
+
const errors_js_1 = require("../errors.js");
|
|
13
|
+
const files_js_1 = require("../files.js");
|
|
14
|
+
const hash_js_1 = require("../tar-protocol/hash.js");
|
|
15
|
+
const atomic_file_js_1 = require("./atomic-file.js");
|
|
16
|
+
const layout_js_1 = require("./layout.js");
|
|
17
|
+
const tree_fs_js_1 = require("./tree-fs.js");
|
|
18
|
+
const MAX_LINK_RECORD_BYTES = 4 * 1024;
|
|
19
|
+
const RECORD_FILENAME = /^[0-9a-f]{64}\.json$/;
|
|
20
|
+
const RECORD_KEYS = 'name,target,targetKind,transferId,version';
|
|
21
|
+
function conflict(message) {
|
|
22
|
+
return new errors_js_1.SwarmDeployError(errors_js_1.ERRORS.LINK_CONFLICT, message);
|
|
23
|
+
}
|
|
24
|
+
function failure(message, cause = null) {
|
|
25
|
+
return new errors_js_1.SwarmDeployError(errors_js_1.ERRORS.LINK_FAILED, message, cause);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Maps every failure to a stable link error. The raw error, which may carry an
|
|
29
|
+
* errno or an absolute path, is kept only as the `cause`, never in the message.
|
|
30
|
+
*/
|
|
31
|
+
function asLinkError(error) {
|
|
32
|
+
if (error instanceof errors_js_1.SwarmDeployError &&
|
|
33
|
+
(error.code === errors_js_1.ERRORS.LINK_CONFLICT ||
|
|
34
|
+
error.code === errors_js_1.ERRORS.LINK_FAILED ||
|
|
35
|
+
error.code === errors_js_1.ERRORS.UNSUPPORTED_STORAGE)) {
|
|
36
|
+
return error;
|
|
37
|
+
}
|
|
38
|
+
return failure('Managed link operation failed', error);
|
|
39
|
+
}
|
|
40
|
+
/** A link or target name: one safe basename, never reserved, never the internal directory. */
|
|
41
|
+
function assertSafeName(value, message) {
|
|
42
|
+
if (typeof value !== 'string' ||
|
|
43
|
+
value.includes('/') ||
|
|
44
|
+
value.includes('\\') ||
|
|
45
|
+
value.includes('\u0000') ||
|
|
46
|
+
value === '.' ||
|
|
47
|
+
value === '..' ||
|
|
48
|
+
value === '.swarm-deploy') {
|
|
49
|
+
throw failure(message);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
(0, files_js_1.validateBasename)(value);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
throw failure(message, error);
|
|
56
|
+
}
|
|
57
|
+
if ((0, files_js_1.isReservedHistoryName)(value))
|
|
58
|
+
throw failure(message);
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
function assertRecord(value, expectedName) {
|
|
62
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
63
|
+
throw failure('Invalid managed link record');
|
|
64
|
+
}
|
|
65
|
+
const candidate = value;
|
|
66
|
+
if (Object.keys(candidate).sort().join(',') !== RECORD_KEYS ||
|
|
67
|
+
candidate.version !== 1 ||
|
|
68
|
+
candidate.name !== expectedName ||
|
|
69
|
+
(candidate.targetKind !== 'file' && candidate.targetKind !== 'directory') ||
|
|
70
|
+
typeof candidate.transferId !== 'string' ||
|
|
71
|
+
!/^[0-9a-f]{64}$/.test(candidate.transferId)) {
|
|
72
|
+
throw failure('Invalid managed link record');
|
|
73
|
+
}
|
|
74
|
+
assertSafeName(candidate.name, 'Invalid managed link record');
|
|
75
|
+
assertSafeName(candidate.target, 'Invalid managed link record');
|
|
76
|
+
return candidate;
|
|
77
|
+
}
|
|
78
|
+
function randomSuffix() {
|
|
79
|
+
const bytes = b4a_1.default.allocUnsafe(16);
|
|
80
|
+
sodium_native_1.default.randombytes_buf(bytes);
|
|
81
|
+
return b4a_1.default.toString(bytes, 'hex');
|
|
82
|
+
}
|
|
83
|
+
async function syncDirectory(directory, storage) {
|
|
84
|
+
const handle = await storage.open(directory, 'r');
|
|
85
|
+
try {
|
|
86
|
+
await handle.sync();
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
await handle.close();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Owns every server-managed symlink in the storage root.
|
|
94
|
+
*
|
|
95
|
+
* A destination is replaceable only when a valid ownership record exists, the
|
|
96
|
+
* visible destination is a symbolic link, and `readlink()` returns either the
|
|
97
|
+
* recorded target or the desired target. Anything else is unmanaged: it is left
|
|
98
|
+
* untouched and the operation fails closed. A link target is always exactly a
|
|
99
|
+
* sibling basename, and `readlink()` output is only ever compared, never used
|
|
100
|
+
* to build a path.
|
|
101
|
+
*/
|
|
102
|
+
class LinkStore {
|
|
103
|
+
layout;
|
|
104
|
+
storage;
|
|
105
|
+
constructor({ layout, storage = _fs_1.default.promises }) {
|
|
106
|
+
if (!layout || typeof layout !== 'object')
|
|
107
|
+
throw failure('Invalid storage layout');
|
|
108
|
+
(0, tree_fs_js_1.assertSymlinkCapable)(storage);
|
|
109
|
+
this.layout = layout;
|
|
110
|
+
this.storage = storage;
|
|
111
|
+
}
|
|
112
|
+
recordPath(name) {
|
|
113
|
+
return _path_1.default.join(this.layout.links, `${b4a_1.default.toString((0, hash_js_1.sodiumSha256)(b4a_1.default.from(name)), 'hex')}.json`);
|
|
114
|
+
}
|
|
115
|
+
finalPath(name) {
|
|
116
|
+
return _path_1.default.join(this.layout.root, name);
|
|
117
|
+
}
|
|
118
|
+
async read(name) {
|
|
119
|
+
try {
|
|
120
|
+
return await this.readRecord(assertSafeName(name, 'Invalid managed link name'));
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
throw asLinkError(error);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Every persisted ownership record, keyed by its proven link name. */
|
|
127
|
+
async list() {
|
|
128
|
+
try {
|
|
129
|
+
return await this.listRecords();
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw asLinkError(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async readRecord(name) {
|
|
136
|
+
try {
|
|
137
|
+
return assertRecord(await (0, atomic_file_js_1.readJson)(this.recordPath(name), this.storage, MAX_LINK_RECORD_BYTES), name);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if ((0, error_code_js_1.isMissing)(error))
|
|
141
|
+
return null;
|
|
142
|
+
if (error instanceof atomic_file_js_1.MetadataFormatError) {
|
|
143
|
+
throw failure('Malformed managed link record', error);
|
|
144
|
+
}
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async listRecords() {
|
|
149
|
+
const filenames = await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.links, this.storage, () => this.storage.readdir(this.layout.links));
|
|
150
|
+
const records = [];
|
|
151
|
+
for (const filename of filenames.sort()) {
|
|
152
|
+
if (!RECORD_FILENAME.test(filename))
|
|
153
|
+
continue;
|
|
154
|
+
let parsed;
|
|
155
|
+
try {
|
|
156
|
+
parsed = await (0, atomic_file_js_1.readJson)(_path_1.default.join(this.layout.links, filename), this.storage, MAX_LINK_RECORD_BYTES);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
throw failure('Malformed managed link record', error);
|
|
160
|
+
}
|
|
161
|
+
const record = assertRecord(parsed, typeof parsed.name === 'string' ? parsed.name : '');
|
|
162
|
+
if (_path_1.default.basename(this.recordPath(record.name)) !== filename) {
|
|
163
|
+
throw failure('Foreign managed link record');
|
|
164
|
+
}
|
|
165
|
+
records.push(record);
|
|
166
|
+
}
|
|
167
|
+
return records;
|
|
168
|
+
}
|
|
169
|
+
classify(name) {
|
|
170
|
+
const finalPath = this.finalPath(name);
|
|
171
|
+
return (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.root, this.storage, async () => {
|
|
172
|
+
let stat;
|
|
173
|
+
try {
|
|
174
|
+
stat = await this.storage.lstat(finalPath);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
if ((0, error_code_js_1.isMissing)(error))
|
|
178
|
+
return { state: 'MISSING' };
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
if (!stat.isSymbolicLink())
|
|
182
|
+
return { state: 'UNMANAGED' };
|
|
183
|
+
return { state: 'SYMLINK', target: await this.storage.readlink(finalPath) };
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
async writeRecord(link) {
|
|
187
|
+
const record = {
|
|
188
|
+
version: 1,
|
|
189
|
+
name: link.name,
|
|
190
|
+
target: link.target,
|
|
191
|
+
transferId: link.transferId,
|
|
192
|
+
targetKind: link.targetKind
|
|
193
|
+
};
|
|
194
|
+
assertRecord(record, link.name);
|
|
195
|
+
await (0, atomic_file_js_1.writeAtomic)(this.recordPath(link.name), b4a_1.default.from(JSON.stringify(record)), this.storage);
|
|
196
|
+
}
|
|
197
|
+
async removeRecord(name) {
|
|
198
|
+
await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.links, this.storage, async () => {
|
|
199
|
+
try {
|
|
200
|
+
await this.storage.unlink(this.recordPath(name));
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
if (!(0, error_code_js_1.isMissing)(error))
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.links, this.storage, () => syncDirectory(this.layout.links, this.storage));
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Creates a link where nothing exists. The ownership record is durable first,
|
|
211
|
+
* so a crash after the link appears never leaves an unrecorded link; the
|
|
212
|
+
* link itself is created without overwriting, so a path that appeared since
|
|
213
|
+
* classification is never replaced and its record is withdrawn.
|
|
214
|
+
*/
|
|
215
|
+
async createLink(link) {
|
|
216
|
+
await this.writeRecord(link);
|
|
217
|
+
try {
|
|
218
|
+
await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.root, this.storage, () => this.storage.symlink(link.target, this.finalPath(link.name)));
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
await this.removeRecord(link.name).catch(() => { });
|
|
222
|
+
if ((0, error_code_js_1.errorCode)(error) === 'EEXIST') {
|
|
223
|
+
throw conflict('Unmanaged path at a configured managed link name');
|
|
224
|
+
}
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.root, this.storage, () => syncDirectory(this.layout.root, this.storage));
|
|
228
|
+
}
|
|
229
|
+
/** Removes a temporary symlink with `lstat`/`unlink`, never a regular-file helper. */
|
|
230
|
+
async removeTemporary(temporary) {
|
|
231
|
+
await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.publications, this.storage, async () => {
|
|
232
|
+
try {
|
|
233
|
+
await this.storage.lstat(temporary);
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
if ((0, error_code_js_1.isMissing)(error))
|
|
237
|
+
return;
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
await this.storage.unlink(temporary);
|
|
241
|
+
}).catch(() => { });
|
|
242
|
+
}
|
|
243
|
+
/** Atomically swaps an owned link by renaming a private temporary link over it. */
|
|
244
|
+
async replaceLink(link) {
|
|
245
|
+
const temporary = _path_1.default.join(this.layout.publications, `.link-${randomSuffix()}`);
|
|
246
|
+
try {
|
|
247
|
+
await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.publications, this.storage, () => this.storage.symlink(link.target, temporary));
|
|
248
|
+
await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.publications, this.storage, () => syncDirectory(this.layout.publications, this.storage));
|
|
249
|
+
await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.root, this.storage, () => (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.publications, this.storage, () => this.storage.rename(temporary, this.finalPath(link.name))));
|
|
250
|
+
await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.root, this.storage, () => syncDirectory(this.layout.root, this.storage));
|
|
251
|
+
await this.writeRecord(link);
|
|
252
|
+
}
|
|
253
|
+
finally {
|
|
254
|
+
await this.removeTemporary(temporary);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
async removeLink(record, desiredTarget) {
|
|
258
|
+
const destination = await this.classify(record.name);
|
|
259
|
+
const allowed = new Set([record.target]);
|
|
260
|
+
if (desiredTarget)
|
|
261
|
+
allowed.add(desiredTarget);
|
|
262
|
+
if (destination.state === 'SYMLINK' && allowed.has(destination.target)) {
|
|
263
|
+
await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.root, this.storage, () => this.storage.unlink(this.finalPath(record.name)));
|
|
264
|
+
await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.root, this.storage, () => syncDirectory(this.layout.root, this.storage));
|
|
265
|
+
}
|
|
266
|
+
else if (destination.state !== 'MISSING') {
|
|
267
|
+
throw conflict('Unmanaged path at a removed managed link name');
|
|
268
|
+
}
|
|
269
|
+
await this.removeRecord(record.name);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Converges every desired link and removes the record and visible link of
|
|
273
|
+
* every name no rule owns. Level-triggered: the same input always produces
|
|
274
|
+
* the same output, whatever the previous attempt's crash point.
|
|
275
|
+
*/
|
|
276
|
+
async reconcile(desired, ruleNames, options = {}) {
|
|
277
|
+
try {
|
|
278
|
+
return await this.converge(desired, ruleNames, options);
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
throw asLinkError(error);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
async sweepTemporaryLinks() {
|
|
285
|
+
const names = await (0, layout_js_1.withSafeDirectoryIdentity)(this.layout.publications, this.storage, () => this.storage.readdir(this.layout.publications));
|
|
286
|
+
for (const name of names) {
|
|
287
|
+
if (!/^\.link-[0-9a-f]{32}$/.test(name))
|
|
288
|
+
continue;
|
|
289
|
+
await this.removeTemporary(_path_1.default.join(this.layout.publications, name));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
async converge(desired, ruleNames, { managedArtifactNames } = {}) {
|
|
293
|
+
await this.sweepTemporaryLinks();
|
|
294
|
+
const result = { created: [], updated: [], removed: [], unchanged: [] };
|
|
295
|
+
const desiredByName = new Map(desired.map((link) => [link.name, link]));
|
|
296
|
+
for (const record of await this.listRecords()) {
|
|
297
|
+
if (ruleNames.has(record.name)) {
|
|
298
|
+
if (!desiredByName.has(record.name)) {
|
|
299
|
+
const destination = await this.classify(record.name);
|
|
300
|
+
const desiredTarget = destination.state === 'SYMLINK' && destination.target !== record.target
|
|
301
|
+
? destination.target
|
|
302
|
+
: undefined;
|
|
303
|
+
await this.removeLink(record, desiredTarget);
|
|
304
|
+
result.removed.push(record.name);
|
|
305
|
+
}
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const destination = await this.classify(record.name);
|
|
309
|
+
let desiredTarget;
|
|
310
|
+
if (destination.state === 'SYMLINK' && destination.target !== record.target) {
|
|
311
|
+
const pending = desiredByName.get(record.name);
|
|
312
|
+
if (pending)
|
|
313
|
+
desiredTarget = pending.target;
|
|
314
|
+
else if (managedArtifactNames?.has(destination.target)) {
|
|
315
|
+
desiredTarget = destination.target;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
await this.removeLink(record, desiredTarget);
|
|
319
|
+
result.removed.push(record.name);
|
|
320
|
+
}
|
|
321
|
+
for (const link of desired) {
|
|
322
|
+
if (!ruleNames.has(link.name))
|
|
323
|
+
throw failure('Desired link is not a configured rule');
|
|
324
|
+
assertSafeName(link.name, 'Invalid managed link name');
|
|
325
|
+
assertSafeName(link.target, 'Invalid managed link target');
|
|
326
|
+
if (link.target === link.name)
|
|
327
|
+
throw failure('Managed link cannot target itself');
|
|
328
|
+
const record = await this.readRecord(link.name);
|
|
329
|
+
const destination = await this.classify(link.name);
|
|
330
|
+
if (destination.state === 'UNMANAGED') {
|
|
331
|
+
throw conflict('Unmanaged path at a configured managed link name');
|
|
332
|
+
}
|
|
333
|
+
if (destination.state === 'MISSING') {
|
|
334
|
+
await this.createLink(link);
|
|
335
|
+
result.created.push(link.name);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (record === null)
|
|
339
|
+
throw conflict('Unrecorded symlink at a configured managed link name');
|
|
340
|
+
// Ownership proof: a record exists and the visible link is either the
|
|
341
|
+
// recorded target or the desired one (a crash after the visible swap).
|
|
342
|
+
if (destination.target !== record.target && destination.target !== link.target) {
|
|
343
|
+
throw conflict('Managed link does not match its ownership record');
|
|
344
|
+
}
|
|
345
|
+
if (destination.target === link.target) {
|
|
346
|
+
if (record.target === link.target &&
|
|
347
|
+
record.transferId === link.transferId &&
|
|
348
|
+
record.targetKind === link.targetKind) {
|
|
349
|
+
result.unchanged.push(link.name);
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
await this.writeRecord(link);
|
|
353
|
+
result.updated.push(link.name);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
await this.replaceLink(link);
|
|
357
|
+
result.updated.push(link.name);
|
|
358
|
+
}
|
|
359
|
+
return result;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
exports.LinkStore = LinkStore;
|
|
363
|
+
//# sourceMappingURL=link-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link-store.js","sourceRoot":"","sources":["../../src/storage/link-store.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAqB;AACrB,oDAAuD;AACvD,8CAAoB;AACpB,kDAAwB;AACxB,kEAAkC;AAClC,4CAAuD;AACvD,0CAAqE;AACrE,qDAAsD;AAGtD,qDAA6E;AAC7E,2CAAuD;AACvD,6CAAmD;AAGnD,MAAM,qBAAqB,GAAG,CAAC,GAAG,IAAI,CAAA;AACtC,MAAM,eAAe,GAAG,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IAAI,WAAW,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;gBACvC,IACE,MAAM,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;oBAC7B,MAAM,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU;oBACrC,MAAM,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,EACrC,CAAC;oBACD,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;oBAChC,SAAQ;gBACV,CAAC;gBACD,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;gBAC5B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBAC9B,SAAQ;YACV,CAAC;YACD,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;YAC5B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAChC,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
|
@@ -50,6 +50,7 @@ interface CommitStore {
|
|
|
50
50
|
purged: true;
|
|
51
51
|
preservedPath: boolean;
|
|
52
52
|
}>;
|
|
53
|
+
sweepTrash(): Promise<number>;
|
|
53
54
|
}
|
|
54
55
|
type RecoveryEvent = {
|
|
55
56
|
type: 'recovery';
|
|
@@ -70,7 +71,7 @@ type RecoveryEvent = {
|
|
|
70
71
|
type: 'cleanup';
|
|
71
72
|
transfer: string;
|
|
72
73
|
name: null;
|
|
73
|
-
reason: 'corrupt-journal';
|
|
74
|
+
reason: 'corrupt-journal' | 'trash-residue';
|
|
74
75
|
} | {
|
|
75
76
|
type: 'scrub';
|
|
76
77
|
status: 'started';
|
package/dist/storage/recovery.js
CHANGED
|
@@ -55,7 +55,9 @@ async function assertRecoveryLayout(layout, storage) {
|
|
|
55
55
|
layout.staging,
|
|
56
56
|
layout.sessions,
|
|
57
57
|
layout.commits,
|
|
58
|
-
layout.journals
|
|
58
|
+
layout.journals,
|
|
59
|
+
layout.links,
|
|
60
|
+
layout.trash
|
|
59
61
|
]) {
|
|
60
62
|
await (0, layout_js_1.assertSafeDirectory)(directory, storage);
|
|
61
63
|
}
|
|
@@ -222,6 +224,11 @@ async function recoverStorage({ layout, sessionStore, commitStore, logger = null
|
|
|
222
224
|
await sessionStore.delete(b4a_1.default.from(id, 'hex'));
|
|
223
225
|
}
|
|
224
226
|
}
|
|
227
|
+
const sweptTrash = await commitStore.sweepTrash();
|
|
228
|
+
if (sweptTrash > 0) {
|
|
229
|
+
report(logger, 'warn', 'Swept managed directory trash residue', { trees: sweptTrash });
|
|
230
|
+
emit(onEvent, { type: 'cleanup', transfer: 'trash', name: null, reason: 'trash-residue' });
|
|
231
|
+
}
|
|
225
232
|
const retention = new retention_js_1.RetentionManager({
|
|
226
233
|
layout,
|
|
227
234
|
sessionStore,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery.js","sourceRoot":"","sources":["../../src/storage/recovery.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"recovery.js","sourceRoot":"","sources":["../../src/storage/recovery.ts"],"names":[],"mappings":";;;;;QAwWS,sBAAsB;QAAE,cAAc;AAxW/C,8CAAqB;AACrB,8CAAoB;AACpB,4CAAuD;AACvD,qDAAsD;AACtD,2CAA4E;AAC5E,uDAAuD;AACvD,iDAAiD;AAwFjD,SAAS,YAAY,CAAC,OAAe,EAAE,KAAK,GAAmB,IAAI;IACjE,OAAO,IAAI,4BAAgB,CAAC,kBAAM,CAAC,gBAAgB,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;AACtE,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACtE,CAAC;AAED,SAAS,mBAAmB,CAAC,EAAU;IACrC,OAAO,aAAG,CAAC,QAAQ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AK,CAAC,OAAO,CAAC,MAAM;SACnC,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,OAAO,EAAE;YACZ,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC;SAC3B,CAAC,CAAA;QACF,MAAM,GAAG,CAAA;IACX,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type VersionGranularity } from '../release.js';
|
|
2
|
+
import { type CommitRecord } from './commit-journal.js';
|
|
2
3
|
import type { StorageAdapter, StorageLayout } from './types.js';
|
|
3
4
|
declare const DEFAULT_RESUME_TTL: number;
|
|
4
5
|
declare const DEFAULT_CLEANUP_INTERVAL: number;
|
|
@@ -44,6 +45,8 @@ type RetentionEvent = {
|
|
|
44
45
|
expiredSessions: number;
|
|
45
46
|
scrubbed: number;
|
|
46
47
|
ageDeleted: number;
|
|
48
|
+
countDeleted: number;
|
|
49
|
+
versionDeleted: number;
|
|
47
50
|
storageDeleted: number;
|
|
48
51
|
} | {
|
|
49
52
|
type: 'retention';
|
|
@@ -62,6 +65,8 @@ type RetentionEventPayload = {
|
|
|
62
65
|
expiredSessions: number;
|
|
63
66
|
scrubbed: number;
|
|
64
67
|
ageDeleted: number;
|
|
68
|
+
countDeleted: number;
|
|
69
|
+
versionDeleted: number;
|
|
65
70
|
storageDeleted: number;
|
|
66
71
|
} | {
|
|
67
72
|
trigger: string;
|
|
@@ -81,6 +86,9 @@ interface RetentionManagerOptions {
|
|
|
81
86
|
sessionStore: SessionStore;
|
|
82
87
|
commitStore: CommitStore;
|
|
83
88
|
maxAge?: number;
|
|
89
|
+
maxCount?: number;
|
|
90
|
+
maxVersions?: number;
|
|
91
|
+
versionGranularity?: VersionGranularity;
|
|
84
92
|
maxStorageBytes?: number;
|
|
85
93
|
resumeTtl?: number;
|
|
86
94
|
cleanupInterval?: number;
|
|
@@ -89,15 +97,39 @@ interface RetentionManagerOptions {
|
|
|
89
97
|
isSessionActive: (session: Session) => boolean;
|
|
90
98
|
hasActiveUploads?: () => boolean;
|
|
91
99
|
isPinned?: (record: CommitRecord) => boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Reconciles managed symlinks and returns the transfer IDs pinned by a rule.
|
|
102
|
+
* Called once per pass with the scrubbed record set, with the root lease
|
|
103
|
+
* already held; it must not acquire the root lease itself.
|
|
104
|
+
*/
|
|
105
|
+
reconcileLinks?: (records: CommitRecord[]) => Promise<ReadonlySet<string>>;
|
|
106
|
+
/**
|
|
107
|
+
* When link reconciliation fails, returns transfer IDs that must stay pinned
|
|
108
|
+
* from desired links and durable ownership records.
|
|
109
|
+
*/
|
|
110
|
+
linkPinsFallback?: (records: CommitRecord[]) => Promise<ReadonlySet<string>>;
|
|
111
|
+
/** Names in the storage root that are server-managed symlinks, not artifacts. */
|
|
112
|
+
managedLinkNames?: () => ReadonlySet<string>;
|
|
92
113
|
logger?: Logger | null;
|
|
93
114
|
scheduler?: Scheduler;
|
|
94
115
|
onEvent?: ((event: RetentionEvent) => void) | null;
|
|
95
116
|
}
|
|
117
|
+
interface RetentionResult {
|
|
118
|
+
expiredSessions: number;
|
|
119
|
+
scrubbed: number;
|
|
120
|
+
ageDeleted: number;
|
|
121
|
+
countDeleted: number;
|
|
122
|
+
versionDeleted: number;
|
|
123
|
+
storageDeleted: number;
|
|
124
|
+
}
|
|
96
125
|
declare class RetentionManager {
|
|
97
126
|
layout: StorageLayout;
|
|
98
127
|
sessionStore: SessionStore;
|
|
99
128
|
commitStore: CommitStore;
|
|
100
129
|
maxAge: number | undefined;
|
|
130
|
+
maxCount: number | undefined;
|
|
131
|
+
maxVersions: number | undefined;
|
|
132
|
+
versionGranularity: VersionGranularity | undefined;
|
|
101
133
|
maxStorageBytes: number | undefined;
|
|
102
134
|
resumeTtl: number;
|
|
103
135
|
cleanupInterval: number;
|
|
@@ -106,6 +138,9 @@ declare class RetentionManager {
|
|
|
106
138
|
isSessionActive: (session: Session) => boolean;
|
|
107
139
|
hasActiveUploads: () => boolean;
|
|
108
140
|
isPinned: (record: CommitRecord) => boolean;
|
|
141
|
+
reconcileLinks: ((records: CommitRecord[]) => Promise<ReadonlySet<string>>) | undefined;
|
|
142
|
+
linkPinsFallback: ((records: CommitRecord[]) => Promise<ReadonlySet<string>>) | undefined;
|
|
143
|
+
managedLinkNames: (() => ReadonlySet<string>) | undefined;
|
|
109
144
|
logger: Logger | null;
|
|
110
145
|
timer: unknown | null;
|
|
111
146
|
cleanupFailure: unknown | null;
|
|
@@ -115,7 +150,7 @@ declare class RetentionManager {
|
|
|
115
150
|
tickPromise: Promise<void> | null;
|
|
116
151
|
tickQueued: boolean;
|
|
117
152
|
lifecycle: number;
|
|
118
|
-
constructor({ layout, sessionStore, commitStore, maxAge, maxStorageBytes, resumeTtl, cleanupInterval, clock, storage, isSessionActive, hasActiveUploads, isPinned, logger, scheduler, onEvent }: RetentionManagerOptions);
|
|
153
|
+
constructor({ layout, sessionStore, commitStore, maxAge, maxCount, maxVersions, versionGranularity, maxStorageBytes, resumeTtl, cleanupInterval, clock, storage, isSessionActive, hasActiveUploads, isPinned, reconcileLinks, linkPinsFallback, managedLinkNames, logger, scheduler, onEvent }: RetentionManagerOptions);
|
|
119
154
|
_emit(payload: RetentionEventPayload): void;
|
|
120
155
|
_hasActiveReceivingUpload(): boolean;
|
|
121
156
|
expireSessions(): Promise<number>;
|
|
@@ -126,7 +161,7 @@ declare class RetentionManager {
|
|
|
126
161
|
deleted: number;
|
|
127
162
|
unknown: string[];
|
|
128
163
|
}>;
|
|
129
|
-
_deleteRecord(record: CommitRecord, reason: 'MAX_AGE' | 'MAX_STORAGE'): Promise<void>;
|
|
164
|
+
_deleteRecord(record: CommitRecord, reason: 'MAX_AGE' | 'MAX_COUNT' | 'MAX_VERSIONS' | 'MAX_STORAGE'): Promise<void>;
|
|
130
165
|
/**
|
|
131
166
|
* Configured mutable current records survive age and quota eviction. Their
|
|
132
167
|
* size still counts toward the logical total so a replacement that cannot be
|
|
@@ -134,24 +169,9 @@ declare class RetentionManager {
|
|
|
134
169
|
*/
|
|
135
170
|
_isPinned(record: CommitRecord): boolean;
|
|
136
171
|
_totalSize(records: CommitRecord[]): number;
|
|
137
|
-
run(options?: RetentionRunOptions): Promise<
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
ageDeleted: number;
|
|
141
|
-
storageDeleted: number;
|
|
142
|
-
}>;
|
|
143
|
-
_runUnlocked(options?: RetentionRunOptions): Promise<{
|
|
144
|
-
expiredSessions: number;
|
|
145
|
-
scrubbed: number;
|
|
146
|
-
ageDeleted: number;
|
|
147
|
-
storageDeleted: number;
|
|
148
|
-
}>;
|
|
149
|
-
_run({ incomingBytes }?: RetentionRunOptions): Promise<{
|
|
150
|
-
expiredSessions: number;
|
|
151
|
-
scrubbed: number;
|
|
152
|
-
ageDeleted: number;
|
|
153
|
-
storageDeleted: number;
|
|
154
|
-
}>;
|
|
172
|
+
run(options?: RetentionRunOptions): Promise<RetentionResult>;
|
|
173
|
+
_runUnlocked(options?: RetentionRunOptions): Promise<RetentionResult>;
|
|
174
|
+
_run({ incomingBytes, trigger }?: RetentionRunOptions): Promise<RetentionResult>;
|
|
155
175
|
afterCommit(): Promise<boolean>;
|
|
156
176
|
_afterCommitUnlocked(): Promise<boolean>;
|
|
157
177
|
start(): Promise<void>;
|