From 06eef0758c57085e976fcfe10c722a23df32c3b5 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 29 Aug 2023 14:03:17 +0530 Subject: [PATCH] check if file exists before attempting move --- apps/photos/src/services/export/index.ts | 90 ++++++++++++++---------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/apps/photos/src/services/export/index.ts b/apps/photos/src/services/export/index.ts index be433e26e..ae4e32d18 100644 --- a/apps/photos/src/services/export/index.ts +++ b/apps/photos/src/services/export/index.ts @@ -789,24 +789,28 @@ class ExportService { addLogLine( `moving image file ${imageExportPath} to trash folder` ); - await this.electronAPIs.moveFile( - imageExportPath, - getTrashedFileExportPath( - exportDir, - imageExportPath - ) - ); + if (this.exists(imageExportPath)) { + await this.electronAPIs.moveFile( + imageExportPath, + getTrashedFileExportPath( + exportDir, + imageExportPath + ) + ); + } const imageMetadataFileExportPath = getMetadataFileExportPath(imageExportPath); - await this.electronAPIs.moveFile( - imageMetadataFileExportPath, - getTrashedFileExportPath( - exportDir, - imageMetadataFileExportPath - ) - ); + if (this.exists(imageMetadataFileExportPath)) { + await this.electronAPIs.moveFile( + imageMetadataFileExportPath, + getTrashedFileExportPath( + exportDir, + imageMetadataFileExportPath + ) + ); + } const videoExportPath = getFileExportPath( collectionExportPath, @@ -815,22 +819,26 @@ class ExportService { addLogLine( `moving video file ${videoExportPath} to trash folder` ); - await this.electronAPIs.moveFile( - videoExportPath, - getTrashedFileExportPath( - exportDir, - videoExportPath - ) - ); + if (this.exists(videoExportPath)) { + await this.electronAPIs.moveFile( + videoExportPath, + getTrashedFileExportPath( + exportDir, + videoExportPath + ) + ); + } const videoMetadataFileExportPath = getMetadataFileExportPath(videoExportPath); - await this.electronAPIs.moveFile( - videoMetadataFileExportPath, - getTrashedFileExportPath( - exportDir, - videoMetadataFileExportPath - ) - ); + if (this.exists(videoMetadataFileExportPath)) { + await this.electronAPIs.moveFile( + videoMetadataFileExportPath, + getTrashedFileExportPath( + exportDir, + videoMetadataFileExportPath + ) + ); + } } else { const fileExportPath = getFileExportPath( collectionExportPath, @@ -843,19 +851,23 @@ class ExportService { addLogLine( `moving file ${fileExportPath} to ${trashedFilePath} trash folder` ); - await this.electronAPIs.moveFile( - fileExportPath, - trashedFilePath - ); + if (this.exists(fileExportPath)) { + await this.electronAPIs.moveFile( + fileExportPath, + trashedFilePath + ); + } const metadataFileExportPath = getMetadataFileExportPath(fileExportPath); - await this.electronAPIs.moveFile( - metadataFileExportPath, - getTrashedFileExportPath( - exportDir, - metadataFileExportPath - ) - ); + if (this.exists(metadataFileExportPath)) { + await this.electronAPIs.moveFile( + metadataFileExportPath, + getTrashedFileExportPath( + exportDir, + metadataFileExportPath + ) + ); + } } } catch (e) { await this.addFileExportedRecord(