@rljson/fs-agent 0.0.48 → 0.0.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.
@@ -276,6 +276,14 @@ export declare class FsAgent {
276
276
  /** Files written vs left alone by the current {@link restore}. */
277
277
  private _restoreWritten;
278
278
  private _restoreSkipped;
279
+ /**
280
+ * The file set of the newest tree any peer has told this node about.
281
+ *
282
+ * Kept so the SEND path can answer the one question a receiver never can:
283
+ * am I about to announce a state that is merely my progress through someone
284
+ * else's? See the check in `syncToDb`.
285
+ */
286
+ private _lastKnownRemoteFiles?;
279
287
  /**
280
288
  * Files this restore DELETED.
281
289
  *
package/dist/fs-agent.js CHANGED
@@ -1152,6 +1152,14 @@ class FsAgent {
1152
1152
  /** Files written vs left alone by the current {@link restore}. */
1153
1153
  _restoreWritten = 0;
1154
1154
  _restoreSkipped = 0;
1155
+ /**
1156
+ * The file set of the newest tree any peer has told this node about.
1157
+ *
1158
+ * Kept so the SEND path can answer the one question a receiver never can:
1159
+ * am I about to announce a state that is merely my progress through someone
1160
+ * else's? See the check in `syncToDb`.
1161
+ */
1162
+ _lastKnownRemoteFiles;
1155
1163
  /**
1156
1164
  * Files this restore DELETED.
1157
1165
  *
@@ -2021,6 +2029,25 @@ ${err.stack}` : String(err);
2021
2029
  if (contentKey === this._lastSentContentKey) {
2022
2030
  return;
2023
2031
  }
2032
+ const known = this._lastKnownRemoteFiles;
2033
+ if (known && tree.trees.size > 0) {
2034
+ const mine = this._getFileContentMap(tree);
2035
+ if (mine.size < known.size) {
2036
+ let hasOwn = false;
2037
+ for (const path of mine.keys()) {
2038
+ if (!known.has(path)) {
2039
+ hasOwn = true;
2040
+ break;
2041
+ }
2042
+ }
2043
+ if (!hasOwn) {
2044
+ console.log(
2045
+ `[FsAgent] not announcing ${mine.size} of ${known.size} files — this node is still catching up, and that is a gap rather than news.`
2046
+ );
2047
+ return;
2048
+ }
2049
+ }
2050
+ }
2024
2051
  const dbAdapter = new FsDbAdapter(db, treeKey);
2025
2052
  const parentRef = this._currentRef;
2026
2053
  const previous = await this._ancestryPrevious(
@@ -2498,6 +2525,7 @@ ${err.stack}` : String(err);
2498
2525
  this._persistCurrentRef(postRestoreRef);
2499
2526
  const postRestoreFiles = this._getFileContentMap(postRestoreTree);
2500
2527
  const incomingFiles = this._getFileContentMap(incomingTree);
2528
+ this._lastKnownRemoteFiles = incomingFiles;
2501
2529
  let hasNewsOfOurOwn = false;
2502
2530
  for (const path of postRestoreFiles.keys()) {
2503
2531
  if (!incomingFiles.has(path)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/fs-agent",
3
- "version": "0.0.48",
3
+ "version": "0.0.49",
4
4
  "description": "Rljson fs-agent description",
5
5
  "homepage": "https://github.com/rljson/fs-agent",
6
6
  "bugs": "https://github.com/rljson/fs-agent/issues",