dsh-config-manager 0.2.4 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/lib/adapters/self.d.ts +44 -4
- package/lib/adapters/self.js +63 -3
- package/lib/client.d.ts +11 -6
- package/lib/client.js +1254 -1183
- package/lib/core/analyzer.d.ts +3 -0
- package/lib/core/analyzer.js +32 -56
- package/lib/core/backup.d.ts +36 -0
- package/lib/core/backup.js +125 -3
- package/lib/core/import-defaults.d.ts +13 -0
- package/lib/core/import-defaults.js +14 -0
- package/lib/core/importer.d.ts +10 -1
- package/lib/core/importer.js +7 -1
- package/lib/core/messages.d.ts +4 -0
- package/lib/core/messages.js +8 -0
- package/lib/core/model-tools.js +19 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +12 -22
- package/lib/routes/import.js +3 -1
- package/lib/routes/recovery.js +226 -2
- package/lib/routes/sync.js +26 -7
- package/lib/security/integrity.d.ts +24 -0
- package/lib/security/integrity.js +30 -0
- package/lib/security/unverified-file-blocks.d.ts +73 -0
- package/lib/security/unverified-file-blocks.js +151 -0
- package/lib/sync/autosync-config.d.ts +8 -4
- package/lib/sync/autosync-config.js +2 -2
- package/lib/sync/autosync-scheduler.d.ts +61 -3
- package/lib/sync/autosync-scheduler.js +87 -10
- package/lib/sync/config-issue-reporting.d.ts +32 -0
- package/lib/sync/config-issue-reporting.js +63 -0
- package/lib/sync/gc-skip.d.ts +42 -0
- package/lib/sync/gc-skip.js +57 -0
- package/lib/sync/git/git-transport.d.ts +10 -0
- package/lib/sync/git/git-transport.js +72 -14
- package/lib/sync/merge-preview-text.d.ts +11 -0
- package/lib/sync/merge-preview-text.js +38 -0
- package/lib/sync/s3/oss4-verify.js +21 -6
- package/lib/sync/s3/s3-providers.d.ts +13 -0
- package/lib/sync/s3/s3-providers.js +6 -0
- package/lib/sync/s3/s3-transport.d.ts +30 -1
- package/lib/sync/s3/s3-transport.js +108 -23
- package/lib/sync/session-tombstones.d.ts +53 -0
- package/lib/sync/session-tombstones.js +52 -0
- package/lib/sync/sync-config.d.ts +55 -5
- package/lib/sync/sync-config.js +188 -15
- package/lib/sync/sync-engine.d.ts +21 -7
- package/lib/sync/sync-engine.js +63 -85
- package/lib/sync/webdav/webdav-transport.d.ts +11 -1
- package/lib/sync/webdav/webdav-transport.js +22 -6
- package/lib/ui/i18n.js +56 -36
- package/lib/ui/import-wizard.d.ts +1 -1
- package/lib/ui/import-wizard.js +2 -1
- package/lib/ui/overview-view.d.ts +6 -2
- package/lib/ui/overview-view.js +8 -1
- package/lib/ui/report.js +2 -1
- package/package.json +2 -2
- package/src/adapters/self.test.ts +126 -85
- package/src/adapters/self.ts +73 -6
- package/src/client/ConfigManagerSection.tsx +0 -3
- package/src/client/common/Icon.tsx +3 -0
- package/src/client/common/SectionComposition.tsx +6 -1
- package/src/client/common/info-hint-guard.test.ts +7 -5
- package/src/client/config-manager.module.css +254 -13
- package/src/client/environment/EnvironmentPanel.tsx +57 -47
- package/src/client/environment/maintenance/DiskUsageCard.tsx +3 -1
- package/src/client/export/ExportView.tsx +3 -1
- package/src/client/home/HomePanel.tsx +25 -5
- package/src/client/import/ImportWizardView.tsx +1 -3
- package/src/client/import/import-wizard-steps.tsx +1 -17
- package/src/client/library/ArtifactRow.tsx +13 -2
- package/src/client/library/LibraryPanel.tsx +12 -2
- package/src/client/locales.ts +53 -34
- package/src/client/lucide-icons.d.ts +2 -0
- package/src/client/market/MarketPanel.tsx +12 -11
- package/src/client/market/market-locales.ts +16 -16
- package/src/client/recovery/RollbackCard.tsx +4 -2
- package/src/client/recovery/recovery-locales.test.ts +4 -2
- package/src/client/recovery/recovery-locales.ts +23 -23
- package/src/client/sync/AutosyncCard.tsx +36 -10
- package/src/client/sync/SyncChannelEntryCard.tsx +18 -19
- package/src/client/sync/SyncPanel.tsx +32 -33
- package/src/client/sync/SyncProbeRow.tsx +23 -6
- package/src/client/sync/SyncSectionPickerDialog.tsx +2 -2
- package/src/client/sync/sync-locales.ts +24 -24
- package/src/core/analyzer.ts +37 -56
- package/src/core/backup.test.ts +139 -1
- package/src/core/backup.ts +145 -4
- package/src/core/import-defaults.ts +13 -0
- package/src/core/importer.ts +12 -2
- package/src/core/integrity-extra-entries.test.ts +205 -0
- package/src/core/messages.test.ts +3 -1
- package/src/core/messages.ts +8 -0
- package/src/core/model-tools.test.ts +33 -0
- package/src/core/model-tools.ts +20 -4
- package/src/index.ts +12 -21
- package/src/routes/import.ts +4 -1
- package/src/routes/recovery.test.ts +198 -1
- package/src/routes/recovery.ts +194 -1
- package/src/routes/sync.ts +27 -8
- package/src/security/integrity.ts +37 -0
- package/src/security/unverified-file-blocks.ts +192 -0
- package/src/sync/autosync-config.ts +9 -5
- package/src/sync/autosync-scheduler.test.ts +133 -6
- package/src/sync/autosync-scheduler.ts +118 -14
- package/src/sync/config-issue-reporting.test.ts +148 -0
- package/src/sync/config-issue-reporting.ts +75 -0
- package/src/sync/gc-skip.test.ts +66 -0
- package/src/sync/gc-skip.ts +64 -0
- package/src/sync/git/git-probe.test.ts +3 -2
- package/src/sync/git/git-transport.test.ts +168 -7
- package/src/sync/git/git-transport.ts +70 -14
- package/src/sync/merge-preview-text.ts +37 -0
- package/src/sync/s3/oss4-verify.ts +22 -6
- package/src/sync/s3/s3-conditional-write.test.ts +153 -3
- package/src/sync/s3/s3-delete-index-404.test.ts +26 -1
- package/src/sync/s3/s3-providers.ts +20 -0
- package/src/sync/s3/s3-transport.oss4-server.test.ts +48 -0
- package/src/sync/s3/s3-transport.ts +121 -21
- package/src/sync/session-tombstones.ts +90 -0
- package/src/sync/sync-config.test.ts +170 -1
- package/src/sync/sync-config.ts +184 -14
- package/src/sync/sync-engine.test.ts +238 -0
- package/src/sync/sync-engine.ts +79 -83
- package/src/sync/webdav/webdav-delete-index-404.test.ts +29 -1
- package/src/sync/webdav/webdav-transport.ts +26 -5
- package/src/ui/disk-usage-view.test.ts +2 -1
- package/src/ui/i18n.test.ts +47 -0
- package/src/ui/i18n.ts +58 -38
- package/src/ui/import-wizard.test.ts +18 -1
- package/src/ui/import-wizard.ts +3 -2
- package/src/ui/overview-view.test.ts +9 -0
- package/src/ui/overview-view.ts +9 -2
- package/src/ui/report.test.ts +4 -3
- package/src/ui/report.ts +2 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* S3 兼容系通道:本轮借鉴项的**针对性**单测(不重复 s3-transport.test.ts 的既有契约)。
|
|
3
|
-
* - ①
|
|
4
|
-
* 索引 PUT 412 → conflict;409
|
|
5
|
-
* 409 **不带条件头** →
|
|
3
|
+
* - ① 条件写(etag 方言):索引 ETag → if-match;索引缺失且远端无内容 → if-none-match: *;
|
|
4
|
+
* 索引 PUT 412 → conflict;409 **带条件头且报文是 FileAlreadyExists** → conflict;
|
|
5
|
+
* 409 **不带条件头** → 绝不走并发写冲突那条路径;
|
|
6
|
+
* - ①-b 阿里云 OSS(forbid-overwrite 方言):不发任何 If-*;首推 → x-oss-forbid-overwrite: true;
|
|
7
|
+
* 索引已有 ETag → 写前 HEAD 复核;409 报文是 FileImmutable → 如实报错,不冒充并发写;
|
|
6
8
|
* - ② 探针:HEAD 回 301/307/308 + x-amz-bucket-region → 抛错且文案里带可执行的 region;
|
|
7
9
|
* 404 / 403 各自文案;HEAD 200 时读索引回报快照数。
|
|
8
10
|
*/
|
|
@@ -234,6 +236,154 @@ test('条件写①(删除路径):delete 读 index 拿 ETag → 写回剩
|
|
|
234
236
|
);
|
|
235
237
|
});
|
|
236
238
|
|
|
239
|
+
/* ---------------- ①-b 阿里云 OSS:没有 If-*,只有 x-oss-forbid-overwrite(issue #109 第二层) ---------------- */
|
|
240
|
+
|
|
241
|
+
const OSS_ENDPOINT = 'https://oss-cn-hangzhou.aliyuncs.com';
|
|
242
|
+
const OSS_INDEX_URL = 'https://' + BUCKET + '.oss-cn-hangzhou.aliyuncs.com/' + PREFIX + '/index.json';
|
|
243
|
+
const OSS_SNAPSHOT_URL = 'https://' + BUCKET + '.oss-cn-hangzhou.aliyuncs.com/' + PREFIX + '/snap-001.json';
|
|
244
|
+
const OSS_BLOBS_INDEX_URL = 'https://' + BUCKET + '.oss-cn-hangzhou.aliyuncs.com/' + PREFIX + '/blobs-index.json';
|
|
245
|
+
|
|
246
|
+
/** OSS 变体选项:虚拟主机风格(现场配置),region 必填,provider=oss。 */
|
|
247
|
+
function ossOptions(request: S3RequestFn): S3TransportOptions {
|
|
248
|
+
return makeOptions(request, { provider: 'oss', endpoint: OSS_ENDPOINT, region: 'cn-hangzhou', pathStyle: false });
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
test('条件写①-b(OSS):首推发 x-oss-forbid-overwrite,绝不发 if-none-match(真机回 0017-00000245)', async () => {
|
|
252
|
+
const calls: S3Call[] = [];
|
|
253
|
+
const t = new S3Transport(ossOptions(record(calls, (m) => {
|
|
254
|
+
if (m.method === 'GET' && m.url === OSS_INDEX_URL) return res(404, '');
|
|
255
|
+
if (m.method === 'GET' && m.url === OSS_BLOBS_INDEX_URL) return res(404, '');
|
|
256
|
+
if (m.method === 'PUT' && m.url === OSS_SNAPSHOT_URL) return res(200, '');
|
|
257
|
+
if (m.method === 'PUT' && m.url === OSS_INDEX_URL) return res(200, '');
|
|
258
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
259
|
+
})));
|
|
260
|
+
|
|
261
|
+
await t.upload(sampleSnapshot());
|
|
262
|
+
|
|
263
|
+
const put = calls.filter((c) => c.method === 'PUT' && c.url === OSS_INDEX_URL)[0]!;
|
|
264
|
+
assert.equal(put.headers['x-oss-forbid-overwrite'], 'true', 'OSS 的「禁止覆盖」只能这么表达');
|
|
265
|
+
assert.equal(put.headers['if-none-match'], undefined, 'If-None-Match 会被 OSS 判成未实现的功能');
|
|
266
|
+
assert.equal(put.headers['if-match'], undefined);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test('条件写①-b(OSS):索引已有 ETag → 不发 if-match,改在写前 HEAD 复核 ETag', async () => {
|
|
270
|
+
const calls: S3Call[] = [];
|
|
271
|
+
const t = new S3Transport(ossOptions(record(calls, (m) => {
|
|
272
|
+
if (m.method === 'GET' && m.url === OSS_INDEX_URL) return res(200, '[]', { etag: '"v1-oss"' });
|
|
273
|
+
if (m.method === 'PUT' && m.url === OSS_SNAPSHOT_URL) return res(200, '');
|
|
274
|
+
if (m.method === 'HEAD' && m.url === OSS_INDEX_URL) return res(200, '', { etag: '"v1-oss"' });
|
|
275
|
+
if (m.method === 'PUT' && m.url === OSS_INDEX_URL) return res(200, '');
|
|
276
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
277
|
+
})));
|
|
278
|
+
|
|
279
|
+
await t.upload(sampleSnapshot());
|
|
280
|
+
|
|
281
|
+
const headAt = calls.findIndex((c) => c.method === 'HEAD' && c.url === OSS_INDEX_URL);
|
|
282
|
+
const putAt = calls.findIndex((c) => c.method === 'PUT' && c.url === OSS_INDEX_URL);
|
|
283
|
+
assert.ok(headAt >= 0, '写前必须复核一次 ETag');
|
|
284
|
+
assert.ok(headAt < putAt, '复核必须在索引 PUT 之前');
|
|
285
|
+
const put = calls[putAt]!;
|
|
286
|
+
assert.equal(put.headers['if-match'], undefined, 'OSS PutObject 不支持 If-Match');
|
|
287
|
+
assert.equal(put.headers['x-oss-forbid-overwrite'], undefined, '索引已存在时不能用「禁止覆盖」(会被自己挡住)');
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test('条件写①-b(OSS):写前复核发现 ETag 变了 → 判并发写并中止(索引零写入)', async () => {
|
|
291
|
+
const calls: S3Call[] = [];
|
|
292
|
+
const t = new S3Transport(ossOptions(record(calls, (m) => {
|
|
293
|
+
if (m.method === 'GET' && m.url === OSS_INDEX_URL) return res(200, '[]', { etag: '"v1-oss"' });
|
|
294
|
+
if (m.method === 'PUT' && m.url === OSS_SNAPSHOT_URL) return res(200, '');
|
|
295
|
+
if (m.method === 'HEAD' && m.url === OSS_INDEX_URL) return res(200, '', { etag: '"v2-oss"' });
|
|
296
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
297
|
+
})));
|
|
298
|
+
|
|
299
|
+
await assert.rejects(
|
|
300
|
+
() => t.upload(sampleSnapshot()),
|
|
301
|
+
(err: unknown) => {
|
|
302
|
+
assert.ok(err instanceof S3TransportError);
|
|
303
|
+
assert.equal(err.kind, 'conflict');
|
|
304
|
+
assert.equal(err.retryable, false);
|
|
305
|
+
assert.equal(err.message, s3Msg('sync.s3.concurrentWrite', { status: '409', url: OSS_INDEX_URL }));
|
|
306
|
+
return true;
|
|
307
|
+
},
|
|
308
|
+
);
|
|
309
|
+
assert.equal(calls.filter((c) => c.method === 'PUT' && c.url === OSS_INDEX_URL).length, 0, '复核不过 ⇒ 索引零写入');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test('条件写①-b(OSS):索引 PUT 回 409(FileAlreadyExists)→ 仍判并发写冲突', async () => {
|
|
313
|
+
const calls: S3Call[] = [];
|
|
314
|
+
const t = new S3Transport(ossOptions(record(calls, (m) => {
|
|
315
|
+
if (m.method === 'GET' && m.url === OSS_INDEX_URL) return res(404, '');
|
|
316
|
+
if (m.method === 'GET' && m.url === OSS_BLOBS_INDEX_URL) return res(404, '');
|
|
317
|
+
if (m.method === 'PUT' && m.url === OSS_SNAPSHOT_URL) return res(200, '');
|
|
318
|
+
if (m.method === 'PUT' && m.url === OSS_INDEX_URL) return res(409, '<Error><Code>FileAlreadyExists</Code></Error>');
|
|
319
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
320
|
+
})));
|
|
321
|
+
|
|
322
|
+
await assert.rejects(
|
|
323
|
+
() => t.upload(sampleSnapshot()),
|
|
324
|
+
(err: unknown) => {
|
|
325
|
+
assert.ok(err instanceof S3TransportError);
|
|
326
|
+
assert.equal(err.kind, 'conflict');
|
|
327
|
+
assert.equal(err.status, 409);
|
|
328
|
+
return true;
|
|
329
|
+
},
|
|
330
|
+
);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('条件写①-b(OSS):索引 PUT 回 409 FileImmutable(桶数据被保护)→ 不冒充并发写,如实带报文', async () => {
|
|
334
|
+
const immutable = '<Error><Code>FileImmutable</Code><Message>The bucket is protected.</Message></Error>';
|
|
335
|
+
const t = new S3Transport(ossOptions(record([], (m) => {
|
|
336
|
+
if (m.method === 'GET' && m.url === OSS_INDEX_URL) return res(404, '');
|
|
337
|
+
if (m.method === 'GET' && m.url === OSS_BLOBS_INDEX_URL) return res(404, '');
|
|
338
|
+
if (m.method === 'PUT' && m.url === OSS_SNAPSHOT_URL) return res(200, '');
|
|
339
|
+
if (m.method === 'PUT' && m.url === OSS_INDEX_URL) return res(409, immutable);
|
|
340
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
341
|
+
})));
|
|
342
|
+
|
|
343
|
+
await assert.rejects(
|
|
344
|
+
() => t.upload(sampleSnapshot()),
|
|
345
|
+
(err: unknown) => {
|
|
346
|
+
assert.ok(err instanceof S3TransportError);
|
|
347
|
+
assert.equal(err.status, 409);
|
|
348
|
+
assert.notEqual(
|
|
349
|
+
err.message,
|
|
350
|
+
s3Msg('sync.s3.concurrentWrite', { status: '409', url: OSS_INDEX_URL }),
|
|
351
|
+
'FileImmutable 与 FileAlreadyExists 同为 409,不能都说成「别的设备改过索引」',
|
|
352
|
+
);
|
|
353
|
+
assert.match(err.message, /FileImmutable/, '真实错误码必须原样带出,用户才看得出是桶的保护策略');
|
|
354
|
+
return true;
|
|
355
|
+
},
|
|
356
|
+
);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test('条件写①-b(OSS,删除路径):索引已有 ETag → 写回前 HEAD 复核,且不发 if-match / forbid-overwrite', async () => {
|
|
360
|
+
const meta = {
|
|
361
|
+
id: 'snap-001',
|
|
362
|
+
createdAt: '2026-10-18T09:00:00.000Z',
|
|
363
|
+
sections: {},
|
|
364
|
+
manifest: { schemaVersion: 1, dshVersion: '1', platform: 'win32', sectionIds: [], containsSecrets: false },
|
|
365
|
+
};
|
|
366
|
+
const calls: S3Call[] = [];
|
|
367
|
+
const t = new S3Transport(ossOptions(record(calls, (m) => {
|
|
368
|
+
if (m.method === 'GET' && m.url === OSS_INDEX_URL) return res(200, JSON.stringify([meta]), { etag: '"v1-oss-del"' });
|
|
369
|
+
if (m.method === 'DELETE' && m.url === OSS_SNAPSHOT_URL) return res(204, '');
|
|
370
|
+
if (m.method === 'HEAD' && m.url === OSS_INDEX_URL) return res(200, '', { etag: '"v1-oss-del"' });
|
|
371
|
+
if (m.method === 'PUT' && m.url === OSS_INDEX_URL) return res(200, '');
|
|
372
|
+
if (m.method === 'GET' && m.url === OSS_BLOBS_INDEX_URL) return res(404, '');
|
|
373
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
374
|
+
})));
|
|
375
|
+
|
|
376
|
+
await t.delete('snap-001');
|
|
377
|
+
|
|
378
|
+
const headAt = calls.findIndex((c) => c.method === 'HEAD' && c.url === OSS_INDEX_URL);
|
|
379
|
+
const putAt = calls.findIndex((c) => c.method === 'PUT' && c.url === OSS_INDEX_URL);
|
|
380
|
+
assert.ok(headAt >= 0 && headAt < putAt, 'OSS 删除路径同样要在写回前复核 ETag');
|
|
381
|
+
const put = calls[putAt]!;
|
|
382
|
+
assert.equal(put.headers['if-match'], undefined, 'OSS PutObject 不支持 If-Match');
|
|
383
|
+
assert.equal(put.headers['x-oss-forbid-overwrite'], undefined, '索引已存在,「禁止覆盖」会把自己挡在门外');
|
|
384
|
+
assert.equal(put.body, '[]');
|
|
385
|
+
});
|
|
386
|
+
|
|
237
387
|
/* ---------------- ② 探针 ---------------- */
|
|
238
388
|
|
|
239
389
|
test('② 探针:HEAD 回 301 + x-amz-bucket-region: cn-hangzhou → 抛错且文案含该 region', async () => {
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
* ② index 读操作抛错 → 显式失败(F2 语义,绝不回落成空索引);
|
|
12
12
|
* ③ index = 200 + [] → 索引权威地声明集合为空,保持既有语义(既有用例
|
|
13
13
|
* 「blob GC:删除最后一份快照后回收超保护窗的无人引用 blob」钉住该路径);
|
|
14
|
-
* ④ GC 遇到「索引有条目但快照文件读不出来(非 404)」→ 本轮放弃(读不出来 ≠
|
|
14
|
+
* ④ GC 遇到「索引有条目但快照文件读不出来(非 404)」→ 本轮放弃(读不出来 ≠ 没引用);
|
|
15
|
+
* ⑤ SYN-04(P1):与 WebDAV 同型 —— **404 也放弃本轮**(孤儿条目 / 假 404 拿不到内容就无法证明
|
|
16
|
+
* 「没人引用」),本轮 0 删除并记下放弃码(`lastGcSkip`,机器可判定)。
|
|
15
17
|
*/
|
|
16
18
|
import test from 'node:test';
|
|
17
19
|
import assert from 'node:assert/strict';
|
|
@@ -168,3 +170,26 @@ test('N1⑤:索引有条目但该快照文件读不出来(非 404)→ 本
|
|
|
168
170
|
assert.equal(remote.deletedBlobs.length, 0, '读不出 sync-ccc-333 就无法证明它没引用 blob → 本轮不得删任何 blob');
|
|
169
171
|
assert.equal(remote.objects.has(PREFIX + '/blobs/' + BLOB_HASH), true);
|
|
170
172
|
});
|
|
173
|
+
|
|
174
|
+
test('N1⑥(SYN-04):索引有条目但该快照文件真 404 → 本轮放弃 GC(404 也证明不了「没引用」)+ 记放弃码', async () => {
|
|
175
|
+
const remote = makeRemote({
|
|
176
|
+
index: JSON.stringify([meta('sync-aaa-111', '1'), meta('sync-ccc-333', '3')]),
|
|
177
|
+
snapshotFiles: { 'sync-aaa-111': snapOf('sync-aaa-111', PLAIN) },
|
|
178
|
+
});
|
|
179
|
+
const t = new S3Transport(makeOptions(remote));
|
|
180
|
+
await t.delete('sync-aaa-111');
|
|
181
|
+
assert.equal(remote.deletedBlobs.length, 0, '404 与「读不出来」同属「无法证明没有引用」→ 本轮 0 删除');
|
|
182
|
+
assert.equal(remote.objects.has(PREFIX + '/blobs/' + BLOB_HASH), true, '没有被证明无引用的 blob 必须保留');
|
|
183
|
+
assert.equal(t.lastGcSkip, 'gc-skip-reference-missing', '必须记下本轮放弃码(机器可判定,文案由上层按码翻译)');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('N1⑦(SYN-04):引用者 200 但内容坏掉 → 本轮放弃,放弃码 = snapshot-unparsable', async () => {
|
|
187
|
+
const remote = makeRemote({
|
|
188
|
+
index: JSON.stringify([meta('sync-aaa-111', '1'), meta('sync-ccc-333', '3')]),
|
|
189
|
+
snapshotFiles: { 'sync-aaa-111': snapOf('sync-aaa-111', PLAIN), 'sync-ccc-333': 'not-json' },
|
|
190
|
+
});
|
|
191
|
+
const t = new S3Transport(makeOptions(remote));
|
|
192
|
+
await t.delete('sync-aaa-111');
|
|
193
|
+
assert.equal(remote.deletedBlobs.length, 0, '解析不了 ⇒ 引用集不完整 ⇒ 本轮不得删任何 blob');
|
|
194
|
+
assert.equal(t.lastGcSkip, 'gc-skip-snapshot-unparsable');
|
|
195
|
+
});
|
|
@@ -31,6 +31,16 @@ export const S3_INDEX_FILE = 'index.json';
|
|
|
31
31
|
export const S3_BLOBS_SEG = 'blobs';
|
|
32
32
|
export const S3_BLOBS_INDEX_FILE = 'blobs-index.json';
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* 条件写能力(决定「防两台设备同时写」怎么落地):
|
|
36
|
+
* - `etag`:AWS 风格 If-Match / If-None-Match(s3 / minio / cos / kodo);
|
|
37
|
+
* - `forbid-overwrite`:阿里云 OSS —— PutObject **不支持 If-\***(真机会回 400
|
|
38
|
+
* InvalidArgument「A header you provided implies functionality that is not implemented.」,
|
|
39
|
+
* 错误码 0017-00000245;issue #109 第二层),只有 `x-oss-forbid-overwrite: true`
|
|
40
|
+
* 「对象已存在即拒」这一种禁止覆盖语义。
|
|
41
|
+
*/
|
|
42
|
+
export type S3ConditionalWrite = 'etag' | 'forbid-overwrite';
|
|
43
|
+
|
|
34
44
|
export interface S3ProviderVariant {
|
|
35
45
|
id: S3CompatProvider;
|
|
36
46
|
/** 默认签名方言(可被 \`dialectId\` 覆盖) */
|
|
@@ -43,6 +53,8 @@ export interface S3ProviderVariant {
|
|
|
43
53
|
endpointTemplate?: string;
|
|
44
54
|
/** 默认寻址风格:true = path-style(<endpoint>/<bucket>/<key>),false = virtual-host(<bucket>.<endpoint>/<key>) */
|
|
45
55
|
defaultPathStyle: boolean;
|
|
56
|
+
/** 条件写能力(见 S3ConditionalWrite;与签名方言解耦,跟着服务商走而不是跟着 dialectId 走) */
|
|
57
|
+
conditionalWrite: S3ConditionalWrite;
|
|
46
58
|
/**
|
|
47
59
|
* 变体说明的**目录键**(自 t6 起字段是键而不是文案 —— 中文只存在于 `sync/s3/messages.ts` 的本地目录,
|
|
48
60
|
* 经 `s3Msg` / `composeMsg(host, s3Msg)` 解析成当前语言;本字段本身不渲染)。
|
|
@@ -58,25 +70,30 @@ export const S3_PROVIDER_VARIANTS: Record<S3CompatProvider, S3ProviderVariant> =
|
|
|
58
70
|
s3: {
|
|
59
71
|
id: 's3', dialectId: 'aws4', service: 's3', defaultRegion: 'us-east-1',
|
|
60
72
|
endpointTemplate: 'https://s3.{region}.amazonaws.com', defaultPathStyle: false,
|
|
73
|
+
conditionalWrite: 'etag',
|
|
61
74
|
note: 'sync.s3.providerNoteS3',
|
|
62
75
|
},
|
|
63
76
|
oss: {
|
|
64
77
|
id: 'oss', dialectId: 'oss4', service: 'oss',
|
|
65
78
|
endpointTemplate: 'https://oss-{region}.aliyuncs.com', defaultPathStyle: false,
|
|
79
|
+
conditionalWrite: 'forbid-overwrite',
|
|
66
80
|
note: 'sync.s3.providerNoteOss',
|
|
67
81
|
},
|
|
68
82
|
cos: {
|
|
69
83
|
id: 'cos', dialectId: 'aws4', service: 's3',
|
|
70
84
|
endpointTemplate: 'https://cos.{region}.myqcloud.com', defaultPathStyle: false,
|
|
85
|
+
conditionalWrite: 'etag',
|
|
71
86
|
note: 'sync.s3.providerNoteCos',
|
|
72
87
|
},
|
|
73
88
|
minio: {
|
|
74
89
|
id: 'minio', dialectId: 'aws4', service: 's3', defaultRegion: 'us-east-1', defaultPathStyle: true,
|
|
90
|
+
conditionalWrite: 'etag',
|
|
75
91
|
note: 'sync.s3.providerNoteMinio',
|
|
76
92
|
},
|
|
77
93
|
kodo: {
|
|
78
94
|
id: 'kodo', dialectId: 'aws4', service: 's3',
|
|
79
95
|
endpointTemplate: 'https://s3-{region}.qiniucs.com', defaultPathStyle: false,
|
|
96
|
+
conditionalWrite: 'etag',
|
|
80
97
|
note: 'sync.s3.providerNoteKodo',
|
|
81
98
|
},
|
|
82
99
|
};
|
|
@@ -110,6 +127,8 @@ export interface S3Target {
|
|
|
110
127
|
prefix: string;
|
|
111
128
|
pathStyle: boolean;
|
|
112
129
|
dialect: SigV4Dialect;
|
|
130
|
+
/** 条件写能力(来自变体表;dialectId 覆盖不影响它) */
|
|
131
|
+
conditionalWrite: S3ConditionalWrite;
|
|
113
132
|
}
|
|
114
133
|
|
|
115
134
|
export interface S3TargetInput {
|
|
@@ -176,6 +195,7 @@ export function resolveS3Target(input: S3TargetInput): S3TargetResult {
|
|
|
176
195
|
prefix,
|
|
177
196
|
pathStyle: input.pathStyle ?? variant.defaultPathStyle,
|
|
178
197
|
dialect: sigV4Dialect(input.dialectId ?? variant.dialectId),
|
|
198
|
+
conditionalWrite: variant.conditionalWrite,
|
|
179
199
|
},
|
|
180
200
|
};
|
|
181
201
|
}
|
|
@@ -115,3 +115,51 @@ test('OSS 服务端视角验签:Authorization 逐字形状(逗号后无空
|
|
|
115
115
|
}
|
|
116
116
|
assert.deepEqual(server.failed, []);
|
|
117
117
|
});
|
|
118
|
+
test('OSS 服务端视角:首推全程不发 If-*(真机会回 400 0017-00000245),改用 x-oss-forbid-overwrite', async () => {
|
|
119
|
+
const server = makeServer();
|
|
120
|
+
const seen: { method: string; url: string; headers: Record<string, string> }[] = [];
|
|
121
|
+
const wrapped: S3RequestFn = async (method, url, opts = {}) => {
|
|
122
|
+
seen.push({ method, url, headers: { ...(opts.headers ?? {}) } });
|
|
123
|
+
return await server.request(method, url, opts);
|
|
124
|
+
};
|
|
125
|
+
const transport = makeTransport(wrapped);
|
|
126
|
+
|
|
127
|
+
await transport.probe();
|
|
128
|
+
await transport.upload(sampleSnapshot());
|
|
129
|
+
|
|
130
|
+
for (const req of seen) {
|
|
131
|
+
assert.equal(req.headers['if-none-match'], undefined, '绝不发 If-None-Match:' + req.method + ' ' + req.url);
|
|
132
|
+
assert.equal(req.headers['if-match'], undefined, '绝不发 If-Match:' + req.method + ' ' + req.url);
|
|
133
|
+
}
|
|
134
|
+
const indexPut = seen.find((r) => r.method === 'PUT' && r.url.endsWith('/index.json'));
|
|
135
|
+
assert.ok(indexPut, '必须有一次索引 PUT');
|
|
136
|
+
assert.equal(indexPut.headers['x-oss-forbid-overwrite'], 'true', 'OSS 只能靠 forbid-overwrite 防并发首推');
|
|
137
|
+
assert.deepEqual(server.failed, [], '换头之后仍必须逐请求验签通过');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('OSS 服务端视角:验签器照真机拒 If-*(自证盲点回归)', async () => {
|
|
141
|
+
// 这条用例保护的**不是**我们的代码,而是测试替身本身:如果验签器又「自己实现了 if-none-match」,
|
|
142
|
+
// 那 §issue #109 的「14 个请求零失败」就会重演 —— 本地全绿、真机 400。所以这里刻意注入一个
|
|
143
|
+
// If-None-Match(该头不进 OSS4 签名,故签名依旧有效),断言服务端按真机语义拒绝。
|
|
144
|
+
const server = makeServer();
|
|
145
|
+
const wrapped: S3RequestFn = async (method, url, opts = {}) => {
|
|
146
|
+
if (method === 'PUT' && url.endsWith('/index.json')) {
|
|
147
|
+
return await server.request(method, url, { ...opts, headers: { ...(opts.headers ?? {}), 'if-none-match': '*' } });
|
|
148
|
+
}
|
|
149
|
+
return await server.request(method, url, opts);
|
|
150
|
+
};
|
|
151
|
+
const transport = makeTransport(wrapped);
|
|
152
|
+
|
|
153
|
+
await assert.rejects(
|
|
154
|
+
() => transport.upload(sampleSnapshot()),
|
|
155
|
+
(err: unknown) => {
|
|
156
|
+
const message = (err as Error).message;
|
|
157
|
+
assert.match(message, /implies functionality that is not implemented/, '真机报文原文');
|
|
158
|
+
assert.match(message, /If-None-Match/, 'OSS 会回显被拒的头名');
|
|
159
|
+
assert.match(message, /0017-00000245/, '错误码同现场反馈');
|
|
160
|
+
return true;
|
|
161
|
+
},
|
|
162
|
+
);
|
|
163
|
+
assert.deepEqual(server.failed, [], '签名本身仍然有效 —— 拒的是 API 语义,不是签名');
|
|
164
|
+
assert.ok(!server.objects.has('dsh-config-manager/index.json'), '被拒的索引 PUT 不得落对象');
|
|
165
|
+
});
|
|
@@ -26,6 +26,8 @@ import { requestOnce } from '../../utils/proxy.ts';
|
|
|
26
26
|
import type { RawResponse } from '../../utils/proxy.ts';
|
|
27
27
|
import { parseJsonSafe } from '../../utils/json.ts';
|
|
28
28
|
import type { MsgFunc } from '../../core/msg-types.ts';
|
|
29
|
+
import { GC_SKIP_REFERENCE_MISSING, GC_SKIP_REFERENCE_UNREADABLE, GC_SKIP_SNAPSHOT_UNPARSABLE } from '../gc-skip.ts';
|
|
30
|
+
import type { GcSkipCode } from '../gc-skip.ts';
|
|
29
31
|
import { deserializeSnapshot, serializeSnapshot } from '../snapshot-json.ts';
|
|
30
32
|
import {
|
|
31
33
|
BLOB_SECTIONS, gcBlobs, isBlobRefsSection, isFilesSectionLike, referencedBlobHashes,
|
|
@@ -45,7 +47,7 @@ import { composeMsg, s3Msg } from './messages.ts';
|
|
|
45
47
|
import {
|
|
46
48
|
blobIndexKey, blobKey, canonicalObjectPath, indexKey, objectUrl, resolveS3Target, snapshotKey,
|
|
47
49
|
} from './s3-providers.ts';
|
|
48
|
-
import type { S3Target } from './s3-providers.ts';
|
|
50
|
+
import type { S3ConditionalWrite, S3Target } from './s3-providers.ts';
|
|
49
51
|
import type { CloudConfigIssueCode, S3CompatProvider } from '../sync-config.ts';
|
|
50
52
|
import type { FilesSection, SectionData, SectionId } from '../../schema/types.ts';
|
|
51
53
|
|
|
@@ -62,16 +64,34 @@ const REDACTED = '[REDACTED]';
|
|
|
62
64
|
/**
|
|
63
65
|
* 条件写头(cloud-sync 借鉴项 ①):有 ETag → If-Match(远端必须仍是我读到的那一版);
|
|
64
66
|
* 索引本来就不存在 → If-None-Match: *(防两设备同时首推);服务端不给 ETag → 空(无条件写,不改既有行为)。
|
|
67
|
+
*
|
|
68
|
+
* **阿里云 OSS 没有 If-\***(issue #109 第二层):PutObject 收到 If-Match / If-None-Match 一律回
|
|
69
|
+
* 400 InvalidArgument「A header you provided implies functionality that is not implemented.」
|
|
70
|
+
* (错误码 0017-00000245,真机报文里的 `Header: If-None-Match` 即此)。它只提供
|
|
71
|
+
* `x-oss-forbid-overwrite: true`(对象已存在即 409 FileAlreadyExists)。于是按变体的
|
|
72
|
+
* `conditionalWrite` 能力位映射:
|
|
73
|
+
* - 首推(索引本来就不存在)→ 语义完全等价,改用 x-oss-forbid-overwrite;
|
|
74
|
+
* - 索引已存在(拿到了 ETag)→ 没有对应头,退回「写前 HEAD 复核 ETag」
|
|
75
|
+
* (`assertIndexEtagUnchanged`;非原子,尽力而为)。
|
|
65
76
|
*/
|
|
66
|
-
function conditionalHeaders(
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
function conditionalHeaders(
|
|
78
|
+
etag: string | undefined,
|
|
79
|
+
indexMissing: boolean,
|
|
80
|
+
mode: S3ConditionalWrite,
|
|
81
|
+
): Record<string, string> {
|
|
82
|
+
const guarded = mode === 'forbid-overwrite';
|
|
83
|
+
if (etag !== undefined) return guarded ? {} : { 'if-match': etag };
|
|
84
|
+
if (!indexMissing) return {};
|
|
85
|
+
return guarded ? { 'x-oss-forbid-overwrite': 'true' } : { 'if-none-match': '*' };
|
|
69
86
|
}
|
|
70
87
|
|
|
71
|
-
/**
|
|
72
|
-
|
|
88
|
+
/**
|
|
89
|
+
* 条件写失败判定:412 恒是;409 仅在**确实带了条件写头**时才算
|
|
90
|
+
* (无条件的 409 另有含义,不吞;条件写头的存在由调用方显式告知)。
|
|
91
|
+
*/
|
|
92
|
+
function isConcurrentWrite(status: number, guarded: boolean): boolean {
|
|
73
93
|
if (status === 412) return true;
|
|
74
|
-
return status === 409 &&
|
|
94
|
+
return status === 409 && guarded;
|
|
75
95
|
}
|
|
76
96
|
|
|
77
97
|
/** 请求选项:headers / body / 覆盖默认超时(ms;0 = 不超时) */
|
|
@@ -213,6 +233,14 @@ export class S3Transport implements SyncTransport {
|
|
|
213
233
|
msg: MsgFunc;
|
|
214
234
|
};
|
|
215
235
|
|
|
236
|
+
/** 最近一轮 blob GC 的放弃码(`null` = 跑完或未触发;SYN-04)。 */
|
|
237
|
+
private gcSkip: GcSkipCode | null = null;
|
|
238
|
+
|
|
239
|
+
/** 最近一轮 blob GC 是否因「无法证明引用集完整」而整体放弃(`null` = 正常跑完),供上层给用户提示。 */
|
|
240
|
+
get lastGcSkip(): GcSkipCode | null {
|
|
241
|
+
return this.gcSkip;
|
|
242
|
+
}
|
|
243
|
+
|
|
216
244
|
constructor(options: S3TransportOptions) {
|
|
217
245
|
// t79:宿主传进来的 msg(core 目录)**不包含** sync.s3.* 键,直接用会显示裸键名 —— 合并本地目录。
|
|
218
246
|
const msg = composeMsg(options.msg, s3Msg);
|
|
@@ -298,13 +326,15 @@ export class S3Transport implements SyncTransport {
|
|
|
298
326
|
const merged = idxBefore.filter((m) => m.id !== snapshot.id);
|
|
299
327
|
merged.push(meta);
|
|
300
328
|
merged.sort((a, b) => (a.createdAt < b.createdAt ? -1 : a.createdAt > b.createdAt ? 1 : 0));
|
|
301
|
-
const condHeaders = conditionalHeaders(idxEtag, indexMissing);
|
|
329
|
+
const condHeaders = conditionalHeaders(idxEtag, indexMissing, this.target.conditionalWrite);
|
|
330
|
+
await this.reassertIndexEtag(idxEtag, secret);
|
|
302
331
|
const putIdx = await this.send('PUT', indexKey(this.target.prefix), {
|
|
303
332
|
body: JSON.stringify(merged),
|
|
304
333
|
secret,
|
|
305
334
|
headers: condHeaders,
|
|
306
335
|
});
|
|
307
|
-
|
|
336
|
+
const idxFailure = await this.conditionalFailure('PUT', putIdx.url, putIdx.res, Object.keys(condHeaders).length > 0, secret);
|
|
337
|
+
if (idxFailure !== undefined) throw idxFailure;
|
|
308
338
|
if (!putIdx.res.ok) {
|
|
309
339
|
throw new S3TransportError(await this.failText('PUT', putIdx.url, putIdx.res, secret), classifyHttpStatus(putIdx.res.status));
|
|
310
340
|
}
|
|
@@ -351,13 +381,15 @@ export class S3Transport implements SyncTransport {
|
|
|
351
381
|
if (indexMissing) return;
|
|
352
382
|
const remaining = idx.filter((m) => m.id !== id);
|
|
353
383
|
if (remaining.length === idx.length && del.res.status === 404) return; // 对象与索引都没有 → 静默成功
|
|
354
|
-
const condHeaders = conditionalHeaders(idxEtag, false);
|
|
384
|
+
const condHeaders = conditionalHeaders(idxEtag, false, this.target.conditionalWrite);
|
|
385
|
+
await this.reassertIndexEtag(idxEtag, secret);
|
|
355
386
|
const putIdx = await this.send('PUT', indexKey(this.target.prefix), {
|
|
356
387
|
body: JSON.stringify(remaining),
|
|
357
388
|
secret,
|
|
358
389
|
headers: condHeaders,
|
|
359
390
|
});
|
|
360
|
-
|
|
391
|
+
const idxFailure = await this.conditionalFailure('PUT', putIdx.url, putIdx.res, Object.keys(condHeaders).length > 0, secret);
|
|
392
|
+
if (idxFailure !== undefined) throw idxFailure;
|
|
361
393
|
if (!putIdx.res.ok) {
|
|
362
394
|
throw new S3TransportError(await this.failText('PUT', putIdx.url, putIdx.res, secret), classifyHttpStatus(putIdx.res.status));
|
|
363
395
|
}
|
|
@@ -374,6 +406,58 @@ export class S3Transport implements SyncTransport {
|
|
|
374
406
|
);
|
|
375
407
|
}
|
|
376
408
|
|
|
409
|
+
/**
|
|
410
|
+
* OSS 方言的「ETag 条件写」替身(issue #109 第二层):PutObject 既无 If-Match 也无
|
|
411
|
+
* If-None-Match,`x-oss-forbid-overwrite` 只能表达「别覆盖已存在的对象」,表达不了
|
|
412
|
+
* 「远端必须还是我读到的那一版」。所以索引进已存在时改成**写前 HEAD 复核 ETag**:
|
|
413
|
+
* 变了 / 对象没了 → 按并发写中止(零写入)。
|
|
414
|
+
*
|
|
415
|
+
* **不是原子的**:复核与 PUT 之间仍有窗口(服务端不支持条件写就没有真正的解),
|
|
416
|
+
* 比无保护强、比 If-Match 弱 —— 如实登记在 docs/decisions/0003。
|
|
417
|
+
* 其它方言(etag)与「服务端不给 ETag」两种情况一律直接放行,不改既有行为。
|
|
418
|
+
*/
|
|
419
|
+
private async reassertIndexEtag(etag: string | undefined, secret: string): Promise<void> {
|
|
420
|
+
if (this.target.conditionalWrite !== 'forbid-overwrite' || etag === undefined) return;
|
|
421
|
+
const key = indexKey(this.target.prefix);
|
|
422
|
+
const url = objectUrl(this.target, key);
|
|
423
|
+
const head = await this.send('HEAD', key, { secret });
|
|
424
|
+
if (head.res.status === 404) throw this.concurrentWrite(url, 409);
|
|
425
|
+
if (!head.res.ok) {
|
|
426
|
+
throw new S3TransportError(
|
|
427
|
+
await this.failText('HEAD', head.url, head.res, secret),
|
|
428
|
+
classifyHttpStatus(head.res.status),
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
const current = head.res.headers?.['etag'];
|
|
432
|
+
if (typeof current === 'string' && current !== '' && current !== etag) {
|
|
433
|
+
throw this.concurrentWrite(url, 409);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* 条件写失败分类(issue #109 第二层复核):`isConcurrentWrite` 只看「状态码像不像」,
|
|
439
|
+
* 这里再问报文一句确认「对象确实已存在」。OSS 的 **409 不止 FileAlreadyExists** ——
|
|
440
|
+
* FileImmutable(Bucket 数据处于保护状态,删改都会被拒)同为 409,一律按并发写报
|
|
441
|
+
* 「别的设备改过索引」就是假话。报文读不出时仍按并发写处理(宁可让用户重跑一次,
|
|
442
|
+
* 不吞掉真冲突)。412 是 If-Match 语义,恒为并发写。
|
|
443
|
+
*/
|
|
444
|
+
private async conditionalFailure(
|
|
445
|
+
method: string,
|
|
446
|
+
url: string,
|
|
447
|
+
res: S3Response,
|
|
448
|
+
guarded: boolean,
|
|
449
|
+
secret: string,
|
|
450
|
+
): Promise<S3TransportError | undefined> {
|
|
451
|
+
if (!isConcurrentWrite(res.status, guarded)) return undefined;
|
|
452
|
+
if (res.status !== 409) return this.concurrentWrite(url, res.status);
|
|
453
|
+
// 只有 forbid-overwrite 方言的 409 有两种含义(FileAlreadyExists / FileImmutable);
|
|
454
|
+
// etag 方言的 409 由各家自定语义,报文不可当作判据 —— 沿用「带条件头的 409 = 并发写」。
|
|
455
|
+
if (this.target.conditionalWrite !== 'forbid-overwrite') return this.concurrentWrite(url, res.status);
|
|
456
|
+
const body = await this.errorBody(res);
|
|
457
|
+
if (body === '' || body.includes('FileAlreadyExists')) return this.concurrentWrite(url, res.status);
|
|
458
|
+
return new S3TransportError(this.failMessage(method, url, res.status, body, secret), classifyHttpStatus(res.status));
|
|
459
|
+
}
|
|
460
|
+
|
|
377
461
|
/**
|
|
378
462
|
* 连通性探针(cloud-sync 借鉴项 ②):HEAD 桶证明端点/凭据/桶可达,再读一次索引回报快照数。
|
|
379
463
|
* 重定向(301/307/308)时读 x-amz-bucket-region 直接把「region 该填什么」告诉用户 ——
|
|
@@ -476,22 +560,29 @@ export class S3Transport implements SyncTransport {
|
|
|
476
560
|
}
|
|
477
561
|
}
|
|
478
562
|
|
|
479
|
-
/**
|
|
480
|
-
private async
|
|
481
|
-
let body = '';
|
|
563
|
+
/** 读错误响应体(未脱敏原文,截断到 ERR_BODY_MAX;读不出按空串) */
|
|
564
|
+
private async errorBody(res: S3Response): Promise<string> {
|
|
482
565
|
try {
|
|
483
|
-
|
|
566
|
+
return (await res.text()).slice(0, ERR_BODY_MAX);
|
|
484
567
|
} catch {
|
|
485
|
-
|
|
568
|
+
return '';
|
|
486
569
|
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/** 构造 HTTP 非 2xx 失败消息:附上脱敏后的响应体片段(截断) */
|
|
573
|
+
private failMessage(method: string, url: string, status: number, body: string, secret: string): string {
|
|
487
574
|
return this.o.msg('sync.s3.requestFailed', {
|
|
488
575
|
method,
|
|
489
576
|
url,
|
|
490
|
-
status: String(
|
|
577
|
+
status: String(status),
|
|
491
578
|
err: this.mask(body, secret),
|
|
492
579
|
});
|
|
493
580
|
}
|
|
494
581
|
|
|
582
|
+
private async failText(method: string, url: string, res: S3Response, secret: string): Promise<string> {
|
|
583
|
+
return this.failMessage(method, url, res.status, await this.errorBody(res), secret);
|
|
584
|
+
}
|
|
585
|
+
|
|
495
586
|
/** 识别超时错误(AbortError / TimeoutError) */
|
|
496
587
|
private isTimeout(err: unknown): boolean {
|
|
497
588
|
const name = (err as Error | undefined)?.name ?? '';
|
|
@@ -708,20 +799,29 @@ export class S3Transport implements SyncTransport {
|
|
|
708
799
|
}
|
|
709
800
|
|
|
710
801
|
/** blob 仓 GC:逐份读仍存在的快照收集引用,删除无人引用且超保护窗的 blob;
|
|
711
|
-
*
|
|
802
|
+
* 读不坏任何一份快照 → 正常回收,否则本轮整体放弃(宁可留垃圾,不可删在用的)。
|
|
803
|
+
* SYN-04(P1):**404 也放弃本轮** —— 条目在但文件 404 = 拿不到内容 = 无法证明「没人引用」,
|
|
804
|
+
* 按残集回收会删掉仍在用的 blob(与 WebDAV 同型,口径一致)。 */
|
|
712
805
|
private async gcBlobStore(secret: string, remaining: SyncSnapshotMeta[]): Promise<void> {
|
|
806
|
+
this.gcSkip = null;
|
|
713
807
|
const index = await this.readBlobIndex(secret);
|
|
714
808
|
if (Object.keys(index).length === 0) return;
|
|
715
809
|
const referenced = new Set<string>();
|
|
716
810
|
for (const meta of remaining) {
|
|
717
811
|
const sent = await this.send('GET', snapshotKey(this.target.prefix, meta.id), { secret });
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
812
|
+
if (sent.res.status === 404) {
|
|
813
|
+
this.gcSkip = GC_SKIP_REFERENCE_MISSING;
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
if (!sent.res.ok) {
|
|
817
|
+
this.gcSkip = GC_SKIP_REFERENCE_UNREADABLE;
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
721
820
|
let snap: SyncSnapshot;
|
|
722
821
|
try {
|
|
723
822
|
snap = deserializeSnapshot(await sent.res.text());
|
|
724
823
|
} catch {
|
|
824
|
+
this.gcSkip = GC_SKIP_SNAPSHOT_UNPARSABLE;
|
|
725
825
|
return;
|
|
726
826
|
}
|
|
727
827
|
const plain = snap.sections as Partial<Record<SectionId, unknown>>;
|