From 9fa7cb266c6122bf7829b24fca841bd2f7bce0fc Mon Sep 17 00:00:00 2001 From: loveheaven Date: Fri, 22 May 2026 23:06:36 +0800 Subject: [PATCH] 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. --- apps/readest-app/src/services/nativeAppService.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/readest-app/src/services/nativeAppService.ts b/apps/readest-app/src/services/nativeAppService.ts index adbdc796..a345bca0 100644 --- a/apps/readest-app/src/services/nativeAppService.ts +++ b/apps/readest-app/src/services/nativeAppService.ts @@ -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); + } } }