zen-fs-config 0.5.48 → 0.5.50
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/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +111 -16
- package/dist/index.mjs +111 -16
- package/dist/zen-fs-config.js +111 -16
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -954,6 +954,12 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
954
954
|
}): Promise<SyncResult>;
|
|
955
955
|
peekNodeConfig<T = unknown>(nodeId: string, path: string): Promise<T>;
|
|
956
956
|
flush(): Promise<SyncResult[]>;
|
|
957
|
+
/**
|
|
958
|
+
* Write the tombstone record for `filePath` (new `.meta/tombstones` + legacy
|
|
959
|
+
* mirror for one release cycle). Records only metadata — it never creates
|
|
960
|
+
* the deleted file locally.
|
|
961
|
+
*/
|
|
962
|
+
private writeTombstoneFor;
|
|
957
963
|
/**
|
|
958
964
|
* Delete a file and write a tombstone so the deletion propagates
|
|
959
965
|
* to all backends instead of being treated as "missing file → re-create".
|
package/dist/index.d.ts
CHANGED
|
@@ -954,6 +954,12 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
954
954
|
}): Promise<SyncResult>;
|
|
955
955
|
peekNodeConfig<T = unknown>(nodeId: string, path: string): Promise<T>;
|
|
956
956
|
flush(): Promise<SyncResult[]>;
|
|
957
|
+
/**
|
|
958
|
+
* Write the tombstone record for `filePath` (new `.meta/tombstones` + legacy
|
|
959
|
+
* mirror for one release cycle). Records only metadata — it never creates
|
|
960
|
+
* the deleted file locally.
|
|
961
|
+
*/
|
|
962
|
+
private writeTombstoneFor;
|
|
957
963
|
/**
|
|
958
964
|
* Delete a file and write a tombstone so the deletion propagates
|
|
959
965
|
* to all backends instead of being treated as "missing file → re-create".
|
package/dist/index.js
CHANGED
|
@@ -712,7 +712,10 @@ function createChrootFS(inner, root, options = {}) {
|
|
|
712
712
|
return inner.unlink(target);
|
|
713
713
|
},
|
|
714
714
|
async rmdir(path) {
|
|
715
|
-
|
|
715
|
+
const target = visible(path);
|
|
716
|
+
const hook = options.onRmdir ?? options.onUnlink;
|
|
717
|
+
if (hook) return hook(target);
|
|
718
|
+
return inner.rmdir?.(target);
|
|
716
719
|
},
|
|
717
720
|
async rename(oldPath, newPath) {
|
|
718
721
|
return inner.rename?.(visible(oldPath), visible(newPath));
|
|
@@ -1810,6 +1813,59 @@ var CONFIG_GROUP_FEATURES = {
|
|
|
1810
1813
|
configHost: true,
|
|
1811
1814
|
appData: false
|
|
1812
1815
|
};
|
|
1816
|
+
function isDirectoryMode(mode) {
|
|
1817
|
+
return typeof mode === "number" && (mode & 16384) === 16384;
|
|
1818
|
+
}
|
|
1819
|
+
async function isDirectoryPath(fs, absolutePath) {
|
|
1820
|
+
try {
|
|
1821
|
+
const st = await fs.stat(absolutePath);
|
|
1822
|
+
return isDirectoryMode(st?.mode);
|
|
1823
|
+
} catch {
|
|
1824
|
+
return false;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
async function collectFilesUnder(fs, dir, out = []) {
|
|
1828
|
+
const entries = await fs.readdir(dir);
|
|
1829
|
+
for (const entry of entries) {
|
|
1830
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
1831
|
+
if (await isDirectoryPath(fs, child)) {
|
|
1832
|
+
await collectFilesUnder(fs, child, out);
|
|
1833
|
+
} else {
|
|
1834
|
+
out.push(child);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
return out;
|
|
1838
|
+
}
|
|
1839
|
+
async function collectDirectoriesUnder(fs, dir, out = []) {
|
|
1840
|
+
out.push(dir);
|
|
1841
|
+
let entries;
|
|
1842
|
+
try {
|
|
1843
|
+
entries = await fs.readdir(dir);
|
|
1844
|
+
} catch {
|
|
1845
|
+
return out;
|
|
1846
|
+
}
|
|
1847
|
+
for (const entry of entries) {
|
|
1848
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
1849
|
+
if (await isDirectoryPath(fs, child)) await collectDirectoriesUnder(fs, child, out);
|
|
1850
|
+
}
|
|
1851
|
+
return out;
|
|
1852
|
+
}
|
|
1853
|
+
async function removeDirectoryTree(fs, dir) {
|
|
1854
|
+
let entries;
|
|
1855
|
+
try {
|
|
1856
|
+
entries = await fs.readdir(dir);
|
|
1857
|
+
} catch {
|
|
1858
|
+
return;
|
|
1859
|
+
}
|
|
1860
|
+
for (const entry of entries) {
|
|
1861
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
1862
|
+
if (await isDirectoryPath(fs, child)) await removeDirectoryTree(fs, child);
|
|
1863
|
+
}
|
|
1864
|
+
try {
|
|
1865
|
+
await fs.rmdir?.(dir);
|
|
1866
|
+
} catch {
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1813
1869
|
function normalizeGroupName(value) {
|
|
1814
1870
|
if (typeof value !== "string") {
|
|
1815
1871
|
throw new Error("Group name must be a string");
|
|
@@ -1937,7 +1993,10 @@ var ConfigRepo = class {
|
|
|
1937
1993
|
this.pollIntervalMs = pollIntervalMs;
|
|
1938
1994
|
this.cacheOptions = cacheOptions;
|
|
1939
1995
|
this.fullFS = backendToSyncableFS(cachedFS, primaryBackendId);
|
|
1940
|
-
this.fs = createChrootFS(cachedFS, `/${appId}
|
|
1996
|
+
this.fs = createChrootFS(cachedFS, `/${appId}`, {
|
|
1997
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
1998
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
1999
|
+
});
|
|
1941
2000
|
this.rootFS = createChrootFS(cachedFS, "/");
|
|
1942
2001
|
}
|
|
1943
2002
|
/** Full path to this node's directory on the primary backend. */
|
|
@@ -2102,12 +2161,12 @@ var ConfigRepo = class {
|
|
|
2102
2161
|
// Tombstone (Deletion Tracking)
|
|
2103
2162
|
// -----------------------------------------------------------------------
|
|
2104
2163
|
/**
|
|
2105
|
-
*
|
|
2106
|
-
*
|
|
2164
|
+
* Write the tombstone record for `filePath` (new `.meta/tombstones` + legacy
|
|
2165
|
+
* mirror for one release cycle). Records only metadata — it never creates
|
|
2166
|
+
* the deleted file locally.
|
|
2107
2167
|
*/
|
|
2108
|
-
async
|
|
2109
|
-
|
|
2110
|
-
const normalizedPath = path.startsWith("/") ? path : "/" + path;
|
|
2168
|
+
async writeTombstoneFor(filePath) {
|
|
2169
|
+
const normalizedPath = filePath.startsWith("/") ? filePath : "/" + filePath;
|
|
2111
2170
|
const tombstone = {
|
|
2112
2171
|
path: normalizedPath,
|
|
2113
2172
|
deletedAt: Date.now(),
|
|
@@ -2120,6 +2179,27 @@ var ConfigRepo = class {
|
|
|
2120
2179
|
await this.ensureDir(tombstonePath);
|
|
2121
2180
|
await this.cachedFS.writeFile(tombstonePath, tombstoneBytes);
|
|
2122
2181
|
}
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* Delete a file and write a tombstone so the deletion propagates
|
|
2185
|
+
* to all backends instead of being treated as "missing file → re-create".
|
|
2186
|
+
*/
|
|
2187
|
+
async deleteFile(path) {
|
|
2188
|
+
this.assertNotDisposed();
|
|
2189
|
+
const normalizedPath = path.startsWith("/") ? path : "/" + path;
|
|
2190
|
+
if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
|
|
2191
|
+
const files = await collectFilesUnder(this.cachedFS, normalizedPath);
|
|
2192
|
+
for (const file of files) await this.deleteFile(file);
|
|
2193
|
+
for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
|
|
2194
|
+
await this.writeTombstoneFor(dir === "/" ? "/.keep" : `${dir}/.keep`);
|
|
2195
|
+
}
|
|
2196
|
+
await removeDirectoryTree(this.cachedFS, normalizedPath);
|
|
2197
|
+
this.invalidateTombstoneCache();
|
|
2198
|
+
this.schedulePostDeleteSync();
|
|
2199
|
+
log2.log(`[ConfigRepo] deleteFile(directory): ${normalizedPath} (${files.length} file(s))`);
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
await this.writeTombstoneFor(normalizedPath);
|
|
2123
2203
|
try {
|
|
2124
2204
|
await this.cachedFS.unlink(normalizedPath);
|
|
2125
2205
|
} catch {
|
|
@@ -3755,7 +3835,8 @@ var AppDataGroupImpl = class {
|
|
|
3755
3835
|
this.fs = createChrootFS(this.localFS, "/", {
|
|
3756
3836
|
hiddenPrefixes: [META_DIR, CONFIG_DIR],
|
|
3757
3837
|
onWrite: (path, data) => this.recordVersion(path, data),
|
|
3758
|
-
onUnlink: (path) => this.deleteFile(path)
|
|
3838
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
3839
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
3759
3840
|
});
|
|
3760
3841
|
const { kept, removed } = dedupeAppDataBackends(this._backends);
|
|
3761
3842
|
if (removed.length > 0) {
|
|
@@ -3868,6 +3949,15 @@ var AppDataGroupImpl = class {
|
|
|
3868
3949
|
log2.warn(`[AppDataGroup:${this.groupId}] tombstone confirmations failed:`, err);
|
|
3869
3950
|
}
|
|
3870
3951
|
}
|
|
3952
|
+
/** Write a tombstone for `filePath`. Records metadata only — it never creates the file. */
|
|
3953
|
+
async writeTombstoneFor(filePath) {
|
|
3954
|
+
await this.tombstones.write({
|
|
3955
|
+
path: filePath.startsWith("/") ? filePath : `/${filePath}`,
|
|
3956
|
+
deletedAt: Date.now(),
|
|
3957
|
+
deletedBy: this.localBackendId,
|
|
3958
|
+
confirmedBy: [this.localBackendId]
|
|
3959
|
+
});
|
|
3960
|
+
}
|
|
3871
3961
|
/**
|
|
3872
3962
|
* Delete a data file with a tombstone in `.meta/tombstones/`.
|
|
3873
3963
|
* The tombstone is synced (`.meta/` is no longer excluded), so the deletion
|
|
@@ -3876,16 +3966,21 @@ var AppDataGroupImpl = class {
|
|
|
3876
3966
|
async deleteFile(path) {
|
|
3877
3967
|
if (this.disposed) throw new Error("DataSyncGroup has been disposed");
|
|
3878
3968
|
const normalized = path.startsWith("/") ? path : `/${path}`;
|
|
3879
|
-
if (normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
3969
|
+
if (normalized === META_DIR || normalized === CONFIG_DIR || normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
3880
3970
|
throw new Error(`Cannot delete metadata path "${normalized}"`);
|
|
3881
3971
|
}
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3972
|
+
if (await isDirectoryPath(this.localFS, normalized)) {
|
|
3973
|
+
const files = await collectFilesUnder(this.localFS, normalized);
|
|
3974
|
+
for (const file of files) await this.deleteFile(file);
|
|
3975
|
+
for (const dir of await collectDirectoriesUnder(this.localFS, normalized)) {
|
|
3976
|
+
await this.writeTombstoneFor(dir === "/" ? "/.keep" : `${dir}/.keep`);
|
|
3977
|
+
}
|
|
3978
|
+
await removeDirectoryTree(this.localFS, normalized);
|
|
3979
|
+
this.schedulePostDeleteSync();
|
|
3980
|
+
log2.log(`[AppDataGroup:${this.groupId}] deleteFile(directory): ${normalized} (${files.length} file(s))`);
|
|
3981
|
+
return;
|
|
3982
|
+
}
|
|
3983
|
+
await this.writeTombstoneFor(normalized);
|
|
3889
3984
|
try {
|
|
3890
3985
|
await this.localFS.unlink(normalized);
|
|
3891
3986
|
} catch {
|
package/dist/index.mjs
CHANGED
|
@@ -161,7 +161,10 @@ function createChrootFS(inner, root, options = {}) {
|
|
|
161
161
|
return inner.unlink(target);
|
|
162
162
|
},
|
|
163
163
|
async rmdir(path) {
|
|
164
|
-
|
|
164
|
+
const target = visible(path);
|
|
165
|
+
const hook = options.onRmdir ?? options.onUnlink;
|
|
166
|
+
if (hook) return hook(target);
|
|
167
|
+
return inner.rmdir?.(target);
|
|
165
168
|
},
|
|
166
169
|
async rename(oldPath, newPath) {
|
|
167
170
|
return inner.rename?.(visible(oldPath), visible(newPath));
|
|
@@ -1255,6 +1258,59 @@ var CONFIG_GROUP_FEATURES = {
|
|
|
1255
1258
|
configHost: true,
|
|
1256
1259
|
appData: false
|
|
1257
1260
|
};
|
|
1261
|
+
function isDirectoryMode(mode) {
|
|
1262
|
+
return typeof mode === "number" && (mode & 16384) === 16384;
|
|
1263
|
+
}
|
|
1264
|
+
async function isDirectoryPath(fs, absolutePath) {
|
|
1265
|
+
try {
|
|
1266
|
+
const st = await fs.stat(absolutePath);
|
|
1267
|
+
return isDirectoryMode(st?.mode);
|
|
1268
|
+
} catch {
|
|
1269
|
+
return false;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
async function collectFilesUnder(fs, dir, out = []) {
|
|
1273
|
+
const entries = await fs.readdir(dir);
|
|
1274
|
+
for (const entry of entries) {
|
|
1275
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
1276
|
+
if (await isDirectoryPath(fs, child)) {
|
|
1277
|
+
await collectFilesUnder(fs, child, out);
|
|
1278
|
+
} else {
|
|
1279
|
+
out.push(child);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
return out;
|
|
1283
|
+
}
|
|
1284
|
+
async function collectDirectoriesUnder(fs, dir, out = []) {
|
|
1285
|
+
out.push(dir);
|
|
1286
|
+
let entries;
|
|
1287
|
+
try {
|
|
1288
|
+
entries = await fs.readdir(dir);
|
|
1289
|
+
} catch {
|
|
1290
|
+
return out;
|
|
1291
|
+
}
|
|
1292
|
+
for (const entry of entries) {
|
|
1293
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
1294
|
+
if (await isDirectoryPath(fs, child)) await collectDirectoriesUnder(fs, child, out);
|
|
1295
|
+
}
|
|
1296
|
+
return out;
|
|
1297
|
+
}
|
|
1298
|
+
async function removeDirectoryTree(fs, dir) {
|
|
1299
|
+
let entries;
|
|
1300
|
+
try {
|
|
1301
|
+
entries = await fs.readdir(dir);
|
|
1302
|
+
} catch {
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
for (const entry of entries) {
|
|
1306
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
1307
|
+
if (await isDirectoryPath(fs, child)) await removeDirectoryTree(fs, child);
|
|
1308
|
+
}
|
|
1309
|
+
try {
|
|
1310
|
+
await fs.rmdir?.(dir);
|
|
1311
|
+
} catch {
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1258
1314
|
function normalizeGroupName(value) {
|
|
1259
1315
|
if (typeof value !== "string") {
|
|
1260
1316
|
throw new Error("Group name must be a string");
|
|
@@ -1382,7 +1438,10 @@ var ConfigRepo = class {
|
|
|
1382
1438
|
this.pollIntervalMs = pollIntervalMs;
|
|
1383
1439
|
this.cacheOptions = cacheOptions;
|
|
1384
1440
|
this.fullFS = backendToSyncableFS(cachedFS, primaryBackendId);
|
|
1385
|
-
this.fs = createChrootFS(cachedFS, `/${appId}
|
|
1441
|
+
this.fs = createChrootFS(cachedFS, `/${appId}`, {
|
|
1442
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
1443
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
1444
|
+
});
|
|
1386
1445
|
this.rootFS = createChrootFS(cachedFS, "/");
|
|
1387
1446
|
}
|
|
1388
1447
|
/** Full path to this node's directory on the primary backend. */
|
|
@@ -1547,12 +1606,12 @@ var ConfigRepo = class {
|
|
|
1547
1606
|
// Tombstone (Deletion Tracking)
|
|
1548
1607
|
// -----------------------------------------------------------------------
|
|
1549
1608
|
/**
|
|
1550
|
-
*
|
|
1551
|
-
*
|
|
1609
|
+
* Write the tombstone record for `filePath` (new `.meta/tombstones` + legacy
|
|
1610
|
+
* mirror for one release cycle). Records only metadata — it never creates
|
|
1611
|
+
* the deleted file locally.
|
|
1552
1612
|
*/
|
|
1553
|
-
async
|
|
1554
|
-
|
|
1555
|
-
const normalizedPath = path.startsWith("/") ? path : "/" + path;
|
|
1613
|
+
async writeTombstoneFor(filePath) {
|
|
1614
|
+
const normalizedPath = filePath.startsWith("/") ? filePath : "/" + filePath;
|
|
1556
1615
|
const tombstone = {
|
|
1557
1616
|
path: normalizedPath,
|
|
1558
1617
|
deletedAt: Date.now(),
|
|
@@ -1565,6 +1624,27 @@ var ConfigRepo = class {
|
|
|
1565
1624
|
await this.ensureDir(tombstonePath);
|
|
1566
1625
|
await this.cachedFS.writeFile(tombstonePath, tombstoneBytes);
|
|
1567
1626
|
}
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1629
|
+
* Delete a file and write a tombstone so the deletion propagates
|
|
1630
|
+
* to all backends instead of being treated as "missing file → re-create".
|
|
1631
|
+
*/
|
|
1632
|
+
async deleteFile(path) {
|
|
1633
|
+
this.assertNotDisposed();
|
|
1634
|
+
const normalizedPath = path.startsWith("/") ? path : "/" + path;
|
|
1635
|
+
if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
|
|
1636
|
+
const files = await collectFilesUnder(this.cachedFS, normalizedPath);
|
|
1637
|
+
for (const file of files) await this.deleteFile(file);
|
|
1638
|
+
for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
|
|
1639
|
+
await this.writeTombstoneFor(dir === "/" ? "/.keep" : `${dir}/.keep`);
|
|
1640
|
+
}
|
|
1641
|
+
await removeDirectoryTree(this.cachedFS, normalizedPath);
|
|
1642
|
+
this.invalidateTombstoneCache();
|
|
1643
|
+
this.schedulePostDeleteSync();
|
|
1644
|
+
log2.log(`[ConfigRepo] deleteFile(directory): ${normalizedPath} (${files.length} file(s))`);
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
await this.writeTombstoneFor(normalizedPath);
|
|
1568
1648
|
try {
|
|
1569
1649
|
await this.cachedFS.unlink(normalizedPath);
|
|
1570
1650
|
} catch {
|
|
@@ -3200,7 +3280,8 @@ var AppDataGroupImpl = class {
|
|
|
3200
3280
|
this.fs = createChrootFS(this.localFS, "/", {
|
|
3201
3281
|
hiddenPrefixes: [META_DIR, CONFIG_DIR],
|
|
3202
3282
|
onWrite: (path, data) => this.recordVersion(path, data),
|
|
3203
|
-
onUnlink: (path) => this.deleteFile(path)
|
|
3283
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
3284
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
3204
3285
|
});
|
|
3205
3286
|
const { kept, removed } = dedupeAppDataBackends(this._backends);
|
|
3206
3287
|
if (removed.length > 0) {
|
|
@@ -3313,6 +3394,15 @@ var AppDataGroupImpl = class {
|
|
|
3313
3394
|
log2.warn(`[AppDataGroup:${this.groupId}] tombstone confirmations failed:`, err);
|
|
3314
3395
|
}
|
|
3315
3396
|
}
|
|
3397
|
+
/** Write a tombstone for `filePath`. Records metadata only — it never creates the file. */
|
|
3398
|
+
async writeTombstoneFor(filePath) {
|
|
3399
|
+
await this.tombstones.write({
|
|
3400
|
+
path: filePath.startsWith("/") ? filePath : `/${filePath}`,
|
|
3401
|
+
deletedAt: Date.now(),
|
|
3402
|
+
deletedBy: this.localBackendId,
|
|
3403
|
+
confirmedBy: [this.localBackendId]
|
|
3404
|
+
});
|
|
3405
|
+
}
|
|
3316
3406
|
/**
|
|
3317
3407
|
* Delete a data file with a tombstone in `.meta/tombstones/`.
|
|
3318
3408
|
* The tombstone is synced (`.meta/` is no longer excluded), so the deletion
|
|
@@ -3321,16 +3411,21 @@ var AppDataGroupImpl = class {
|
|
|
3321
3411
|
async deleteFile(path) {
|
|
3322
3412
|
if (this.disposed) throw new Error("DataSyncGroup has been disposed");
|
|
3323
3413
|
const normalized = path.startsWith("/") ? path : `/${path}`;
|
|
3324
|
-
if (normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
3414
|
+
if (normalized === META_DIR || normalized === CONFIG_DIR || normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
3325
3415
|
throw new Error(`Cannot delete metadata path "${normalized}"`);
|
|
3326
3416
|
}
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3417
|
+
if (await isDirectoryPath(this.localFS, normalized)) {
|
|
3418
|
+
const files = await collectFilesUnder(this.localFS, normalized);
|
|
3419
|
+
for (const file of files) await this.deleteFile(file);
|
|
3420
|
+
for (const dir of await collectDirectoriesUnder(this.localFS, normalized)) {
|
|
3421
|
+
await this.writeTombstoneFor(dir === "/" ? "/.keep" : `${dir}/.keep`);
|
|
3422
|
+
}
|
|
3423
|
+
await removeDirectoryTree(this.localFS, normalized);
|
|
3424
|
+
this.schedulePostDeleteSync();
|
|
3425
|
+
log2.log(`[AppDataGroup:${this.groupId}] deleteFile(directory): ${normalized} (${files.length} file(s))`);
|
|
3426
|
+
return;
|
|
3427
|
+
}
|
|
3428
|
+
await this.writeTombstoneFor(normalized);
|
|
3334
3429
|
try {
|
|
3335
3430
|
await this.localFS.unlink(normalized);
|
|
3336
3431
|
} catch {
|
package/dist/zen-fs-config.js
CHANGED
|
@@ -26741,7 +26741,10 @@ var ZenFSConfig = (() => {
|
|
|
26741
26741
|
return inner.unlink(target);
|
|
26742
26742
|
},
|
|
26743
26743
|
async rmdir(path) {
|
|
26744
|
-
|
|
26744
|
+
const target = visible(path);
|
|
26745
|
+
const hook = options.onRmdir ?? options.onUnlink;
|
|
26746
|
+
if (hook) return hook(target);
|
|
26747
|
+
return inner.rmdir?.(target);
|
|
26745
26748
|
},
|
|
26746
26749
|
async rename(oldPath, newPath) {
|
|
26747
26750
|
return inner.rename?.(visible(oldPath), visible(newPath));
|
|
@@ -27827,6 +27830,59 @@ var ZenFSConfig = (() => {
|
|
|
27827
27830
|
configHost: true,
|
|
27828
27831
|
appData: false
|
|
27829
27832
|
};
|
|
27833
|
+
function isDirectoryMode(mode) {
|
|
27834
|
+
return typeof mode === "number" && (mode & 16384) === 16384;
|
|
27835
|
+
}
|
|
27836
|
+
async function isDirectoryPath(fs, absolutePath) {
|
|
27837
|
+
try {
|
|
27838
|
+
const st = await fs.stat(absolutePath);
|
|
27839
|
+
return isDirectoryMode(st?.mode);
|
|
27840
|
+
} catch {
|
|
27841
|
+
return false;
|
|
27842
|
+
}
|
|
27843
|
+
}
|
|
27844
|
+
async function collectFilesUnder(fs, dir, out = []) {
|
|
27845
|
+
const entries2 = await fs.readdir(dir);
|
|
27846
|
+
for (const entry of entries2) {
|
|
27847
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
27848
|
+
if (await isDirectoryPath(fs, child)) {
|
|
27849
|
+
await collectFilesUnder(fs, child, out);
|
|
27850
|
+
} else {
|
|
27851
|
+
out.push(child);
|
|
27852
|
+
}
|
|
27853
|
+
}
|
|
27854
|
+
return out;
|
|
27855
|
+
}
|
|
27856
|
+
async function collectDirectoriesUnder(fs, dir, out = []) {
|
|
27857
|
+
out.push(dir);
|
|
27858
|
+
let entries2;
|
|
27859
|
+
try {
|
|
27860
|
+
entries2 = await fs.readdir(dir);
|
|
27861
|
+
} catch {
|
|
27862
|
+
return out;
|
|
27863
|
+
}
|
|
27864
|
+
for (const entry of entries2) {
|
|
27865
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
27866
|
+
if (await isDirectoryPath(fs, child)) await collectDirectoriesUnder(fs, child, out);
|
|
27867
|
+
}
|
|
27868
|
+
return out;
|
|
27869
|
+
}
|
|
27870
|
+
async function removeDirectoryTree(fs, dir) {
|
|
27871
|
+
let entries2;
|
|
27872
|
+
try {
|
|
27873
|
+
entries2 = await fs.readdir(dir);
|
|
27874
|
+
} catch {
|
|
27875
|
+
return;
|
|
27876
|
+
}
|
|
27877
|
+
for (const entry of entries2) {
|
|
27878
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
27879
|
+
if (await isDirectoryPath(fs, child)) await removeDirectoryTree(fs, child);
|
|
27880
|
+
}
|
|
27881
|
+
try {
|
|
27882
|
+
await fs.rmdir?.(dir);
|
|
27883
|
+
} catch {
|
|
27884
|
+
}
|
|
27885
|
+
}
|
|
27830
27886
|
function normalizeGroupName(value) {
|
|
27831
27887
|
if (typeof value !== "string") {
|
|
27832
27888
|
throw new Error("Group name must be a string");
|
|
@@ -27960,7 +28016,10 @@ var ZenFSConfig = (() => {
|
|
|
27960
28016
|
this.pollIntervalMs = pollIntervalMs;
|
|
27961
28017
|
this.cacheOptions = cacheOptions;
|
|
27962
28018
|
this.fullFS = backendToSyncableFS(cachedFS, primaryBackendId);
|
|
27963
|
-
this.fs = createChrootFS(cachedFS, `/${appId}
|
|
28019
|
+
this.fs = createChrootFS(cachedFS, `/${appId}`, {
|
|
28020
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
28021
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
28022
|
+
});
|
|
27964
28023
|
this.rootFS = createChrootFS(cachedFS, "/");
|
|
27965
28024
|
}
|
|
27966
28025
|
/** Full path to this node's directory on the primary backend. */
|
|
@@ -28125,12 +28184,12 @@ var ZenFSConfig = (() => {
|
|
|
28125
28184
|
// Tombstone (Deletion Tracking)
|
|
28126
28185
|
// -----------------------------------------------------------------------
|
|
28127
28186
|
/**
|
|
28128
|
-
*
|
|
28129
|
-
*
|
|
28187
|
+
* Write the tombstone record for `filePath` (new `.meta/tombstones` + legacy
|
|
28188
|
+
* mirror for one release cycle). Records only metadata — it never creates
|
|
28189
|
+
* the deleted file locally.
|
|
28130
28190
|
*/
|
|
28131
|
-
async
|
|
28132
|
-
|
|
28133
|
-
const normalizedPath = path.startsWith("/") ? path : "/" + path;
|
|
28191
|
+
async writeTombstoneFor(filePath) {
|
|
28192
|
+
const normalizedPath = filePath.startsWith("/") ? filePath : "/" + filePath;
|
|
28134
28193
|
const tombstone = {
|
|
28135
28194
|
path: normalizedPath,
|
|
28136
28195
|
deletedAt: Date.now(),
|
|
@@ -28143,6 +28202,27 @@ var ZenFSConfig = (() => {
|
|
|
28143
28202
|
await this.ensureDir(tombstonePath);
|
|
28144
28203
|
await this.cachedFS.writeFile(tombstonePath, tombstoneBytes);
|
|
28145
28204
|
}
|
|
28205
|
+
}
|
|
28206
|
+
/**
|
|
28207
|
+
* Delete a file and write a tombstone so the deletion propagates
|
|
28208
|
+
* to all backends instead of being treated as "missing file → re-create".
|
|
28209
|
+
*/
|
|
28210
|
+
async deleteFile(path) {
|
|
28211
|
+
this.assertNotDisposed();
|
|
28212
|
+
const normalizedPath = path.startsWith("/") ? path : "/" + path;
|
|
28213
|
+
if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
|
|
28214
|
+
const files = await collectFilesUnder(this.cachedFS, normalizedPath);
|
|
28215
|
+
for (const file of files) await this.deleteFile(file);
|
|
28216
|
+
for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
|
|
28217
|
+
await this.writeTombstoneFor(dir === "/" ? "/.keep" : `${dir}/.keep`);
|
|
28218
|
+
}
|
|
28219
|
+
await removeDirectoryTree(this.cachedFS, normalizedPath);
|
|
28220
|
+
this.invalidateTombstoneCache();
|
|
28221
|
+
this.schedulePostDeleteSync();
|
|
28222
|
+
log6.log(`[ConfigRepo] deleteFile(directory): ${normalizedPath} (${files.length} file(s))`);
|
|
28223
|
+
return;
|
|
28224
|
+
}
|
|
28225
|
+
await this.writeTombstoneFor(normalizedPath);
|
|
28146
28226
|
try {
|
|
28147
28227
|
await this.cachedFS.unlink(normalizedPath);
|
|
28148
28228
|
} catch {
|
|
@@ -29772,7 +29852,8 @@ var ZenFSConfig = (() => {
|
|
|
29772
29852
|
this.fs = createChrootFS(this.localFS, "/", {
|
|
29773
29853
|
hiddenPrefixes: [META_DIR, CONFIG_DIR],
|
|
29774
29854
|
onWrite: (path, data) => this.recordVersion(path, data),
|
|
29775
|
-
onUnlink: (path) => this.deleteFile(path)
|
|
29855
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
29856
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
29776
29857
|
});
|
|
29777
29858
|
const { kept, removed } = dedupeAppDataBackends(this._backends);
|
|
29778
29859
|
if (removed.length > 0) {
|
|
@@ -29885,6 +29966,15 @@ var ZenFSConfig = (() => {
|
|
|
29885
29966
|
log6.warn(`[AppDataGroup:${this.groupId}] tombstone confirmations failed:`, err2);
|
|
29886
29967
|
}
|
|
29887
29968
|
}
|
|
29969
|
+
/** Write a tombstone for `filePath`. Records metadata only — it never creates the file. */
|
|
29970
|
+
async writeTombstoneFor(filePath) {
|
|
29971
|
+
await this.tombstones.write({
|
|
29972
|
+
path: filePath.startsWith("/") ? filePath : `/${filePath}`,
|
|
29973
|
+
deletedAt: Date.now(),
|
|
29974
|
+
deletedBy: this.localBackendId,
|
|
29975
|
+
confirmedBy: [this.localBackendId]
|
|
29976
|
+
});
|
|
29977
|
+
}
|
|
29888
29978
|
/**
|
|
29889
29979
|
* Delete a data file with a tombstone in `.meta/tombstones/`.
|
|
29890
29980
|
* The tombstone is synced (`.meta/` is no longer excluded), so the deletion
|
|
@@ -29893,16 +29983,21 @@ var ZenFSConfig = (() => {
|
|
|
29893
29983
|
async deleteFile(path) {
|
|
29894
29984
|
if (this.disposed) throw new Error("DataSyncGroup has been disposed");
|
|
29895
29985
|
const normalized = path.startsWith("/") ? path : `/${path}`;
|
|
29896
|
-
if (normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
29986
|
+
if (normalized === META_DIR || normalized === CONFIG_DIR || normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
29897
29987
|
throw new Error(`Cannot delete metadata path "${normalized}"`);
|
|
29898
29988
|
}
|
|
29899
|
-
|
|
29900
|
-
|
|
29901
|
-
|
|
29902
|
-
|
|
29903
|
-
|
|
29904
|
-
|
|
29905
|
-
|
|
29989
|
+
if (await isDirectoryPath(this.localFS, normalized)) {
|
|
29990
|
+
const files = await collectFilesUnder(this.localFS, normalized);
|
|
29991
|
+
for (const file of files) await this.deleteFile(file);
|
|
29992
|
+
for (const dir of await collectDirectoriesUnder(this.localFS, normalized)) {
|
|
29993
|
+
await this.writeTombstoneFor(dir === "/" ? "/.keep" : `${dir}/.keep`);
|
|
29994
|
+
}
|
|
29995
|
+
await removeDirectoryTree(this.localFS, normalized);
|
|
29996
|
+
this.schedulePostDeleteSync();
|
|
29997
|
+
log6.log(`[AppDataGroup:${this.groupId}] deleteFile(directory): ${normalized} (${files.length} file(s))`);
|
|
29998
|
+
return;
|
|
29999
|
+
}
|
|
30000
|
+
await this.writeTombstoneFor(normalized);
|
|
29906
30001
|
try {
|
|
29907
30002
|
await this.localFS.unlink(normalized);
|
|
29908
30003
|
} catch {
|