diff --git a/desktop/src/main/fs.ts b/desktop/src/main/fs.ts index cdf51aff0..749f21bf2 100644 --- a/desktop/src/main/fs.ts +++ b/desktop/src/main/fs.ts @@ -16,6 +16,8 @@ export const fsMkdirIfNeeded = (dirPath: string) => export const fsRmdir = (path: string) => fs.rmdir(path); +export const fsRm = (path: string) => fs.rm(path); + /** * Write a (web) ReadableStream to a file at the given {@link filePath}. * @@ -107,15 +109,3 @@ export const isFolder = async (dirPath: string) => { const stats = await fs.stat(dirPath); return stats.isDirectory(); }; - -export const deleteFile = async (filePath: string) => { - // Ensure it exists - if (!existsSync(filePath)) return; - - // And is a file - const stat = await fs.stat(filePath); - if (!stat.isFile()) throw new Error("Path is not a file"); - - // rm it - return fs.rm(filePath); -}; diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.ts index ae8047595..12bcc72bf 100644 --- a/desktop/src/main/ipc.ts +++ b/desktop/src/main/ipc.ts @@ -18,7 +18,7 @@ import { showUploadZipDialog, } from "./dialogs"; import { - deleteFile, + fsRm, fsRmdir, fsExists, fsMkdirIfNeeded, @@ -175,6 +175,10 @@ export const attachIPCHandlers = () => { ipcMain.handle("fsMkdirIfNeeded", (_, dirPath) => fsMkdirIfNeeded(dirPath)); + ipcMain.handle("fsRmdir", (_, path: string) => fsRmdir(path)); + + ipcMain.handle("fsRm", (_, path: string) => fsRm(path)); + // - FS Legacy ipcMain.handle( @@ -195,10 +199,6 @@ export const attachIPCHandlers = () => { moveFile(oldPath, newPath), ); - ipcMain.handle("fsRmdir", (_, path: string) => fsRmdir(path)); - - ipcMain.handle("deleteFile", (_, path: string) => deleteFile(path)); - // - Upload ipcMain.handle("getPendingUploads", () => getPendingUploads()); diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts index 9c9161260..d33e2b675 100644 --- a/desktop/src/preload.ts +++ b/desktop/src/preload.ts @@ -244,8 +244,7 @@ const moveFile = (oldPath: string, newPath: string): Promise => const fsRmdir = (path: string): Promise => ipcRenderer.invoke("fsRmdir", path); -const deleteFile = (path: string): Promise => - ipcRenderer.invoke("deleteFile", path); +const fsRm = (path: string): Promise => ipcRenderer.invoke("fsRm", path); // - Upload @@ -351,6 +350,7 @@ contextBridge.exposeInMainWorld("electron", { rename: fsRename, mkdirIfNeeded: fsMkdirIfNeeded, rmdir: fsRmdir, + rm: fsRm, }, // - FS legacy @@ -360,7 +360,6 @@ contextBridge.exposeInMainWorld("electron", { readTextFile, isFolder, moveFile, - deleteFile, // - Upload diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.ts index adf4e8313..0c5fb23ef 100644 --- a/web/apps/photos/src/services/export/index.ts +++ b/web/apps/photos/src/services/export/index.ts @@ -1147,7 +1147,7 @@ class ExportService { videoStream, ); } catch (e) { - await electron.deleteFile( + await electron.fs.rm( `${collectionExportPath}/${imageExportName}`, ); throw e; diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts index 2a3b156f2..8f72cb450 100644 --- a/web/apps/photos/src/utils/file/index.ts +++ b/web/apps/photos/src/utils/file/index.ts @@ -834,7 +834,7 @@ async function downloadFileDesktop( videoStream, ); } catch (e) { - await electron.deleteFile(`${downloadPath}/${imageExportName}`); + await electron.fs.rm(`${downloadPath}/${imageExportName}`); throw e; } } else { diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.ts index 62a992f49..301a95191 100644 --- a/web/packages/next/types/ipc.ts +++ b/web/packages/next/types/ipc.ts @@ -181,6 +181,13 @@ export interface Electron { * Delete the directory at the {@link path} if it is empty. */ rmdir: (path: string) => Promise; + + /** + * Equivalent of `rm`. + * + * Delete the file at {@link path}. + */ + rm: (path: string) => Promise; }; /* @@ -301,7 +308,6 @@ export interface Electron { readTextFile: (path: string) => Promise; isFolder: (dirPath: string) => Promise; moveFile: (oldPath: string, newPath: string) => Promise; - deleteFile: (path: string) => Promise; // - Upload