fix(migration): skip migrate20251029 silently on fresh installs (#4268)
migrate20251029 unconditionally calls copyFiles() and deleteDir() on the legacy Images/Readest/Images path. On a fresh install where that directory never existed, both calls bubble up an OS error ("os error 2" / ENOENT) which is then caught one frame up by runMigrations() and printed as an Error migrating to version 20251029 in the console. Functionally harmless (migrationVersion is still advanced afterwards), but a misleading red herring for new users and anyone debugging startup logs.
Check fs.exists(oldDir) up front and return early if absent; also guard the deleteDir call in case copyFiles partially completed and the cleanup target is gone. No behavior change on machines that actually have the legacy layout.
This commit is contained in:
@@ -665,10 +665,20 @@ export class NativeAppService extends BaseAppService {
|
||||
const rootPath = await this.resolveFilePath('..', 'Data');
|
||||
const newDir = await this.fs.getPrefix('Images');
|
||||
const oldDir = await join(rootPath, 'Images', 'Readest', 'Images');
|
||||
const dirToDelete = await join(rootPath, 'Images', 'Readest');
|
||||
|
||||
// Skip silently on fresh installs that never had the legacy layout.
|
||||
// copyFiles / deleteDir would otherwise throw `os error 2` when the
|
||||
// old directory does not exist, which is harmless but noisy.
|
||||
if (!(await this.fs.exists(oldDir, 'None'))) {
|
||||
console.log('Migration 20251029: legacy Images/Readest/Images not found, skipping.');
|
||||
return;
|
||||
}
|
||||
|
||||
await copyFiles(this, oldDir, newDir);
|
||||
|
||||
const dirToDelete = await join(rootPath, 'Images', 'Readest');
|
||||
await this.deleteDir(dirToDelete, 'None', true);
|
||||
if (await this.fs.exists(dirToDelete, 'None')) {
|
||||
await this.deleteDir(dirToDelete, 'None', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user