zen-fs-config 0.10.1 → 0.10.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.d.mts CHANGED
@@ -1463,6 +1463,16 @@ declare class ConfigRepo implements IConfigRepo {
1463
1463
  * 时刻新就意味着这条墓碑已经被写操作撤销。
1464
1464
  */
1465
1465
  private isPathRecreatedAfterTombstone;
1466
+ /**
1467
+ * 目录墓碑专用:目录下是否存在「删除之后写入」的真实数据项。
1468
+ *
1469
+ * 只递归看普通文件,不看目录 inode 的 mtime;`.keep` / `.mtime` / `.version`
1470
+ * 这些后端元数据每轮同步都可能被重写,不能当作重建证据。目录里只剩占位
1471
+ * 文件时返回 false —— 那属于待清理残留,不是用户重建。
1472
+ */
1473
+ private dirHasEntryNewerThan;
1474
+ /** 后端内部元数据:不作为「删除后重建」的证据。 */
1475
+ private isBackendMetadataPath;
1466
1476
  /**
1467
1477
  * Before sync: for each tombstone, delete the actual file on all replicas.
1468
1478
  * This prevents bi-directional sync from copying the file back.
@@ -2708,6 +2718,7 @@ declare class TombstoneStore {
2708
2718
  * 本来就旧,用副本判定既不可靠又会掩盖真正的删除传播。
2709
2719
  */
2710
2720
  private wasRecreatedAfterDeletion;
2721
+ private dirHasEntryNewerThan;
2711
2722
  private mtimeOf;
2712
2723
  private deleteEverywhere;
2713
2724
  /**
package/dist/index.d.ts CHANGED
@@ -1463,6 +1463,16 @@ declare class ConfigRepo implements IConfigRepo {
1463
1463
  * 时刻新就意味着这条墓碑已经被写操作撤销。
1464
1464
  */
1465
1465
  private isPathRecreatedAfterTombstone;
1466
+ /**
1467
+ * 目录墓碑专用:目录下是否存在「删除之后写入」的真实数据项。
1468
+ *
1469
+ * 只递归看普通文件,不看目录 inode 的 mtime;`.keep` / `.mtime` / `.version`
1470
+ * 这些后端元数据每轮同步都可能被重写,不能当作重建证据。目录里只剩占位
1471
+ * 文件时返回 false —— 那属于待清理残留,不是用户重建。
1472
+ */
1473
+ private dirHasEntryNewerThan;
1474
+ /** 后端内部元数据:不作为「删除后重建」的证据。 */
1475
+ private isBackendMetadataPath;
1466
1476
  /**
1467
1477
  * Before sync: for each tombstone, delete the actual file on all replicas.
1468
1478
  * This prevents bi-directional sync from copying the file back.
@@ -2708,6 +2718,7 @@ declare class TombstoneStore {
2708
2718
  * 本来就旧,用副本判定既不可靠又会掩盖真正的删除传播。
2709
2719
  */
2710
2720
  private wasRecreatedAfterDeletion;
2721
+ private dirHasEntryNewerThan;
2711
2722
  private mtimeOf;
2712
2723
  private deleteEverywhere;
2713
2724
  /**
package/dist/index.js CHANGED
@@ -2389,10 +2389,40 @@ var TombstoneStore = class {
2389
2389
  * 本来就旧,用副本判定既不可靠又会掩盖真正的删除传播。
2390
2390
  */
2391
2391
  async wasRecreatedAfterDeletion(tombstone) {
2392
+ if (isDirectoryTombstone(tombstone)) {
2393
+ return this.dirHasEntryNewerThan(this.fs, tombstone.path, tombstone.deletedAt);
2394
+ }
2392
2395
  const mtimeMs = await this.mtimeOf(this.fs, tombstone.path);
2393
2396
  if (mtimeMs === null) return false;
2394
2397
  return mtimeMs > tombstone.deletedAt + RECREATE_AFTER_DELETE_SKEW_MS;
2395
2398
  }
2399
+ async dirHasEntryNewerThan(fs, dirPath, deletedAt, depth = 0) {
2400
+ let names;
2401
+ try {
2402
+ names = await fs.readdir(dirPath);
2403
+ } catch {
2404
+ return false;
2405
+ }
2406
+ for (const name of names) {
2407
+ const childPath = `${dirPath}/${name}`;
2408
+ if (isHiddenPlaceholderPath(childPath) || childPath.endsWith(".version")) continue;
2409
+ let inode;
2410
+ try {
2411
+ inode = await fs.stat(childPath);
2412
+ } catch {
2413
+ continue;
2414
+ }
2415
+ const isChildDir = typeof inode?.isDirectory === "function" ? inode.isDirectory() : !!(inode && ((inode.mode ?? 0) & 61440) === 16384);
2416
+ if (isChildDir) {
2417
+ if (depth < 4 && await this.dirHasEntryNewerThan(fs, childPath, deletedAt, depth + 1)) {
2418
+ return true;
2419
+ }
2420
+ continue;
2421
+ }
2422
+ if (Number(inode?.mtimeMs ?? 0) > deletedAt + RECREATE_AFTER_DELETE_SKEW_MS) return true;
2423
+ }
2424
+ return false;
2425
+ }
2396
2426
  async mtimeOf(fs, filePath) {
2397
2427
  try {
2398
2428
  const stat = await fs.stat?.(filePath);
@@ -3791,7 +3821,12 @@ var ConfigRepo = class _ConfigRepo {
3791
3821
  for (const [id, replica] of this.replicaBackends) {
3792
3822
  surfaces.push({ label: id, fs: replica.instance });
3793
3823
  }
3824
+ const isDirTombstone = isDirectoryTombstone(tombstone);
3794
3825
  for (const surface of surfaces) {
3826
+ if (isDirTombstone) {
3827
+ if (await this.dirHasEntryNewerThan(surface.fs, tombstone.path, tombstone.deletedAt)) return true;
3828
+ continue;
3829
+ }
3795
3830
  let mtimeMs;
3796
3831
  try {
3797
3832
  const inode = await surface.fs.stat(tombstone.path);
@@ -3803,6 +3838,44 @@ var ConfigRepo = class _ConfigRepo {
3803
3838
  }
3804
3839
  return false;
3805
3840
  }
3841
+ /**
3842
+ * 目录墓碑专用:目录下是否存在「删除之后写入」的真实数据项。
3843
+ *
3844
+ * 只递归看普通文件,不看目录 inode 的 mtime;`.keep` / `.mtime` / `.version`
3845
+ * 这些后端元数据每轮同步都可能被重写,不能当作重建证据。目录里只剩占位
3846
+ * 文件时返回 false —— 那属于待清理残留,不是用户重建。
3847
+ */
3848
+ async dirHasEntryNewerThan(fs, dirPath, deletedAt, depth = 0) {
3849
+ let names;
3850
+ try {
3851
+ names = await fs.readdir(dirPath);
3852
+ } catch {
3853
+ return false;
3854
+ }
3855
+ for (const name of names) {
3856
+ const childPath = `${dirPath}/${name}`;
3857
+ if (this.isBackendMetadataPath(childPath)) continue;
3858
+ let inode;
3859
+ try {
3860
+ inode = await fs.stat(childPath);
3861
+ } catch {
3862
+ continue;
3863
+ }
3864
+ const childIsDir = typeof inode?.isDirectory === "function" ? inode.isDirectory() : !!(inode && ((inode.mode ?? 0) & 61440) === 16384);
3865
+ if (childIsDir) {
3866
+ if (depth < 4 && await this.dirHasEntryNewerThan(fs, childPath, deletedAt, depth + 1)) {
3867
+ return true;
3868
+ }
3869
+ continue;
3870
+ }
3871
+ if (Number(inode?.mtimeMs ?? 0) > deletedAt + TOMBSTONE_RECREATE_SKEW_MS) return true;
3872
+ }
3873
+ return false;
3874
+ }
3875
+ /** 后端内部元数据:不作为「删除后重建」的证据。 */
3876
+ isBackendMetadataPath(filePath) {
3877
+ return filePath.endsWith("/.keep") || isMtimeSidecar(filePath) || filePath.endsWith(".version");
3878
+ }
3806
3879
  /**
3807
3880
  * Before sync: for each tombstone, delete the actual file on all replicas.
3808
3881
  * This prevents bi-directional sync from copying the file back.
package/dist/index.mjs CHANGED
@@ -1595,10 +1595,40 @@ var TombstoneStore = class {
1595
1595
  * 本来就旧,用副本判定既不可靠又会掩盖真正的删除传播。
1596
1596
  */
1597
1597
  async wasRecreatedAfterDeletion(tombstone) {
1598
+ if (isDirectoryTombstone(tombstone)) {
1599
+ return this.dirHasEntryNewerThan(this.fs, tombstone.path, tombstone.deletedAt);
1600
+ }
1598
1601
  const mtimeMs = await this.mtimeOf(this.fs, tombstone.path);
1599
1602
  if (mtimeMs === null) return false;
1600
1603
  return mtimeMs > tombstone.deletedAt + RECREATE_AFTER_DELETE_SKEW_MS;
1601
1604
  }
1605
+ async dirHasEntryNewerThan(fs, dirPath, deletedAt, depth = 0) {
1606
+ let names;
1607
+ try {
1608
+ names = await fs.readdir(dirPath);
1609
+ } catch {
1610
+ return false;
1611
+ }
1612
+ for (const name of names) {
1613
+ const childPath = `${dirPath}/${name}`;
1614
+ if (isHiddenPlaceholderPath(childPath) || childPath.endsWith(".version")) continue;
1615
+ let inode;
1616
+ try {
1617
+ inode = await fs.stat(childPath);
1618
+ } catch {
1619
+ continue;
1620
+ }
1621
+ const isChildDir = typeof inode?.isDirectory === "function" ? inode.isDirectory() : !!(inode && ((inode.mode ?? 0) & 61440) === 16384);
1622
+ if (isChildDir) {
1623
+ if (depth < 4 && await this.dirHasEntryNewerThan(fs, childPath, deletedAt, depth + 1)) {
1624
+ return true;
1625
+ }
1626
+ continue;
1627
+ }
1628
+ if (Number(inode?.mtimeMs ?? 0) > deletedAt + RECREATE_AFTER_DELETE_SKEW_MS) return true;
1629
+ }
1630
+ return false;
1631
+ }
1602
1632
  async mtimeOf(fs, filePath) {
1603
1633
  try {
1604
1634
  const stat = await fs.stat?.(filePath);
@@ -2997,7 +3027,12 @@ var ConfigRepo = class _ConfigRepo {
2997
3027
  for (const [id, replica] of this.replicaBackends) {
2998
3028
  surfaces.push({ label: id, fs: replica.instance });
2999
3029
  }
3030
+ const isDirTombstone = isDirectoryTombstone(tombstone);
3000
3031
  for (const surface of surfaces) {
3032
+ if (isDirTombstone) {
3033
+ if (await this.dirHasEntryNewerThan(surface.fs, tombstone.path, tombstone.deletedAt)) return true;
3034
+ continue;
3035
+ }
3001
3036
  let mtimeMs;
3002
3037
  try {
3003
3038
  const inode = await surface.fs.stat(tombstone.path);
@@ -3009,6 +3044,44 @@ var ConfigRepo = class _ConfigRepo {
3009
3044
  }
3010
3045
  return false;
3011
3046
  }
3047
+ /**
3048
+ * 目录墓碑专用:目录下是否存在「删除之后写入」的真实数据项。
3049
+ *
3050
+ * 只递归看普通文件,不看目录 inode 的 mtime;`.keep` / `.mtime` / `.version`
3051
+ * 这些后端元数据每轮同步都可能被重写,不能当作重建证据。目录里只剩占位
3052
+ * 文件时返回 false —— 那属于待清理残留,不是用户重建。
3053
+ */
3054
+ async dirHasEntryNewerThan(fs, dirPath, deletedAt, depth = 0) {
3055
+ let names;
3056
+ try {
3057
+ names = await fs.readdir(dirPath);
3058
+ } catch {
3059
+ return false;
3060
+ }
3061
+ for (const name of names) {
3062
+ const childPath = `${dirPath}/${name}`;
3063
+ if (this.isBackendMetadataPath(childPath)) continue;
3064
+ let inode;
3065
+ try {
3066
+ inode = await fs.stat(childPath);
3067
+ } catch {
3068
+ continue;
3069
+ }
3070
+ const childIsDir = typeof inode?.isDirectory === "function" ? inode.isDirectory() : !!(inode && ((inode.mode ?? 0) & 61440) === 16384);
3071
+ if (childIsDir) {
3072
+ if (depth < 4 && await this.dirHasEntryNewerThan(fs, childPath, deletedAt, depth + 1)) {
3073
+ return true;
3074
+ }
3075
+ continue;
3076
+ }
3077
+ if (Number(inode?.mtimeMs ?? 0) > deletedAt + TOMBSTONE_RECREATE_SKEW_MS) return true;
3078
+ }
3079
+ return false;
3080
+ }
3081
+ /** 后端内部元数据:不作为「删除后重建」的证据。 */
3082
+ isBackendMetadataPath(filePath) {
3083
+ return filePath.endsWith("/.keep") || isMtimeSidecar(filePath) || filePath.endsWith(".version");
3084
+ }
3012
3085
  /**
3013
3086
  * Before sync: for each tombstone, delete the actual file on all replicas.
3014
3087
  * This prevents bi-directional sync from copying the file back.
@@ -28353,10 +28353,40 @@ var ZenFSConfig = (() => {
28353
28353
  * 本来就旧,用副本判定既不可靠又会掩盖真正的删除传播。
28354
28354
  */
28355
28355
  async wasRecreatedAfterDeletion(tombstone) {
28356
+ if (isDirectoryTombstone(tombstone)) {
28357
+ return this.dirHasEntryNewerThan(this.fs, tombstone.path, tombstone.deletedAt);
28358
+ }
28356
28359
  const mtimeMs = await this.mtimeOf(this.fs, tombstone.path);
28357
28360
  if (mtimeMs === null) return false;
28358
28361
  return mtimeMs > tombstone.deletedAt + RECREATE_AFTER_DELETE_SKEW_MS;
28359
28362
  }
28363
+ async dirHasEntryNewerThan(fs, dirPath, deletedAt, depth = 0) {
28364
+ let names;
28365
+ try {
28366
+ names = await fs.readdir(dirPath);
28367
+ } catch {
28368
+ return false;
28369
+ }
28370
+ for (const name of names) {
28371
+ const childPath = `${dirPath}/${name}`;
28372
+ if (isHiddenPlaceholderPath(childPath) || childPath.endsWith(".version")) continue;
28373
+ let inode;
28374
+ try {
28375
+ inode = await fs.stat(childPath);
28376
+ } catch {
28377
+ continue;
28378
+ }
28379
+ const isChildDir = typeof inode?.isDirectory === "function" ? inode.isDirectory() : !!(inode && ((inode.mode ?? 0) & 61440) === 16384);
28380
+ if (isChildDir) {
28381
+ if (depth < 4 && await this.dirHasEntryNewerThan(fs, childPath, deletedAt, depth + 1)) {
28382
+ return true;
28383
+ }
28384
+ continue;
28385
+ }
28386
+ if (Number(inode?.mtimeMs ?? 0) > deletedAt + RECREATE_AFTER_DELETE_SKEW_MS) return true;
28387
+ }
28388
+ return false;
28389
+ }
28360
28390
  async mtimeOf(fs, filePath) {
28361
28391
  try {
28362
28392
  const stat5 = await fs.stat?.(filePath);
@@ -29734,7 +29764,12 @@ var ZenFSConfig = (() => {
29734
29764
  for (const [id, replica] of this.replicaBackends) {
29735
29765
  surfaces.push({ label: id, fs: replica.instance });
29736
29766
  }
29767
+ const isDirTombstone = isDirectoryTombstone(tombstone);
29737
29768
  for (const surface of surfaces) {
29769
+ if (isDirTombstone) {
29770
+ if (await this.dirHasEntryNewerThan(surface.fs, tombstone.path, tombstone.deletedAt)) return true;
29771
+ continue;
29772
+ }
29738
29773
  let mtimeMs;
29739
29774
  try {
29740
29775
  const inode = await surface.fs.stat(tombstone.path);
@@ -29746,6 +29781,44 @@ var ZenFSConfig = (() => {
29746
29781
  }
29747
29782
  return false;
29748
29783
  }
29784
+ /**
29785
+ * 目录墓碑专用:目录下是否存在「删除之后写入」的真实数据项。
29786
+ *
29787
+ * 只递归看普通文件,不看目录 inode 的 mtime;`.keep` / `.mtime` / `.version`
29788
+ * 这些后端元数据每轮同步都可能被重写,不能当作重建证据。目录里只剩占位
29789
+ * 文件时返回 false —— 那属于待清理残留,不是用户重建。
29790
+ */
29791
+ async dirHasEntryNewerThan(fs, dirPath, deletedAt, depth = 0) {
29792
+ let names;
29793
+ try {
29794
+ names = await fs.readdir(dirPath);
29795
+ } catch {
29796
+ return false;
29797
+ }
29798
+ for (const name of names) {
29799
+ const childPath = `${dirPath}/${name}`;
29800
+ if (this.isBackendMetadataPath(childPath)) continue;
29801
+ let inode;
29802
+ try {
29803
+ inode = await fs.stat(childPath);
29804
+ } catch {
29805
+ continue;
29806
+ }
29807
+ const childIsDir = typeof inode?.isDirectory === "function" ? inode.isDirectory() : !!(inode && ((inode.mode ?? 0) & 61440) === 16384);
29808
+ if (childIsDir) {
29809
+ if (depth < 4 && await this.dirHasEntryNewerThan(fs, childPath, deletedAt, depth + 1)) {
29810
+ return true;
29811
+ }
29812
+ continue;
29813
+ }
29814
+ if (Number(inode?.mtimeMs ?? 0) > deletedAt + TOMBSTONE_RECREATE_SKEW_MS) return true;
29815
+ }
29816
+ return false;
29817
+ }
29818
+ /** 后端内部元数据:不作为「删除后重建」的证据。 */
29819
+ isBackendMetadataPath(filePath) {
29820
+ return filePath.endsWith("/.keep") || isMtimeSidecar(filePath) || filePath.endsWith(".version");
29821
+ }
29749
29822
  /**
29750
29823
  * Before sync: for each tombstone, delete the actual file on all replicas.
29751
29824
  * This prevents bi-directional sync from copying the file back.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.10.1",
3
+ "version": "0.10.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",
@@ -24,7 +24,7 @@
24
24
  "build:npm": "tsup --format cjs,esm --dts",
25
25
  "build:browser": "tsup --format iife --global-name ZenFSConfig --platform browser --no-external /./ --external zen-fs-github --external zen-fs-gitee --external zen-fs-remotestoragejs --out-extension .js=.browser.js",
26
26
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
27
- "clean": "rm -rf dist",
27
+ "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
28
28
  "typecheck": "tsc --noEmit",
29
29
  "test": "vitest run",
30
30
  "test:watch": "vitest",