mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2025-12-22 06:01:28 +00:00
### Fixed
- Opening IndexedDB handling has been ensured.
- Migration check of corrupted files detection has been fixed.
- Now informs us about conflicted files as non-recoverable, but noted so.
- No longer errors on not-found files.
This commit is contained in:
@@ -8,8 +8,8 @@ export const OpenKeyValueDatabase = async (dbKey: string): Promise<KeyValueDatab
|
|||||||
}
|
}
|
||||||
const storeKey = dbKey;
|
const storeKey = dbKey;
|
||||||
const dbPromise = openDB(dbKey, 1, {
|
const dbPromise = openDB(dbKey, 1, {
|
||||||
upgrade(db) {
|
upgrade(db, _oldVersion, _newVersion, _transaction, _event) {
|
||||||
db.createObjectStore(storeKey);
|
return db.createObjectStore(storeKey);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const db = await dbPromise;
|
const db = await dbPromise;
|
||||||
|
|||||||
@@ -207,6 +207,9 @@ export class StorageEventManagerObsidian extends StorageEventManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file instanceof TFolder) continue;
|
if (file instanceof TFolder) continue;
|
||||||
|
// TODO: Confirm why only the TFolder skipping
|
||||||
|
// Possibly following line is needed...
|
||||||
|
// if (file?.isFolder) continue;
|
||||||
if (!(await this.core.$$isTargetFile(file.path))) continue;
|
if (!(await this.core.$$isTargetFile(file.path))) continue;
|
||||||
|
|
||||||
// Stop cache using to prevent the corruption;
|
// Stop cache using to prevent the corruption;
|
||||||
|
|||||||
@@ -17,6 +17,15 @@ import { isMetaEntry } from "../../lib/src/common/types.ts";
|
|||||||
import { isDeletedEntry, isDocContentSame, isLoadedEntry, readAsBlob } from "../../lib/src/common/utils.ts";
|
import { isDeletedEntry, isDocContentSame, isLoadedEntry, readAsBlob } from "../../lib/src/common/utils.ts";
|
||||||
import { countCompromisedChunks } from "../../lib/src/pouchdb/negotiation.ts";
|
import { countCompromisedChunks } from "../../lib/src/pouchdb/negotiation.ts";
|
||||||
|
|
||||||
|
type ErrorInfo = {
|
||||||
|
path: string;
|
||||||
|
recordedSize: number;
|
||||||
|
actualSize: number;
|
||||||
|
storageSize: number;
|
||||||
|
contentMatched: boolean;
|
||||||
|
isConflicted?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export class ModuleMigration extends AbstractModule implements ICoreModule {
|
export class ModuleMigration extends AbstractModule implements ICoreModule {
|
||||||
async migrateUsingDoctor(skipRebuild: boolean = false, activateReason = "updated", forceRescan = false) {
|
async migrateUsingDoctor(skipRebuild: boolean = false, activateReason = "updated", forceRescan = false) {
|
||||||
const { shouldRebuild, shouldRebuildLocal, isModified, settings } = await performDoctorConsultation(
|
const { shouldRebuild, shouldRebuildLocal, isModified, settings } = await performDoctorConsultation(
|
||||||
@@ -112,7 +121,8 @@ export class ModuleMigration extends AbstractModule implements ICoreModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._log("Checking for incomplete documents...", LOG_LEVEL_NOTICE, "check-incomplete");
|
this._log("Checking for incomplete documents...", LOG_LEVEL_NOTICE, "check-incomplete");
|
||||||
const errorFiles = [];
|
|
||||||
|
const errorFiles = [] as ErrorInfo[];
|
||||||
for await (const metaDoc of this.localDatabase.findAllNormalDocs({ conflicts: true })) {
|
for await (const metaDoc of this.localDatabase.findAllNormalDocs({ conflicts: true })) {
|
||||||
const path = getPath(metaDoc);
|
const path = getPath(metaDoc);
|
||||||
|
|
||||||
@@ -133,17 +143,38 @@ export class ModuleMigration extends AbstractModule implements ICoreModule {
|
|||||||
if (isDeletedEntry(doc)) {
|
if (isDeletedEntry(doc)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const storageFileContent = await this.core.storageAccess.readHiddenFileBinary(path);
|
const isConflicted = metaDoc?._conflicts && metaDoc._conflicts.length > 0;
|
||||||
|
|
||||||
|
let storageFileContent;
|
||||||
|
try {
|
||||||
|
storageFileContent = await this.core.storageAccess.readHiddenFileBinary(path);
|
||||||
|
} catch (e) {
|
||||||
|
Logger(`Failed to read file ${path}: Possibly unprocessed or missing`);
|
||||||
|
Logger(e, LOG_LEVEL_VERBOSE);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// const storageFileBlob = createBlob(storageFileContent);
|
// const storageFileBlob = createBlob(storageFileContent);
|
||||||
const sizeOnStorage = storageFileContent.byteLength;
|
const sizeOnStorage = storageFileContent.byteLength;
|
||||||
const recordedSize = doc.size;
|
const recordedSize = doc.size;
|
||||||
const docBlob = readAsBlob(doc);
|
const docBlob = readAsBlob(doc);
|
||||||
const actualSize = docBlob.size;
|
const actualSize = docBlob.size;
|
||||||
if (recordedSize !== actualSize || sizeOnStorage !== actualSize || sizeOnStorage !== recordedSize) {
|
if (
|
||||||
|
recordedSize !== actualSize ||
|
||||||
|
sizeOnStorage !== actualSize ||
|
||||||
|
sizeOnStorage !== recordedSize ||
|
||||||
|
isConflicted
|
||||||
|
) {
|
||||||
const contentMatched = await isDocContentSame(doc.data, storageFileContent);
|
const contentMatched = await isDocContentSame(doc.data, storageFileContent);
|
||||||
errorFiles.push({ path, recordedSize, actualSize, storageSize: sizeOnStorage, contentMatched });
|
errorFiles.push({
|
||||||
|
path,
|
||||||
|
recordedSize,
|
||||||
|
actualSize,
|
||||||
|
storageSize: sizeOnStorage,
|
||||||
|
contentMatched,
|
||||||
|
isConflicted,
|
||||||
|
});
|
||||||
Logger(
|
Logger(
|
||||||
`Size mismatch for ${path}: ${recordedSize} (DB Recorded) , ${actualSize} (DB Stored) , ${sizeOnStorage} (Storage Stored), ${contentMatched ? "Content Matched" : "Content Mismatched"}`
|
`Size mismatch for ${path}: ${recordedSize} (DB Recorded) , ${actualSize} (DB Stored) , ${sizeOnStorage} (Storage Stored), ${contentMatched ? "Content Matched" : "Content Mismatched"} ${isConflicted ? "Conflicted" : "Not Conflicted"}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,24 +198,23 @@ export class ModuleMigration extends AbstractModule implements ICoreModule {
|
|||||||
// Probably restored by the user by resolving A or B on other device, We should overwrite the storage
|
// Probably restored by the user by resolving A or B on other device, We should overwrite the storage
|
||||||
// Also do not fix it automatically. It should be overwritten by replication.
|
// Also do not fix it automatically. It should be overwritten by replication.
|
||||||
const recoverable = errorFiles.filter((e) => {
|
const recoverable = errorFiles.filter((e) => {
|
||||||
return e.recordedSize === e.storageSize;
|
return e.recordedSize === e.storageSize && !e.isConflicted;
|
||||||
});
|
});
|
||||||
const unrecoverable = errorFiles.filter((e) => {
|
const unrecoverable = errorFiles.filter((e) => {
|
||||||
return e.recordedSize !== e.storageSize;
|
return e.recordedSize !== e.storageSize || e.isConflicted;
|
||||||
});
|
});
|
||||||
|
const fileInfo = (e: (typeof errorFiles)[0]) => {
|
||||||
|
return `${e.path} (M: ${e.recordedSize}, A: ${e.actualSize}, S: ${e.storageSize}) ${e.isConflicted ? "(Conflicted)" : ""}`;
|
||||||
|
};
|
||||||
const messageUnrecoverable =
|
const messageUnrecoverable =
|
||||||
unrecoverable.length > 0
|
unrecoverable.length > 0
|
||||||
? $msg("moduleMigration.fix0256.messageUnrecoverable", {
|
? $msg("moduleMigration.fix0256.messageUnrecoverable", {
|
||||||
filesNotRecoverable: unrecoverable
|
filesNotRecoverable: unrecoverable.map((e) => `- ${fileInfo(e)}`).join("\n"),
|
||||||
.map((e) => `- ${e.path} (M: ${e.recordedSize}, A: ${e.actualSize}, S: ${e.storageSize})`)
|
|
||||||
.join("\n"),
|
|
||||||
})
|
})
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
const message = $msg("moduleMigration.fix0256.message", {
|
const message = $msg("moduleMigration.fix0256.message", {
|
||||||
files: recoverable
|
files: recoverable.map((e) => `- ${fileInfo(e)}`).join("\n"),
|
||||||
.map((e) => `- ${e.path} (M: ${e.recordedSize}, A: ${e.actualSize}, S: ${e.storageSize})`)
|
|
||||||
.join("\n"),
|
|
||||||
messageUnrecoverable,
|
messageUnrecoverable,
|
||||||
});
|
});
|
||||||
const CHECK_IT_LATER = $msg("moduleMigration.fix0256.buttons.checkItLater");
|
const CHECK_IT_LATER = $msg("moduleMigration.fix0256.buttons.checkItLater");
|
||||||
|
|||||||
Reference in New Issue
Block a user