zen-fs-config 0.5.48 → 0.5.49
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.js +67 -4
- package/dist/index.mjs +67 -4
- package/dist/zen-fs-config.js +67 -4
- package/package.json +1 -1
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,45 @@ 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 removeDirectoryTree(fs, dir) {
|
|
1840
|
+
let entries;
|
|
1841
|
+
try {
|
|
1842
|
+
entries = await fs.readdir(dir);
|
|
1843
|
+
} catch {
|
|
1844
|
+
return;
|
|
1845
|
+
}
|
|
1846
|
+
for (const entry of entries) {
|
|
1847
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
1848
|
+
if (await isDirectoryPath(fs, child)) await removeDirectoryTree(fs, child);
|
|
1849
|
+
}
|
|
1850
|
+
try {
|
|
1851
|
+
await fs.rmdir?.(dir);
|
|
1852
|
+
} catch {
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1813
1855
|
function normalizeGroupName(value) {
|
|
1814
1856
|
if (typeof value !== "string") {
|
|
1815
1857
|
throw new Error("Group name must be a string");
|
|
@@ -1937,7 +1979,10 @@ var ConfigRepo = class {
|
|
|
1937
1979
|
this.pollIntervalMs = pollIntervalMs;
|
|
1938
1980
|
this.cacheOptions = cacheOptions;
|
|
1939
1981
|
this.fullFS = backendToSyncableFS(cachedFS, primaryBackendId);
|
|
1940
|
-
this.fs = createChrootFS(cachedFS, `/${appId}
|
|
1982
|
+
this.fs = createChrootFS(cachedFS, `/${appId}`, {
|
|
1983
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
1984
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
1985
|
+
});
|
|
1941
1986
|
this.rootFS = createChrootFS(cachedFS, "/");
|
|
1942
1987
|
}
|
|
1943
1988
|
/** Full path to this node's directory on the primary backend. */
|
|
@@ -2108,6 +2153,15 @@ var ConfigRepo = class {
|
|
|
2108
2153
|
async deleteFile(path) {
|
|
2109
2154
|
this.assertNotDisposed();
|
|
2110
2155
|
const normalizedPath = path.startsWith("/") ? path : "/" + path;
|
|
2156
|
+
if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
|
|
2157
|
+
const files = await collectFilesUnder(this.cachedFS, normalizedPath);
|
|
2158
|
+
for (const file of files) await this.deleteFile(file);
|
|
2159
|
+
await removeDirectoryTree(this.cachedFS, normalizedPath);
|
|
2160
|
+
this.invalidateTombstoneCache();
|
|
2161
|
+
this.schedulePostDeleteSync();
|
|
2162
|
+
log2.log(`[ConfigRepo] deleteFile(directory): ${normalizedPath} (${files.length} file(s))`);
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2111
2165
|
const tombstone = {
|
|
2112
2166
|
path: normalizedPath,
|
|
2113
2167
|
deletedAt: Date.now(),
|
|
@@ -3755,7 +3809,8 @@ var AppDataGroupImpl = class {
|
|
|
3755
3809
|
this.fs = createChrootFS(this.localFS, "/", {
|
|
3756
3810
|
hiddenPrefixes: [META_DIR, CONFIG_DIR],
|
|
3757
3811
|
onWrite: (path, data) => this.recordVersion(path, data),
|
|
3758
|
-
onUnlink: (path) => this.deleteFile(path)
|
|
3812
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
3813
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
3759
3814
|
});
|
|
3760
3815
|
const { kept, removed } = dedupeAppDataBackends(this._backends);
|
|
3761
3816
|
if (removed.length > 0) {
|
|
@@ -3876,9 +3931,17 @@ var AppDataGroupImpl = class {
|
|
|
3876
3931
|
async deleteFile(path) {
|
|
3877
3932
|
if (this.disposed) throw new Error("DataSyncGroup has been disposed");
|
|
3878
3933
|
const normalized = path.startsWith("/") ? path : `/${path}`;
|
|
3879
|
-
if (normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
3934
|
+
if (normalized === META_DIR || normalized === CONFIG_DIR || normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
3880
3935
|
throw new Error(`Cannot delete metadata path "${normalized}"`);
|
|
3881
3936
|
}
|
|
3937
|
+
if (await isDirectoryPath(this.localFS, normalized)) {
|
|
3938
|
+
const files = await collectFilesUnder(this.localFS, normalized);
|
|
3939
|
+
for (const file of files) await this.deleteFile(file);
|
|
3940
|
+
await removeDirectoryTree(this.localFS, normalized);
|
|
3941
|
+
this.schedulePostDeleteSync();
|
|
3942
|
+
log2.log(`[AppDataGroup:${this.groupId}] deleteFile(directory): ${normalized} (${files.length} file(s))`);
|
|
3943
|
+
return;
|
|
3944
|
+
}
|
|
3882
3945
|
const tombstone = {
|
|
3883
3946
|
path: normalized,
|
|
3884
3947
|
deletedAt: Date.now(),
|
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,45 @@ 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 removeDirectoryTree(fs, dir) {
|
|
1285
|
+
let entries;
|
|
1286
|
+
try {
|
|
1287
|
+
entries = await fs.readdir(dir);
|
|
1288
|
+
} catch {
|
|
1289
|
+
return;
|
|
1290
|
+
}
|
|
1291
|
+
for (const entry of entries) {
|
|
1292
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
1293
|
+
if (await isDirectoryPath(fs, child)) await removeDirectoryTree(fs, child);
|
|
1294
|
+
}
|
|
1295
|
+
try {
|
|
1296
|
+
await fs.rmdir?.(dir);
|
|
1297
|
+
} catch {
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1258
1300
|
function normalizeGroupName(value) {
|
|
1259
1301
|
if (typeof value !== "string") {
|
|
1260
1302
|
throw new Error("Group name must be a string");
|
|
@@ -1382,7 +1424,10 @@ var ConfigRepo = class {
|
|
|
1382
1424
|
this.pollIntervalMs = pollIntervalMs;
|
|
1383
1425
|
this.cacheOptions = cacheOptions;
|
|
1384
1426
|
this.fullFS = backendToSyncableFS(cachedFS, primaryBackendId);
|
|
1385
|
-
this.fs = createChrootFS(cachedFS, `/${appId}
|
|
1427
|
+
this.fs = createChrootFS(cachedFS, `/${appId}`, {
|
|
1428
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
1429
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
1430
|
+
});
|
|
1386
1431
|
this.rootFS = createChrootFS(cachedFS, "/");
|
|
1387
1432
|
}
|
|
1388
1433
|
/** Full path to this node's directory on the primary backend. */
|
|
@@ -1553,6 +1598,15 @@ var ConfigRepo = class {
|
|
|
1553
1598
|
async deleteFile(path) {
|
|
1554
1599
|
this.assertNotDisposed();
|
|
1555
1600
|
const normalizedPath = path.startsWith("/") ? path : "/" + path;
|
|
1601
|
+
if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
|
|
1602
|
+
const files = await collectFilesUnder(this.cachedFS, normalizedPath);
|
|
1603
|
+
for (const file of files) await this.deleteFile(file);
|
|
1604
|
+
await removeDirectoryTree(this.cachedFS, normalizedPath);
|
|
1605
|
+
this.invalidateTombstoneCache();
|
|
1606
|
+
this.schedulePostDeleteSync();
|
|
1607
|
+
log2.log(`[ConfigRepo] deleteFile(directory): ${normalizedPath} (${files.length} file(s))`);
|
|
1608
|
+
return;
|
|
1609
|
+
}
|
|
1556
1610
|
const tombstone = {
|
|
1557
1611
|
path: normalizedPath,
|
|
1558
1612
|
deletedAt: Date.now(),
|
|
@@ -3200,7 +3254,8 @@ var AppDataGroupImpl = class {
|
|
|
3200
3254
|
this.fs = createChrootFS(this.localFS, "/", {
|
|
3201
3255
|
hiddenPrefixes: [META_DIR, CONFIG_DIR],
|
|
3202
3256
|
onWrite: (path, data) => this.recordVersion(path, data),
|
|
3203
|
-
onUnlink: (path) => this.deleteFile(path)
|
|
3257
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
3258
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
3204
3259
|
});
|
|
3205
3260
|
const { kept, removed } = dedupeAppDataBackends(this._backends);
|
|
3206
3261
|
if (removed.length > 0) {
|
|
@@ -3321,9 +3376,17 @@ var AppDataGroupImpl = class {
|
|
|
3321
3376
|
async deleteFile(path) {
|
|
3322
3377
|
if (this.disposed) throw new Error("DataSyncGroup has been disposed");
|
|
3323
3378
|
const normalized = path.startsWith("/") ? path : `/${path}`;
|
|
3324
|
-
if (normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
3379
|
+
if (normalized === META_DIR || normalized === CONFIG_DIR || normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
3325
3380
|
throw new Error(`Cannot delete metadata path "${normalized}"`);
|
|
3326
3381
|
}
|
|
3382
|
+
if (await isDirectoryPath(this.localFS, normalized)) {
|
|
3383
|
+
const files = await collectFilesUnder(this.localFS, normalized);
|
|
3384
|
+
for (const file of files) await this.deleteFile(file);
|
|
3385
|
+
await removeDirectoryTree(this.localFS, normalized);
|
|
3386
|
+
this.schedulePostDeleteSync();
|
|
3387
|
+
log2.log(`[AppDataGroup:${this.groupId}] deleteFile(directory): ${normalized} (${files.length} file(s))`);
|
|
3388
|
+
return;
|
|
3389
|
+
}
|
|
3327
3390
|
const tombstone = {
|
|
3328
3391
|
path: normalized,
|
|
3329
3392
|
deletedAt: Date.now(),
|
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,45 @@ 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 removeDirectoryTree(fs, dir) {
|
|
27857
|
+
let entries2;
|
|
27858
|
+
try {
|
|
27859
|
+
entries2 = await fs.readdir(dir);
|
|
27860
|
+
} catch {
|
|
27861
|
+
return;
|
|
27862
|
+
}
|
|
27863
|
+
for (const entry of entries2) {
|
|
27864
|
+
const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
|
|
27865
|
+
if (await isDirectoryPath(fs, child)) await removeDirectoryTree(fs, child);
|
|
27866
|
+
}
|
|
27867
|
+
try {
|
|
27868
|
+
await fs.rmdir?.(dir);
|
|
27869
|
+
} catch {
|
|
27870
|
+
}
|
|
27871
|
+
}
|
|
27830
27872
|
function normalizeGroupName(value) {
|
|
27831
27873
|
if (typeof value !== "string") {
|
|
27832
27874
|
throw new Error("Group name must be a string");
|
|
@@ -27960,7 +28002,10 @@ var ZenFSConfig = (() => {
|
|
|
27960
28002
|
this.pollIntervalMs = pollIntervalMs;
|
|
27961
28003
|
this.cacheOptions = cacheOptions;
|
|
27962
28004
|
this.fullFS = backendToSyncableFS(cachedFS, primaryBackendId);
|
|
27963
|
-
this.fs = createChrootFS(cachedFS, `/${appId}
|
|
28005
|
+
this.fs = createChrootFS(cachedFS, `/${appId}`, {
|
|
28006
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
28007
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
28008
|
+
});
|
|
27964
28009
|
this.rootFS = createChrootFS(cachedFS, "/");
|
|
27965
28010
|
}
|
|
27966
28011
|
/** Full path to this node's directory on the primary backend. */
|
|
@@ -28131,6 +28176,15 @@ var ZenFSConfig = (() => {
|
|
|
28131
28176
|
async deleteFile(path) {
|
|
28132
28177
|
this.assertNotDisposed();
|
|
28133
28178
|
const normalizedPath = path.startsWith("/") ? path : "/" + path;
|
|
28179
|
+
if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
|
|
28180
|
+
const files = await collectFilesUnder(this.cachedFS, normalizedPath);
|
|
28181
|
+
for (const file of files) await this.deleteFile(file);
|
|
28182
|
+
await removeDirectoryTree(this.cachedFS, normalizedPath);
|
|
28183
|
+
this.invalidateTombstoneCache();
|
|
28184
|
+
this.schedulePostDeleteSync();
|
|
28185
|
+
log6.log(`[ConfigRepo] deleteFile(directory): ${normalizedPath} (${files.length} file(s))`);
|
|
28186
|
+
return;
|
|
28187
|
+
}
|
|
28134
28188
|
const tombstone = {
|
|
28135
28189
|
path: normalizedPath,
|
|
28136
28190
|
deletedAt: Date.now(),
|
|
@@ -29772,7 +29826,8 @@ var ZenFSConfig = (() => {
|
|
|
29772
29826
|
this.fs = createChrootFS(this.localFS, "/", {
|
|
29773
29827
|
hiddenPrefixes: [META_DIR, CONFIG_DIR],
|
|
29774
29828
|
onWrite: (path, data) => this.recordVersion(path, data),
|
|
29775
|
-
onUnlink: (path) => this.deleteFile(path)
|
|
29829
|
+
onUnlink: (path) => this.deleteFile(path),
|
|
29830
|
+
onRmdir: (path) => this.deleteFile(path)
|
|
29776
29831
|
});
|
|
29777
29832
|
const { kept, removed } = dedupeAppDataBackends(this._backends);
|
|
29778
29833
|
if (removed.length > 0) {
|
|
@@ -29893,9 +29948,17 @@ var ZenFSConfig = (() => {
|
|
|
29893
29948
|
async deleteFile(path) {
|
|
29894
29949
|
if (this.disposed) throw new Error("DataSyncGroup has been disposed");
|
|
29895
29950
|
const normalized = path.startsWith("/") ? path : `/${path}`;
|
|
29896
|
-
if (normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
29951
|
+
if (normalized === META_DIR || normalized === CONFIG_DIR || normalized.startsWith(`${META_DIR}/`) || normalized.startsWith(`${CONFIG_DIR}/`)) {
|
|
29897
29952
|
throw new Error(`Cannot delete metadata path "${normalized}"`);
|
|
29898
29953
|
}
|
|
29954
|
+
if (await isDirectoryPath(this.localFS, normalized)) {
|
|
29955
|
+
const files = await collectFilesUnder(this.localFS, normalized);
|
|
29956
|
+
for (const file of files) await this.deleteFile(file);
|
|
29957
|
+
await removeDirectoryTree(this.localFS, normalized);
|
|
29958
|
+
this.schedulePostDeleteSync();
|
|
29959
|
+
log6.log(`[AppDataGroup:${this.groupId}] deleteFile(directory): ${normalized} (${files.length} file(s))`);
|
|
29960
|
+
return;
|
|
29961
|
+
}
|
|
29899
29962
|
const tombstone = {
|
|
29900
29963
|
path: normalized,
|
|
29901
29964
|
deletedAt: Date.now(),
|