Preserve newer hidden files during Merge initialisation

This commit is contained in:
vorotamoroz committed 2026-10-31 15:50:19 +00:00
1 parent dfb6215e77
commit ceaf1f90e9
5 files changed
+388 -63

No files matched your search

@@ -90,6 +90,39 @@ afterEach(async () => {
for (const fixture of fixtureOwners.splice(0)) await fixture.dispose();
});
describe("Hidden File Sync initial modification times", () => {
it.each([
{ label: "newer", localMtime: 30_000, expected: "local content" },
{ label: "older", localMtime: 10_000, expected: "database content" },
{ label: "equal", localMtime: 20_000, expected: "database content" },
])("stores only a newer local file when the local timestamp is $label", async ({ localMtime, expected }) => {
const { fixture, hiddenFileSync, storageAccess } = await createHiddenFileSync();
const entry = optionalFileEntry(`i:${path}`, "database content");
entry.mtime = 20_000;
await fixture.localDatabase.putDBEntry(entry);
storageAccess.setFile("local content", localMtime);
await hiddenFileSync.trackStorageFileModification(path, true);
const saved = await fixture.localDatabase.getDBEntry(`i:${path}` as FilePath);
expect(saved).not.toBe(false);
if (saved) {
expect(await getText(saved)).toBe(expected);
expect(saved.mtime).toBe(expected === "local content" ? localMtime : 20_000);
}
});
it("stores a local-only file when only newer changes are requested", async () => {
const { fixture, hiddenFileSync } = await createHiddenFileSync();
await hiddenFileSync.trackStorageFileModification(path, true);
const saved = await fixture.localDatabase.getDBEntry(`i:${path}` as FilePath);
expect(saved).not.toBe(false);
if (saved) expect(await getText(saved)).toBe(content);
});
});
describe("Hidden File Sync optional save outcomes", () => {
it("retries a failed database write when the storage fingerprint is unchanged", async () => {
const { fixture, hiddenFileSync } = await createHiddenFileSync();
@@ -688,7 +688,7 @@ Offline Changed files: ${processFiles.length}`;
const dbMTime = getComparingMTime(filesOnDB, includeDeleted);
const diff = compareMTime(storageMTime, dbMTime);
if (diff != TARGET_IS_NEW) {
if (diff != BASE_IS_NEW) {
this._log(`Hidden file:${path} is not new.`, LOG_LEVEL_VERBOSE);
if (filesOnDB && stat) {
// OnlyNew not handles the deletion.