zen-fs-config 0.7.7 → 0.7.9
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/dist/{backend-registry-UCAMGG6O.mjs → backend-registry-EKW4RVPI.mjs} +1 -1
- package/dist/{chunk-WURWDHNT.mjs → chunk-OCPRJBM5.mjs} +128 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +217 -15
- package/dist/index.mjs +70 -3
- package/dist/zen-fs-config.js +293 -91
- package/package.json +1 -1
|
@@ -1,3 +1,125 @@
|
|
|
1
|
+
// src/idb-repair.ts
|
|
2
|
+
var INODE_SIZE = 4096;
|
|
3
|
+
var S_IFMT = 61440;
|
|
4
|
+
var S_IFDIR = 16384;
|
|
5
|
+
var LEGACY_LISTING_MAGIC = 123;
|
|
6
|
+
function idb() {
|
|
7
|
+
return globalThis.indexedDB;
|
|
8
|
+
}
|
|
9
|
+
function openDB(name) {
|
|
10
|
+
const factory = idb();
|
|
11
|
+
if (!factory) return Promise.resolve(null);
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
let req;
|
|
14
|
+
try {
|
|
15
|
+
req = factory.open(name);
|
|
16
|
+
} catch {
|
|
17
|
+
resolve(null);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
req.onupgradeneeded = () => {
|
|
21
|
+
try {
|
|
22
|
+
req.transaction?.abort();
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
req.onsuccess = () => resolve(req.result);
|
|
27
|
+
req.onerror = () => resolve(null);
|
|
28
|
+
req.onblocked = () => resolve(null);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
var request = (req) => new Promise((resolve, reject) => {
|
|
32
|
+
req.onsuccess = () => resolve(req.result);
|
|
33
|
+
req.onerror = () => reject(req.error);
|
|
34
|
+
});
|
|
35
|
+
function isDecodableListing(bytes) {
|
|
36
|
+
if (bytes.length === 0) return false;
|
|
37
|
+
if (bytes[0] !== LEGACY_LISTING_MAGIC) return true;
|
|
38
|
+
let text;
|
|
39
|
+
try {
|
|
40
|
+
text = new TextDecoder().decode(bytes);
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
let parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = JSON.parse(text);
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
51
|
+
return Object.values(parsed).every(
|
|
52
|
+
(v) => typeof v === "number" || typeof v === "string" && /^\d+$/.test(v)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function isDirectoryInode(bytes, key) {
|
|
56
|
+
if (bytes.byteLength !== INODE_SIZE) return null;
|
|
57
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
58
|
+
const ino = view.getUint32(58, true);
|
|
59
|
+
if (ino !== key) return null;
|
|
60
|
+
const mode = view.getUint16(12, true);
|
|
61
|
+
if ((mode & S_IFMT) !== S_IFDIR) return null;
|
|
62
|
+
const mtime = view.getFloat64(42, true);
|
|
63
|
+
if (!Number.isFinite(mtime) || mtime < 1e11 || mtime > 1e13) return null;
|
|
64
|
+
return view.getUint32(0, true);
|
|
65
|
+
}
|
|
66
|
+
async function repairIndexedDBStore(storeName) {
|
|
67
|
+
if (!idb()) return null;
|
|
68
|
+
const db = await openDB(storeName);
|
|
69
|
+
if (!db) return null;
|
|
70
|
+
const objectStoreName = Array.from(
|
|
71
|
+
db.objectStoreNames
|
|
72
|
+
)[0];
|
|
73
|
+
if (!objectStoreName) {
|
|
74
|
+
db.close?.();
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const result = { scanned: 0, repaired: 0, details: [] };
|
|
78
|
+
try {
|
|
79
|
+
const tx = db.transaction(objectStoreName, "readwrite");
|
|
80
|
+
const store = tx.objectStore(objectStoreName);
|
|
81
|
+
const keys = await request(store.getAllKeys());
|
|
82
|
+
const values = await request(store.getAll());
|
|
83
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
84
|
+
for (let i = 0; i < keys.length; i++) {
|
|
85
|
+
const value = values[i];
|
|
86
|
+
if (value instanceof Uint8Array) byKey.set(Number(keys[i]), value);
|
|
87
|
+
}
|
|
88
|
+
for (let i = 0; i < keys.length; i++) {
|
|
89
|
+
const value = values[i];
|
|
90
|
+
if (!(value instanceof Uint8Array)) continue;
|
|
91
|
+
const key = Number(keys[i]);
|
|
92
|
+
if (!Number.isFinite(key)) continue;
|
|
93
|
+
result.scanned++;
|
|
94
|
+
const dataSlot = isDirectoryInode(value, key);
|
|
95
|
+
if (dataSlot === null) continue;
|
|
96
|
+
const listing = byKey.get(dataSlot);
|
|
97
|
+
if (listing && isDecodableListing(listing)) continue;
|
|
98
|
+
const reason = listing ? "listing slot holds non-listing bytes" : "listing slot missing";
|
|
99
|
+
result.repaired++;
|
|
100
|
+
result.details.push({ key, data: dataSlot, reason });
|
|
101
|
+
await request(store.put(new TextEncoder().encode("{}"), dataSlot));
|
|
102
|
+
}
|
|
103
|
+
await new Promise((resolve, reject) => {
|
|
104
|
+
tx.oncomplete = () => resolve();
|
|
105
|
+
tx.onerror = () => reject(tx.error);
|
|
106
|
+
tx.onabort = () => reject(tx.error);
|
|
107
|
+
});
|
|
108
|
+
} catch {
|
|
109
|
+
try {
|
|
110
|
+
db.close?.();
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
} finally {
|
|
115
|
+
try {
|
|
116
|
+
db.close?.();
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
|
|
1
123
|
// src/backend-registry.ts
|
|
2
124
|
var registry = /* @__PURE__ */ new Map();
|
|
3
125
|
var metadataRegistry = /* @__PURE__ */ new Map();
|
|
@@ -164,6 +286,12 @@ registerBackend("IndexedDB", async (options) => {
|
|
|
164
286
|
const { IndexedDB } = await import("@zenfs/dom");
|
|
165
287
|
const storeName = options.storeName ?? "zen-fs-config";
|
|
166
288
|
const label = options.label ?? storeName;
|
|
289
|
+
const repaired = await repairIndexedDBStore(storeName);
|
|
290
|
+
if (repaired?.repaired) {
|
|
291
|
+
console.warn(
|
|
292
|
+
`[Backend:IndexedDB] ${storeName}: reset ${repaired.repaired} corrupted directory listing(s): ` + repaired.details.map((d) => `ino ${d.key}\u2192slot ${d.data} (${d.reason})`).join(", ")
|
|
293
|
+
);
|
|
294
|
+
}
|
|
167
295
|
return wrapZenFSFileSystem({ backend: IndexedDB, storeName, label });
|
|
168
296
|
}, {
|
|
169
297
|
type: "IndexedDB",
|
package/dist/index.d.mts
CHANGED
|
@@ -1077,6 +1077,15 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1077
1077
|
private refreshSyncExclusions;
|
|
1078
1078
|
/** Invalidate the tombstone cache — call after tombstones are modified. */
|
|
1079
1079
|
private invalidateTombstoneCache;
|
|
1080
|
+
/**
|
|
1081
|
+
* 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
|
|
1082
|
+
*
|
|
1083
|
+
* 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
|
|
1084
|
+
* `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
|
|
1085
|
+
* 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
|
|
1086
|
+
* 因此在写入路径上即时撤销,并立即刷新排除表。
|
|
1087
|
+
*/
|
|
1088
|
+
private clearTombstonesForWrite;
|
|
1080
1089
|
/**
|
|
1081
1090
|
* 判定墓碑目标路径是否在删除之后被重新创建。
|
|
1082
1091
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1077,6 +1077,15 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1077
1077
|
private refreshSyncExclusions;
|
|
1078
1078
|
/** Invalidate the tombstone cache — call after tombstones are modified. */
|
|
1079
1079
|
private invalidateTombstoneCache;
|
|
1080
|
+
/**
|
|
1081
|
+
* 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
|
|
1082
|
+
*
|
|
1083
|
+
* 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
|
|
1084
|
+
* `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
|
|
1085
|
+
* 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
|
|
1086
|
+
* 因此在写入路径上即时撤销,并立即刷新排除表。
|
|
1087
|
+
*/
|
|
1088
|
+
private clearTombstonesForWrite;
|
|
1080
1089
|
/**
|
|
1081
1090
|
* 判定墓碑目标路径是否在删除之后被重新创建。
|
|
1082
1091
|
*
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,134 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
+
// src/idb-repair.ts
|
|
34
|
+
function idb() {
|
|
35
|
+
return globalThis.indexedDB;
|
|
36
|
+
}
|
|
37
|
+
function openDB(name) {
|
|
38
|
+
const factory = idb();
|
|
39
|
+
if (!factory) return Promise.resolve(null);
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
let req;
|
|
42
|
+
try {
|
|
43
|
+
req = factory.open(name);
|
|
44
|
+
} catch {
|
|
45
|
+
resolve(null);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
req.onupgradeneeded = () => {
|
|
49
|
+
try {
|
|
50
|
+
req.transaction?.abort();
|
|
51
|
+
} catch {
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
req.onsuccess = () => resolve(req.result);
|
|
55
|
+
req.onerror = () => resolve(null);
|
|
56
|
+
req.onblocked = () => resolve(null);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function isDecodableListing(bytes) {
|
|
60
|
+
if (bytes.length === 0) return false;
|
|
61
|
+
if (bytes[0] !== LEGACY_LISTING_MAGIC) return true;
|
|
62
|
+
let text;
|
|
63
|
+
try {
|
|
64
|
+
text = new TextDecoder().decode(bytes);
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
let parsed;
|
|
69
|
+
try {
|
|
70
|
+
parsed = JSON.parse(text);
|
|
71
|
+
} catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
75
|
+
return Object.values(parsed).every(
|
|
76
|
+
(v) => typeof v === "number" || typeof v === "string" && /^\d+$/.test(v)
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
function isDirectoryInode(bytes, key) {
|
|
80
|
+
if (bytes.byteLength !== INODE_SIZE) return null;
|
|
81
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
82
|
+
const ino = view.getUint32(58, true);
|
|
83
|
+
if (ino !== key) return null;
|
|
84
|
+
const mode = view.getUint16(12, true);
|
|
85
|
+
if ((mode & S_IFMT) !== S_IFDIR) return null;
|
|
86
|
+
const mtime = view.getFloat64(42, true);
|
|
87
|
+
if (!Number.isFinite(mtime) || mtime < 1e11 || mtime > 1e13) return null;
|
|
88
|
+
return view.getUint32(0, true);
|
|
89
|
+
}
|
|
90
|
+
async function repairIndexedDBStore(storeName) {
|
|
91
|
+
if (!idb()) return null;
|
|
92
|
+
const db = await openDB(storeName);
|
|
93
|
+
if (!db) return null;
|
|
94
|
+
const objectStoreName = Array.from(
|
|
95
|
+
db.objectStoreNames
|
|
96
|
+
)[0];
|
|
97
|
+
if (!objectStoreName) {
|
|
98
|
+
db.close?.();
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const result = { scanned: 0, repaired: 0, details: [] };
|
|
102
|
+
try {
|
|
103
|
+
const tx = db.transaction(objectStoreName, "readwrite");
|
|
104
|
+
const store = tx.objectStore(objectStoreName);
|
|
105
|
+
const keys = await request(store.getAllKeys());
|
|
106
|
+
const values = await request(store.getAll());
|
|
107
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
108
|
+
for (let i = 0; i < keys.length; i++) {
|
|
109
|
+
const value = values[i];
|
|
110
|
+
if (value instanceof Uint8Array) byKey.set(Number(keys[i]), value);
|
|
111
|
+
}
|
|
112
|
+
for (let i = 0; i < keys.length; i++) {
|
|
113
|
+
const value = values[i];
|
|
114
|
+
if (!(value instanceof Uint8Array)) continue;
|
|
115
|
+
const key = Number(keys[i]);
|
|
116
|
+
if (!Number.isFinite(key)) continue;
|
|
117
|
+
result.scanned++;
|
|
118
|
+
const dataSlot = isDirectoryInode(value, key);
|
|
119
|
+
if (dataSlot === null) continue;
|
|
120
|
+
const listing = byKey.get(dataSlot);
|
|
121
|
+
if (listing && isDecodableListing(listing)) continue;
|
|
122
|
+
const reason = listing ? "listing slot holds non-listing bytes" : "listing slot missing";
|
|
123
|
+
result.repaired++;
|
|
124
|
+
result.details.push({ key, data: dataSlot, reason });
|
|
125
|
+
await request(store.put(new TextEncoder().encode("{}"), dataSlot));
|
|
126
|
+
}
|
|
127
|
+
await new Promise((resolve, reject) => {
|
|
128
|
+
tx.oncomplete = () => resolve();
|
|
129
|
+
tx.onerror = () => reject(tx.error);
|
|
130
|
+
tx.onabort = () => reject(tx.error);
|
|
131
|
+
});
|
|
132
|
+
} catch {
|
|
133
|
+
try {
|
|
134
|
+
db.close?.();
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
} finally {
|
|
139
|
+
try {
|
|
140
|
+
db.close?.();
|
|
141
|
+
} catch {
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
var INODE_SIZE, S_IFMT, S_IFDIR, LEGACY_LISTING_MAGIC, request;
|
|
147
|
+
var init_idb_repair = __esm({
|
|
148
|
+
"src/idb-repair.ts"() {
|
|
149
|
+
"use strict";
|
|
150
|
+
INODE_SIZE = 4096;
|
|
151
|
+
S_IFMT = 61440;
|
|
152
|
+
S_IFDIR = 16384;
|
|
153
|
+
LEGACY_LISTING_MAGIC = 123;
|
|
154
|
+
request = (req) => new Promise((resolve, reject) => {
|
|
155
|
+
req.onsuccess = () => resolve(req.result);
|
|
156
|
+
req.onerror = () => reject(req.error);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
33
161
|
// src/backend-registry.ts
|
|
34
162
|
var backend_registry_exports = {};
|
|
35
163
|
__export(backend_registry_exports, {
|
|
@@ -267,6 +395,7 @@ var registry, metadataRegistry, inMemoryCounter, _memCache, OPTIONAL_BACKEND_GLO
|
|
|
267
395
|
var init_backend_registry = __esm({
|
|
268
396
|
"src/backend-registry.ts"() {
|
|
269
397
|
"use strict";
|
|
398
|
+
init_idb_repair();
|
|
270
399
|
registry = /* @__PURE__ */ new Map();
|
|
271
400
|
metadataRegistry = /* @__PURE__ */ new Map();
|
|
272
401
|
inMemoryCounter = 0;
|
|
@@ -291,6 +420,12 @@ var init_backend_registry = __esm({
|
|
|
291
420
|
const { IndexedDB } = await import("@zenfs/dom");
|
|
292
421
|
const storeName = options.storeName ?? "zen-fs-config";
|
|
293
422
|
const label = options.label ?? storeName;
|
|
423
|
+
const repaired = await repairIndexedDBStore(storeName);
|
|
424
|
+
if (repaired?.repaired) {
|
|
425
|
+
console.warn(
|
|
426
|
+
`[Backend:IndexedDB] ${storeName}: reset ${repaired.repaired} corrupted directory listing(s): ` + repaired.details.map((d) => `ino ${d.key}\u2192slot ${d.data} (${d.reason})`).join(", ")
|
|
427
|
+
);
|
|
428
|
+
}
|
|
294
429
|
return wrapZenFSFileSystem({ backend: IndexedDB, storeName, label });
|
|
295
430
|
}, {
|
|
296
431
|
type: "IndexedDB",
|
|
@@ -1153,8 +1288,8 @@ function isLocalStorageUnavailableError(err) {
|
|
|
1153
1288
|
}
|
|
1154
1289
|
function deleteDataGroupLocalStore(appId, groupId, options = {}) {
|
|
1155
1290
|
const storeName = dataGroupLocalStoreName(appId, groupId);
|
|
1156
|
-
const
|
|
1157
|
-
if (!
|
|
1291
|
+
const idb2 = globalThis.indexedDB;
|
|
1292
|
+
if (!idb2 || typeof idb2.deleteDatabase !== "function") {
|
|
1158
1293
|
return Promise.resolve({
|
|
1159
1294
|
storeName,
|
|
1160
1295
|
deleted: false,
|
|
@@ -1174,21 +1309,21 @@ function deleteDataGroupLocalStore(appId, groupId, options = {}) {
|
|
|
1174
1309
|
if (timer) clearTimeout(timer);
|
|
1175
1310
|
resolve(result);
|
|
1176
1311
|
};
|
|
1177
|
-
let
|
|
1312
|
+
let request2;
|
|
1178
1313
|
try {
|
|
1179
|
-
|
|
1314
|
+
request2 = idb2.deleteDatabase(storeName);
|
|
1180
1315
|
} catch (err) {
|
|
1181
1316
|
finish({ storeName, deleted: false, blocked: false, error: summarizeError(err).message });
|
|
1182
1317
|
return;
|
|
1183
1318
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1319
|
+
request2.onsuccess = () => finish({ storeName, deleted: true, blocked: false });
|
|
1320
|
+
request2.onerror = () => finish({
|
|
1186
1321
|
storeName,
|
|
1187
1322
|
deleted: false,
|
|
1188
1323
|
blocked: false,
|
|
1189
|
-
error: summarizeError(
|
|
1324
|
+
error: summarizeError(request2.error).message
|
|
1190
1325
|
});
|
|
1191
|
-
|
|
1326
|
+
request2.onblocked = () => {
|
|
1192
1327
|
blocked = true;
|
|
1193
1328
|
};
|
|
1194
1329
|
timer = setTimeout(() => {
|
|
@@ -2289,9 +2424,9 @@ function pickInstanceId(descriptor) {
|
|
|
2289
2424
|
function isMtimeSidecar(fileName) {
|
|
2290
2425
|
return fileName.endsWith(".mtime");
|
|
2291
2426
|
}
|
|
2292
|
-
var
|
|
2427
|
+
var S_IFDIR2 = 16384;
|
|
2293
2428
|
function isDirectory(stat) {
|
|
2294
|
-
return typeof stat.mode === "number" && (stat.mode &
|
|
2429
|
+
return typeof stat.mode === "number" && (stat.mode & S_IFDIR2) === S_IFDIR2;
|
|
2295
2430
|
}
|
|
2296
2431
|
function joinPath(dir, entry) {
|
|
2297
2432
|
if (dir === "/" || dir === "") return `/${entry}`;
|
|
@@ -2343,10 +2478,10 @@ async function purgeMtimeSidecars(fs, options = {}) {
|
|
|
2343
2478
|
function isKeepFile(fileName) {
|
|
2344
2479
|
return fileName === ".keep";
|
|
2345
2480
|
}
|
|
2346
|
-
var
|
|
2481
|
+
var S_IFDIR3 = 16384;
|
|
2347
2482
|
var DEFAULT_PROTECTED_DIRS = ["/.meta/backends/.keep"];
|
|
2348
2483
|
function isDirectory2(stat) {
|
|
2349
|
-
return typeof stat.mode === "number" && (stat.mode &
|
|
2484
|
+
return typeof stat.mode === "number" && (stat.mode & S_IFDIR3) === S_IFDIR3;
|
|
2350
2485
|
}
|
|
2351
2486
|
function joinPath2(dir, entry) {
|
|
2352
2487
|
if (dir === "/" || dir === "") return `/${entry}`;
|
|
@@ -2404,9 +2539,9 @@ async function purgeKeepFiles(fs, options = {}) {
|
|
|
2404
2539
|
}
|
|
2405
2540
|
|
|
2406
2541
|
// src/version-migration.ts
|
|
2407
|
-
var
|
|
2542
|
+
var S_IFDIR4 = 16384;
|
|
2408
2543
|
function isDir(stat) {
|
|
2409
|
-
return typeof stat.mode === "number" && (stat.mode &
|
|
2544
|
+
return typeof stat.mode === "number" && (stat.mode & S_IFDIR4) === S_IFDIR4;
|
|
2410
2545
|
}
|
|
2411
2546
|
function joinPath3(dir, entry) {
|
|
2412
2547
|
if (dir === "/" || dir === "") return `/${entry}`;
|
|
@@ -3006,6 +3141,40 @@ var ConfigRepo = class {
|
|
|
3006
3141
|
invalidateTombstoneCache() {
|
|
3007
3142
|
this.tombstoneCache = null;
|
|
3008
3143
|
}
|
|
3144
|
+
/**
|
|
3145
|
+
* 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
|
|
3146
|
+
*
|
|
3147
|
+
* 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
|
|
3148
|
+
* `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
|
|
3149
|
+
* 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
|
|
3150
|
+
* 因此在写入路径上即时撤销,并立即刷新排除表。
|
|
3151
|
+
*/
|
|
3152
|
+
async clearTombstonesForWrite(filePath) {
|
|
3153
|
+
let tombstones;
|
|
3154
|
+
try {
|
|
3155
|
+
tombstones = await this.readTombstones();
|
|
3156
|
+
} catch {
|
|
3157
|
+
return;
|
|
3158
|
+
}
|
|
3159
|
+
const normalized = normalizeTombstonePath(filePath);
|
|
3160
|
+
const affected = tombstones.filter((t) => {
|
|
3161
|
+
if (!t.path) return false;
|
|
3162
|
+
if (t.path === normalized) return true;
|
|
3163
|
+
return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
|
|
3164
|
+
});
|
|
3165
|
+
if (affected.length === 0) return;
|
|
3166
|
+
for (const tombstone of affected) {
|
|
3167
|
+
try {
|
|
3168
|
+
await this.cachedFS.unlink(tombstonePathFor(tombstone.path, TOMBSTONES_DIR));
|
|
3169
|
+
} catch {
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
this.invalidateTombstoneCache();
|
|
3173
|
+
await this.readTombstones();
|
|
3174
|
+
log5.log(
|
|
3175
|
+
`[ConfigRepo] cleared ${affected.length} tombstone(s) on write: ${normalized}`
|
|
3176
|
+
);
|
|
3177
|
+
}
|
|
3009
3178
|
/**
|
|
3010
3179
|
* 判定墓碑目标路径是否在删除之后被重新创建。
|
|
3011
3180
|
*
|
|
@@ -3774,6 +3943,7 @@ var ConfigRepo = class {
|
|
|
3774
3943
|
async persistConfig(fullPath, bytes) {
|
|
3775
3944
|
await this.ensureDir(fullPath);
|
|
3776
3945
|
await this.cachedFS.writeFile(fullPath, bytes);
|
|
3946
|
+
await this.clearTombstonesForWrite(fullPath);
|
|
3777
3947
|
const author = `${this.appId}/${this.nodeId}`;
|
|
3778
3948
|
const version = await incrementVersion(this.fullFS, fullPath, bytes, author);
|
|
3779
3949
|
await this.writeVersionSidecar(fullPath, version);
|
|
@@ -3931,6 +4101,7 @@ var ConfigRepo = class {
|
|
|
3931
4101
|
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
3932
4102
|
await this.ensureDir(p);
|
|
3933
4103
|
await this.cachedFS.writeFile(p, bytes);
|
|
4104
|
+
await this.clearTombstonesForWrite(p);
|
|
3934
4105
|
const author = `${this.appId}/${this.nodeId}`;
|
|
3935
4106
|
try {
|
|
3936
4107
|
const version = await incrementVersion(this.fullFS, p, bytes, author);
|
|
@@ -5162,7 +5333,10 @@ var AppDataGroupImpl = class {
|
|
|
5162
5333
|
}
|
|
5163
5334
|
this.fs = createChrootFS(this.localFS, "/", {
|
|
5164
5335
|
hiddenPrefixes: [META_DIR, CONFIG_DIR],
|
|
5165
|
-
onWrite: (path, data) =>
|
|
5336
|
+
onWrite: async (path, data) => {
|
|
5337
|
+
await this.clearTombstonesForWrite(path);
|
|
5338
|
+
await this.recordVersion(path, data);
|
|
5339
|
+
},
|
|
5166
5340
|
onUnlink: (path) => this.deleteFile(path),
|
|
5167
5341
|
onRmdir: (path) => this.deleteFile(path)
|
|
5168
5342
|
});
|
|
@@ -5318,6 +5492,34 @@ var AppDataGroupImpl = class {
|
|
|
5318
5492
|
this.tombstoneExcludePrefixes.push(tombstone.path, `${tombstone.path}/`);
|
|
5319
5493
|
}
|
|
5320
5494
|
}
|
|
5495
|
+
/**
|
|
5496
|
+
* 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
|
|
5497
|
+
*
|
|
5498
|
+
* 与配置组同一语义:墓碑是删除意图,重新写入是更强的意图;只靠 mtime 判定
|
|
5499
|
+
* 要等下一轮 tombstone pass 才解除排除,期间写入既不参与同步又可能被再删。
|
|
5500
|
+
*/
|
|
5501
|
+
async clearTombstonesForWrite(filePath) {
|
|
5502
|
+
try {
|
|
5503
|
+
const tombstones = await this.tombstones.list();
|
|
5504
|
+
const normalized = normalizeTombstonePath(filePath);
|
|
5505
|
+
const affected = tombstones.filter((t) => {
|
|
5506
|
+
if (!t.path) return false;
|
|
5507
|
+
if (t.path === normalized) return true;
|
|
5508
|
+
return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
|
|
5509
|
+
});
|
|
5510
|
+
if (affected.length === 0) return;
|
|
5511
|
+
for (const tombstone of affected) await this.tombstones.remove(tombstone);
|
|
5512
|
+
this.refreshSyncExclusions(await this.tombstones.list());
|
|
5513
|
+
log5.log(
|
|
5514
|
+
`[AppDataGroup:${this.groupId}] cleared ${affected.length} tombstone(s) on write: ${normalized}`
|
|
5515
|
+
);
|
|
5516
|
+
} catch (err) {
|
|
5517
|
+
log5.warn(
|
|
5518
|
+
`[AppDataGroup:${this.groupId}] clear tombstones on write failed for ${filePath}:`,
|
|
5519
|
+
err
|
|
5520
|
+
);
|
|
5521
|
+
}
|
|
5522
|
+
}
|
|
5321
5523
|
async confirmTombstones() {
|
|
5322
5524
|
try {
|
|
5323
5525
|
await this.tombstones.confirm(this.tombstoneTargets());
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
registerBackend,
|
|
10
10
|
unregisterBackend,
|
|
11
11
|
wrapZenFSFileSystem
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-OCPRJBM5.mjs";
|
|
13
13
|
|
|
14
14
|
// src/config-repo.ts
|
|
15
15
|
import {
|
|
@@ -465,7 +465,7 @@ function registerFolderBackend() {
|
|
|
465
465
|
const pathMod = await import("path");
|
|
466
466
|
const dir = options.path;
|
|
467
467
|
const store = new FolderStore({ path: dir, label: options.label, fs, pathMod });
|
|
468
|
-
return (await import("./backend-registry-
|
|
468
|
+
return (await import("./backend-registry-EKW4RVPI.mjs")).wrapZenFSFileSystem({ backend: FolderBackend, path: dir, label: options.label });
|
|
469
469
|
},
|
|
470
470
|
{
|
|
471
471
|
type: "Folder",
|
|
@@ -2431,6 +2431,40 @@ var ConfigRepo = class {
|
|
|
2431
2431
|
invalidateTombstoneCache() {
|
|
2432
2432
|
this.tombstoneCache = null;
|
|
2433
2433
|
}
|
|
2434
|
+
/**
|
|
2435
|
+
* 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
|
|
2436
|
+
*
|
|
2437
|
+
* 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
|
|
2438
|
+
* `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
|
|
2439
|
+
* 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
|
|
2440
|
+
* 因此在写入路径上即时撤销,并立即刷新排除表。
|
|
2441
|
+
*/
|
|
2442
|
+
async clearTombstonesForWrite(filePath) {
|
|
2443
|
+
let tombstones;
|
|
2444
|
+
try {
|
|
2445
|
+
tombstones = await this.readTombstones();
|
|
2446
|
+
} catch {
|
|
2447
|
+
return;
|
|
2448
|
+
}
|
|
2449
|
+
const normalized = normalizeTombstonePath(filePath);
|
|
2450
|
+
const affected = tombstones.filter((t) => {
|
|
2451
|
+
if (!t.path) return false;
|
|
2452
|
+
if (t.path === normalized) return true;
|
|
2453
|
+
return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
|
|
2454
|
+
});
|
|
2455
|
+
if (affected.length === 0) return;
|
|
2456
|
+
for (const tombstone of affected) {
|
|
2457
|
+
try {
|
|
2458
|
+
await this.cachedFS.unlink(tombstonePathFor(tombstone.path, TOMBSTONES_DIR));
|
|
2459
|
+
} catch {
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
this.invalidateTombstoneCache();
|
|
2463
|
+
await this.readTombstones();
|
|
2464
|
+
log5.log(
|
|
2465
|
+
`[ConfigRepo] cleared ${affected.length} tombstone(s) on write: ${normalized}`
|
|
2466
|
+
);
|
|
2467
|
+
}
|
|
2434
2468
|
/**
|
|
2435
2469
|
* 判定墓碑目标路径是否在删除之后被重新创建。
|
|
2436
2470
|
*
|
|
@@ -3199,6 +3233,7 @@ var ConfigRepo = class {
|
|
|
3199
3233
|
async persistConfig(fullPath, bytes) {
|
|
3200
3234
|
await this.ensureDir(fullPath);
|
|
3201
3235
|
await this.cachedFS.writeFile(fullPath, bytes);
|
|
3236
|
+
await this.clearTombstonesForWrite(fullPath);
|
|
3202
3237
|
const author = `${this.appId}/${this.nodeId}`;
|
|
3203
3238
|
const version = await incrementVersion(this.fullFS, fullPath, bytes, author);
|
|
3204
3239
|
await this.writeVersionSidecar(fullPath, version);
|
|
@@ -3356,6 +3391,7 @@ var ConfigRepo = class {
|
|
|
3356
3391
|
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
3357
3392
|
await this.ensureDir(p);
|
|
3358
3393
|
await this.cachedFS.writeFile(p, bytes);
|
|
3394
|
+
await this.clearTombstonesForWrite(p);
|
|
3359
3395
|
const author = `${this.appId}/${this.nodeId}`;
|
|
3360
3396
|
try {
|
|
3361
3397
|
const version = await incrementVersion(this.fullFS, p, bytes, author);
|
|
@@ -4587,7 +4623,10 @@ var AppDataGroupImpl = class {
|
|
|
4587
4623
|
}
|
|
4588
4624
|
this.fs = createChrootFS(this.localFS, "/", {
|
|
4589
4625
|
hiddenPrefixes: [META_DIR, CONFIG_DIR],
|
|
4590
|
-
onWrite: (path, data) =>
|
|
4626
|
+
onWrite: async (path, data) => {
|
|
4627
|
+
await this.clearTombstonesForWrite(path);
|
|
4628
|
+
await this.recordVersion(path, data);
|
|
4629
|
+
},
|
|
4591
4630
|
onUnlink: (path) => this.deleteFile(path),
|
|
4592
4631
|
onRmdir: (path) => this.deleteFile(path)
|
|
4593
4632
|
});
|
|
@@ -4743,6 +4782,34 @@ var AppDataGroupImpl = class {
|
|
|
4743
4782
|
this.tombstoneExcludePrefixes.push(tombstone.path, `${tombstone.path}/`);
|
|
4744
4783
|
}
|
|
4745
4784
|
}
|
|
4785
|
+
/**
|
|
4786
|
+
* 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
|
|
4787
|
+
*
|
|
4788
|
+
* 与配置组同一语义:墓碑是删除意图,重新写入是更强的意图;只靠 mtime 判定
|
|
4789
|
+
* 要等下一轮 tombstone pass 才解除排除,期间写入既不参与同步又可能被再删。
|
|
4790
|
+
*/
|
|
4791
|
+
async clearTombstonesForWrite(filePath) {
|
|
4792
|
+
try {
|
|
4793
|
+
const tombstones = await this.tombstones.list();
|
|
4794
|
+
const normalized = normalizeTombstonePath(filePath);
|
|
4795
|
+
const affected = tombstones.filter((t) => {
|
|
4796
|
+
if (!t.path) return false;
|
|
4797
|
+
if (t.path === normalized) return true;
|
|
4798
|
+
return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
|
|
4799
|
+
});
|
|
4800
|
+
if (affected.length === 0) return;
|
|
4801
|
+
for (const tombstone of affected) await this.tombstones.remove(tombstone);
|
|
4802
|
+
this.refreshSyncExclusions(await this.tombstones.list());
|
|
4803
|
+
log5.log(
|
|
4804
|
+
`[AppDataGroup:${this.groupId}] cleared ${affected.length} tombstone(s) on write: ${normalized}`
|
|
4805
|
+
);
|
|
4806
|
+
} catch (err) {
|
|
4807
|
+
log5.warn(
|
|
4808
|
+
`[AppDataGroup:${this.groupId}] clear tombstones on write failed for ${filePath}:`,
|
|
4809
|
+
err
|
|
4810
|
+
);
|
|
4811
|
+
}
|
|
4812
|
+
}
|
|
4746
4813
|
async confirmTombstones() {
|
|
4747
4814
|
try {
|
|
4748
4815
|
await this.tombstones.confirm(this.tombstoneTargets());
|