zen-fs-config 0.7.0 → 0.7.2

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 CHANGED
@@ -2120,6 +2120,45 @@ async function removeDirectoryTree(fs, dir) {
2120
2120
  } catch {
2121
2121
  }
2122
2122
  }
2123
+ async function collectFilesUnderAny(surfaces, dir, onError) {
2124
+ const merged = /* @__PURE__ */ new Set();
2125
+ for (const surface of surfaces) {
2126
+ try {
2127
+ for (const file of await collectFilesUnder(surface.fs, dir)) merged.add(file);
2128
+ } catch (error) {
2129
+ onError(surface.label, error);
2130
+ }
2131
+ }
2132
+ return [...merged];
2133
+ }
2134
+ async function collectDirectoriesUnderStrict(fs, dir, out = []) {
2135
+ out.push(dir);
2136
+ const entries = await fs.readdir(dir);
2137
+ for (const entry of entries) {
2138
+ const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
2139
+ if (await isDirectoryPath(fs, child)) await collectDirectoriesUnderStrict(fs, child, out);
2140
+ }
2141
+ return out;
2142
+ }
2143
+ async function collectDirectoriesUnderAny(surfaces, dir, onError) {
2144
+ const merged = /* @__PURE__ */ new Set();
2145
+ for (const surface of surfaces) {
2146
+ const found = [];
2147
+ try {
2148
+ await collectDirectoriesUnderStrict(surface.fs, dir, found);
2149
+ } catch (error) {
2150
+ onError(surface.label, error);
2151
+ }
2152
+ for (const child of found) merged.add(child);
2153
+ }
2154
+ return [...merged];
2155
+ }
2156
+ async function isDirectoryAny(surfaces, path) {
2157
+ for (const surface of surfaces) {
2158
+ if (await isDirectoryPath(surface.fs, path)) return true;
2159
+ }
2160
+ return false;
2161
+ }
2123
2162
  function isNotFoundError(err) {
2124
2163
  const code = err?.code;
2125
2164
  if (code === "ENOENT" || code === "ENOTDIR") return true;
@@ -2461,10 +2500,20 @@ var ConfigRepo = class {
2461
2500
  async deleteFile(path) {
2462
2501
  this.assertNotDisposed();
2463
2502
  const normalizedPath = path.startsWith("/") ? path : "/" + path;
2464
- if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
2465
- const files = await collectFilesUnder(this.cachedFS, normalizedPath);
2503
+ const surfaces = [{ label: "local-cache", fs: this.cachedFS }];
2504
+ for (const [id, replica] of this.replicaBackends) {
2505
+ surfaces.push({ label: id, fs: replica.instance });
2506
+ }
2507
+ const onEnumerateError = (label, error) => {
2508
+ const reason = error?.message ?? String(error);
2509
+ log3.warn(
2510
+ `[ConfigRepo] deleteFile(directory): cannot enumerate "${label}" under ${normalizedPath}: ${reason}`
2511
+ );
2512
+ };
2513
+ if (await isDirectoryAny(surfaces, normalizedPath)) {
2514
+ const files = await collectFilesUnderAny(surfaces, normalizedPath, onEnumerateError);
2466
2515
  for (const file of files) await this.deleteFile(file);
2467
- for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
2516
+ for (const dir of await collectDirectoriesUnderAny(surfaces, normalizedPath, onEnumerateError)) {
2468
2517
  const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
2469
2518
  await this.writeTombstoneFor(keepPath);
2470
2519
  await this.writeTombstoneFor(`${keepPath}.mtime`);
package/dist/index.mjs CHANGED
@@ -1565,6 +1565,45 @@ async function removeDirectoryTree(fs, dir) {
1565
1565
  } catch {
1566
1566
  }
1567
1567
  }
1568
+ async function collectFilesUnderAny(surfaces, dir, onError) {
1569
+ const merged = /* @__PURE__ */ new Set();
1570
+ for (const surface of surfaces) {
1571
+ try {
1572
+ for (const file of await collectFilesUnder(surface.fs, dir)) merged.add(file);
1573
+ } catch (error) {
1574
+ onError(surface.label, error);
1575
+ }
1576
+ }
1577
+ return [...merged];
1578
+ }
1579
+ async function collectDirectoriesUnderStrict(fs, dir, out = []) {
1580
+ out.push(dir);
1581
+ const entries = await fs.readdir(dir);
1582
+ for (const entry of entries) {
1583
+ const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
1584
+ if (await isDirectoryPath(fs, child)) await collectDirectoriesUnderStrict(fs, child, out);
1585
+ }
1586
+ return out;
1587
+ }
1588
+ async function collectDirectoriesUnderAny(surfaces, dir, onError) {
1589
+ const merged = /* @__PURE__ */ new Set();
1590
+ for (const surface of surfaces) {
1591
+ const found = [];
1592
+ try {
1593
+ await collectDirectoriesUnderStrict(surface.fs, dir, found);
1594
+ } catch (error) {
1595
+ onError(surface.label, error);
1596
+ }
1597
+ for (const child of found) merged.add(child);
1598
+ }
1599
+ return [...merged];
1600
+ }
1601
+ async function isDirectoryAny(surfaces, path) {
1602
+ for (const surface of surfaces) {
1603
+ if (await isDirectoryPath(surface.fs, path)) return true;
1604
+ }
1605
+ return false;
1606
+ }
1568
1607
  function isNotFoundError(err) {
1569
1608
  const code = err?.code;
1570
1609
  if (code === "ENOENT" || code === "ENOTDIR") return true;
@@ -1906,10 +1945,20 @@ var ConfigRepo = class {
1906
1945
  async deleteFile(path) {
1907
1946
  this.assertNotDisposed();
1908
1947
  const normalizedPath = path.startsWith("/") ? path : "/" + path;
1909
- if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
1910
- const files = await collectFilesUnder(this.cachedFS, normalizedPath);
1948
+ const surfaces = [{ label: "local-cache", fs: this.cachedFS }];
1949
+ for (const [id, replica] of this.replicaBackends) {
1950
+ surfaces.push({ label: id, fs: replica.instance });
1951
+ }
1952
+ const onEnumerateError = (label, error) => {
1953
+ const reason = error?.message ?? String(error);
1954
+ log3.warn(
1955
+ `[ConfigRepo] deleteFile(directory): cannot enumerate "${label}" under ${normalizedPath}: ${reason}`
1956
+ );
1957
+ };
1958
+ if (await isDirectoryAny(surfaces, normalizedPath)) {
1959
+ const files = await collectFilesUnderAny(surfaces, normalizedPath, onEnumerateError);
1911
1960
  for (const file of files) await this.deleteFile(file);
1912
- for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
1961
+ for (const dir of await collectDirectoriesUnderAny(surfaces, normalizedPath, onEnumerateError)) {
1913
1962
  const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
1914
1963
  await this.writeTombstoneFor(keepPath);
1915
1964
  await this.writeTombstoneFor(`${keepPath}.mtime`);
@@ -25487,36 +25487,6 @@ var ZenFSConfig = (() => {
25487
25487
  await visit(normalizedRoot);
25488
25488
  return results;
25489
25489
  }
25490
- async function collectDirectories(fs, root, filter) {
25491
- const results = [];
25492
- const normalizedRoot = normalizePath(root);
25493
- async function visit(dir) {
25494
- let entries2;
25495
- try {
25496
- entries2 = await fs.readdir(dir);
25497
- } catch {
25498
- return;
25499
- }
25500
- for (const entry of entries2) {
25501
- if (entry === ".zenfs-sync") continue;
25502
- const fullPath = resolvePath(dir, entry);
25503
- let relPath = fullPath.slice(normalizedRoot.length) || "/";
25504
- if (!relPath.startsWith("/")) relPath = "/" + relPath;
25505
- let stat5;
25506
- try {
25507
- stat5 = await fs.stat(fullPath);
25508
- } catch {
25509
- continue;
25510
- }
25511
- if (isDirectory(stat5)) {
25512
- if (isPathAllowed(relPath, filter)) results.push(relPath);
25513
- await visit(fullPath);
25514
- }
25515
- }
25516
- }
25517
- await visit(normalizedRoot);
25518
- return results;
25519
- }
25520
25490
  async function buildSnapshot(fs, root, filter) {
25521
25491
  const normalizedRoot = normalizePath(root);
25522
25492
  const fsName = fs.backendName || "unknown";
@@ -26031,7 +26001,6 @@ var ZenFSConfig = (() => {
26031
26001
  }
26032
26002
  }
26033
26003
  }
26034
- await this.preserveDirectories(src, tgt);
26035
26004
  return {
26036
26005
  pairId: this.pairId,
26037
26006
  direction: this.options.direction,
@@ -26232,8 +26201,6 @@ var ZenFSConfig = (() => {
26232
26201
  }
26233
26202
  }
26234
26203
  }
26235
- await this.preserveDirectories(this.source, this.target);
26236
- await this.preserveDirectories(this.target, this.source);
26237
26204
  const durationMs = Date.now() - startTime;
26238
26205
  log3(`[zen-fs-sync] syncBidirectional END pairId=${this.pairId} +${filesCreated}/~${filesUpdated}/-${filesDeleted} ${durationMs}ms`);
26239
26206
  return {
@@ -26263,28 +26230,6 @@ var ZenFSConfig = (() => {
26263
26230
  }
26264
26231
  return buildSnapshot(fs, this.root, this.options.filter);
26265
26232
  }
26266
- /**
26267
- * Preserve empty directories across backends (zen-fs-sync/docs/SyncableFS.md §2).
26268
- *
26269
- * A backend that cannot store empty directories (Git, RemoteStorage) keeps a
26270
- * directory alive with an internal `.keep` placeholder that is hidden from
26271
- * callers. Because the sync snapshot is file-based, empty directories are not
26272
- * represented, so the sync engine must explicitly `mkdir` each source
26273
- * directory on the target. The target's own `mkdir` then produces its own
26274
- * (hidden) placeholder. Best-effort: failures are logged, never thrown.
26275
- */
26276
- async preserveDirectories(source, target) {
26277
- try {
26278
- const dirs = await collectDirectories(source, this.root, this.options.filter);
26279
- for (const relDir of dirs) {
26280
- if (relDir === "/") continue;
26281
- const fullDir = resolvePath(this.root, relDir);
26282
- await ensureDir(target, fullDir);
26283
- }
26284
- } catch (err2) {
26285
- log3(`[zen-fs-sync] preserveDirectories FAIL: ${err2}`);
26286
- }
26287
- }
26288
26233
  /**
26289
26234
  * Compare two snapshots for equality (same paths, same size, same mtime).
26290
26235
  * Returns true if they are identical, false otherwise.
@@ -28134,6 +28079,45 @@ var ZenFSConfig = (() => {
28134
28079
  } catch {
28135
28080
  }
28136
28081
  }
28082
+ async function collectFilesUnderAny(surfaces, dir, onError) {
28083
+ const merged = /* @__PURE__ */ new Set();
28084
+ for (const surface of surfaces) {
28085
+ try {
28086
+ for (const file of await collectFilesUnder(surface.fs, dir)) merged.add(file);
28087
+ } catch (error) {
28088
+ onError(surface.label, error);
28089
+ }
28090
+ }
28091
+ return [...merged];
28092
+ }
28093
+ async function collectDirectoriesUnderStrict(fs, dir, out = []) {
28094
+ out.push(dir);
28095
+ const entries2 = await fs.readdir(dir);
28096
+ for (const entry of entries2) {
28097
+ const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
28098
+ if (await isDirectoryPath(fs, child)) await collectDirectoriesUnderStrict(fs, child, out);
28099
+ }
28100
+ return out;
28101
+ }
28102
+ async function collectDirectoriesUnderAny(surfaces, dir, onError) {
28103
+ const merged = /* @__PURE__ */ new Set();
28104
+ for (const surface of surfaces) {
28105
+ const found = [];
28106
+ try {
28107
+ await collectDirectoriesUnderStrict(surface.fs, dir, found);
28108
+ } catch (error) {
28109
+ onError(surface.label, error);
28110
+ }
28111
+ for (const child of found) merged.add(child);
28112
+ }
28113
+ return [...merged];
28114
+ }
28115
+ async function isDirectoryAny(surfaces, path) {
28116
+ for (const surface of surfaces) {
28117
+ if (await isDirectoryPath(surface.fs, path)) return true;
28118
+ }
28119
+ return false;
28120
+ }
28137
28121
  function isNotFoundError(err2) {
28138
28122
  const code = err2?.code;
28139
28123
  if (code === "ENOENT" || code === "ENOTDIR") return true;
@@ -28481,10 +28465,20 @@ var ZenFSConfig = (() => {
28481
28465
  async deleteFile(path) {
28482
28466
  this.assertNotDisposed();
28483
28467
  const normalizedPath = path.startsWith("/") ? path : "/" + path;
28484
- if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
28485
- const files = await collectFilesUnder(this.cachedFS, normalizedPath);
28468
+ const surfaces = [{ label: "local-cache", fs: this.cachedFS }];
28469
+ for (const [id, replica] of this.replicaBackends) {
28470
+ surfaces.push({ label: id, fs: replica.instance });
28471
+ }
28472
+ const onEnumerateError = (label, error) => {
28473
+ const reason = error?.message ?? String(error);
28474
+ log7.warn(
28475
+ `[ConfigRepo] deleteFile(directory): cannot enumerate "${label}" under ${normalizedPath}: ${reason}`
28476
+ );
28477
+ };
28478
+ if (await isDirectoryAny(surfaces, normalizedPath)) {
28479
+ const files = await collectFilesUnderAny(surfaces, normalizedPath, onEnumerateError);
28486
28480
  for (const file of files) await this.deleteFile(file);
28487
- for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
28481
+ for (const dir of await collectDirectoriesUnderAny(surfaces, normalizedPath, onEnumerateError)) {
28488
28482
  const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
28489
28483
  await this.writeTombstoneFor(keepPath);
28490
28484
  await this.writeTombstoneFor(`${keepPath}.mtime`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Distributed config management library built on ZenFS, zen-fs-cache, and zen-fs-sync",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -49,7 +49,7 @@
49
49
  "@zenfs/core": ">=2.3.0",
50
50
  "@zenfs/dom": ">=1.0.0",
51
51
  "zen-fs-cache": ">=1.0.0",
52
- "zen-fs-sync": ">=0.4.7",
52
+ "zen-fs-sync": ">=0.4.18",
53
53
  "zen-fs-github": "*",
54
54
  "zen-fs-gitee": "*",
55
55
  "zen-fs-remotestoragejs": "*",
@@ -85,6 +85,6 @@
85
85
  "typescript": "^5.9.3",
86
86
  "vitest": "^1.6.1",
87
87
  "zen-fs-cache": "^1.0.6",
88
- "zen-fs-sync": "^0.4.17"
88
+ "zen-fs-sync": "^0.4.18"
89
89
  }
90
90
  }