mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-26 11:03:21 +00:00
fix(startup): recheck sizes after reading storage
This commit is contained in:
1 parent
fc2b35e0dc
commit
fd2eebdf38
3 files changed
+41
No files matched your search
@@ -117,6 +117,10 @@ export async function checkIncompleteDocuments(
|
||||
continue;
|
||||
}
|
||||
sizeOnStorage = storageFileContent.byteLength;
|
||||
// The file may have changed since stat, so recheck using the bytes read.
|
||||
if (recordedSize === actualSize && sizeOnStorage === actualSize && !isConflicted) {
|
||||
continue;
|
||||
}
|
||||
const contentMatched = await isDocContentSame(doc.data, storageFileContent);
|
||||
errorFiles.push({
|
||||
path,
|
||||
|
||||
@@ -182,6 +182,39 @@ describe("checkIncompleteDocuments", () => {
|
||||
expect(fixture.dependencies.keyValueDB.set).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not offer repair when all sizes agree after reading storage", async () => {
|
||||
const healthy = documentFixture("settled.md", { storageContent: "abc" });
|
||||
const fixture = createDependencies(documentsFrom([healthy]), [healthy]);
|
||||
vi.mocked(fixture.dependencies.storageAccess.statHidden).mockResolvedValueOnce({ ...healthy.stub.stat, size: 4 });
|
||||
|
||||
await expect(checkIncompleteDocuments(fixture.dependencies)).resolves.toBe(true);
|
||||
|
||||
expect(fixture.readHiddenFileBinary).toHaveBeenCalledWith("settled.md");
|
||||
expect(fixture.askSelectStringDialogue).not.toHaveBeenCalled();
|
||||
expect(fixture.storeFileToDB).not.toHaveBeenCalled();
|
||||
expect(fixture.dependencies.keyValueDB.set).toHaveBeenCalledWith("checkIncompleteDocs", true);
|
||||
});
|
||||
|
||||
it("uses the bytes read from storage when a size mismatch remains", async () => {
|
||||
const mismatched = documentFixture("changing.md", { recordedSize: 3, storageContent: "abcde" });
|
||||
const fixture = createDependencies(documentsFrom([mismatched]), [mismatched]);
|
||||
vi.mocked(fixture.dependencies.storageAccess.statHidden).mockResolvedValueOnce({
|
||||
...mismatched.stub.stat,
|
||||
size: 4,
|
||||
});
|
||||
fixture.askSelectStringDialogue.mockImplementation(selectButton(0));
|
||||
|
||||
await expect(checkIncompleteDocuments(fixture.dependencies)).resolves.toBe(true);
|
||||
|
||||
expect(fixture.readHiddenFileBinary).toHaveBeenCalledWith("changing.md");
|
||||
expect(fixture.askSelectStringDialogue).toHaveBeenCalledOnce();
|
||||
expect(fixture.askSelectStringDialogue.mock.calls[0]?.[0]).toEqual(
|
||||
expect.stringContaining("changing.md (M: 3, A: 3, S: 5)")
|
||||
);
|
||||
expect(fixture.storeFileToDB).not.toHaveBeenCalled();
|
||||
expect(fixture.dependencies.keyValueDB.set).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("still reads conflicted storage for the existing repair dialogue", async () => {
|
||||
const conflicted = documentFixture("conflicted.md", { storageContent: "abc", conflicts: ["2-other"] });
|
||||
const fixture = createDependencies(documentsFrom([conflicted]), [conflicted]);
|
||||
|
||||
Reference in new issue
Block a user