Skip to content

Commit 135c2d9

Browse files
committed
Fix: Return shard filename to prevent orphan deletion
The markOrphanedFiles function was deleting shard manifests because they weren't included in the newFiles set. Now writeShardedCategory returns the shard filename and packItemCategoryData includes it in the returned filenames list.
1 parent 0bdb8c1 commit 135c2d9

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/sync/operations/push.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,10 @@ function packItemCategoryData(
171171
const newItems = removeItemsById(processed, tombResult.itemsToRemove);
172172

173173
// Always use sharding for item categories
174-
writeShardedCategory(category, newItems, tombResult.tombstones, ctx);
174+
const shardFile = writeShardedCategory(category, newItems, tombResult.tombstones, ctx);
175175

176-
return filenames;
176+
// Return both item filenames AND the shard file to prevent orphan deletion
177+
return [...filenames, shardFile];
177178
}
178179

179180
/**

src/sync/operations/sharding.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import type { PushContext, SyncCategory } from './types.js';
1616

1717
/**
1818
* Write a sharded category (items stored in separate shard file).
19+
* Returns the shard filename for tracking.
1920
*/
2021
export function writeShardedCategory(
2122
category: SyncCategory,
2223
items: Record<string, ItemInfo>,
2324
tombstones: Record<string, Tombstone>,
2425
ctx: PushContext
25-
): void {
26+
): string {
2627
const shardFile = getShardFilename(category);
2728

2829
// Create shard content
@@ -51,4 +52,6 @@ export function writeShardedCategory(
5152
lastModifiedBy: ctx.machineId,
5253
vectorClock: { [ctx.machineId]: ctx.newClock[ctx.machineId] ?? 1 },
5354
} satisfies ShardedCategoryRef;
55+
56+
return shardFile;
5457
}

0 commit comments

Comments
 (0)