Ver código fonte

Move into fs

Manav Rathi 1 ano atrás
pai
commit
59b9e3e586

+ 2 - 5
desktop/src/main/fs.ts

@@ -14,6 +14,8 @@ export const fsRename = (oldPath: string, newPath: string) =>
 export const fsMkdirIfNeeded = (dirPath: string) =>
     fs.mkdir(dirPath, { recursive: true });
 
+export const fsRmdir = (path: string) => fs.rmdir(path);
+
 /**
  * Write a (web) ReadableStream to a file at the given {@link filePath}.
  *
@@ -106,11 +108,6 @@ export const isFolder = async (dirPath: string) => {
     return stats.isDirectory();
 };
 
-export const deleteFolder = async (folderPath: string) => {
-    // rm -rf it
-    await fs.rmdir(folderPath);
-};
-
 export const deleteFile = async (filePath: string) => {
     // Ensure it exists
     if (!existsSync(filePath)) return;

+ 2 - 2
desktop/src/main/ipc.ts

@@ -19,7 +19,7 @@ import {
 } from "./dialogs";
 import {
     deleteFile,
-    deleteFolder,
+    fsRmdir,
     fsExists,
     fsMkdirIfNeeded,
     fsRename,
@@ -195,7 +195,7 @@ export const attachIPCHandlers = () => {
         moveFile(oldPath, newPath),
     );
 
-    ipcMain.handle("deleteFolder", (_, path: string) => deleteFolder(path));
+    ipcMain.handle("fsRmdir", (_, path: string) => fsRmdir(path));
 
     ipcMain.handle("deleteFile", (_, path: string) => deleteFile(path));
 

+ 3 - 3
desktop/src/preload.ts

@@ -241,8 +241,8 @@ const isFolder = (dirPath: string): Promise<boolean> =>
 const moveFile = (oldPath: string, newPath: string): Promise<void> =>
     ipcRenderer.invoke("moveFile", oldPath, newPath);
 
-const deleteFolder = (path: string): Promise<void> =>
-    ipcRenderer.invoke("deleteFolder", path);
+const fsRmdir = (path: string): Promise<void> =>
+    ipcRenderer.invoke("fsRmdir", path);
 
 const deleteFile = (path: string): Promise<void> =>
     ipcRenderer.invoke("deleteFile", path);
@@ -350,6 +350,7 @@ contextBridge.exposeInMainWorld("electron", {
         exists: fsExists,
         rename: fsRename,
         mkdirIfNeeded: fsMkdirIfNeeded,
+        rmdir: fsRmdir,
     },
 
     // - FS legacy
@@ -359,7 +360,6 @@ contextBridge.exposeInMainWorld("electron", {
     readTextFile,
     isFolder,
     moveFile,
-    deleteFolder,
     deleteFile,
 
     // - Upload

+ 3 - 2
web/apps/photos/src/services/export/index.ts

@@ -564,6 +564,7 @@ class ExportService {
         exportFolder: string,
         isCanceled: CancellationStatus,
     ) {
+        const fs = ensureElectron().fs;
         try {
             const exportRecord = await this.getExportRecord(exportFolder);
             const collectionIDPathMap =
@@ -598,11 +599,11 @@ class ExportService {
                     );
                     try {
                         // delete the collection metadata folder
-                        await ensureElectron().deleteFolder(
+                        await fs.rmdir(
                             getMetadataFolderExportPath(collectionExportPath),
                         );
                         // delete the collection folder
-                        await ensureElectron().deleteFolder(
+                        await fs.rmdir(
                             collectionExportPath,
                         );
                     } catch (e) {

+ 8 - 2
web/packages/next/types/ipc.ts

@@ -163,7 +163,7 @@ export interface Electron {
         exists: (path: string) => Promise<boolean>;
 
         /**
-         * mkdir -p
+         * Equivalent of `mkdir -p`.
          *
          * Create a directory at the given path if it does not already exist.
          * Any parent directories in the path that don't already exist will also
@@ -174,6 +174,13 @@ export interface Electron {
 
         /** Rename {@link oldPath} to {@link newPath} */
         rename: (oldPath: string, newPath: string) => Promise<void>;
+
+        /**
+         * Equivalent of `rmdir`.
+         *
+         * Delete the directory at the {@link path} if it is empty.
+         */
+        rmdir: (path: string) => Promise<void>;
     };
 
     /*
@@ -294,7 +301,6 @@ export interface Electron {
     readTextFile: (path: string) => Promise<string>;
     isFolder: (dirPath: string) => Promise<boolean>;
     moveFile: (oldPath: string, newPath: string) => Promise<void>;
-    deleteFolder: (path: string) => Promise<void>;
     deleteFile: (path: string) => Promise<void>;
 
     // - Upload