Remove unnecessary checks
It is simpler for us to parallel the rm command than our bespoke variant.
This commit is contained in:
parent
59b9e3e586
commit
eb64a00ed2
6 changed files with 18 additions and 23 deletions
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -244,8 +244,7 @@ const moveFile = (oldPath: string, newPath: string): Promise<void> =>
|
|||
const fsRmdir = (path: string): Promise<void> =>
|
||||
ipcRenderer.invoke("fsRmdir", path);
|
||||
|
||||
const deleteFile = (path: string): Promise<void> =>
|
||||
ipcRenderer.invoke("deleteFile", path);
|
||||
const fsRm = (path: string): Promise<void> => 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
|
||||
|
||||
|
|
|
@ -1147,7 +1147,7 @@ class ExportService {
|
|||
videoStream,
|
||||
);
|
||||
} catch (e) {
|
||||
await electron.deleteFile(
|
||||
await electron.fs.rm(
|
||||
`${collectionExportPath}/${imageExportName}`,
|
||||
);
|
||||
throw e;
|
||||
|
|
|
@ -834,7 +834,7 @@ async function downloadFileDesktop(
|
|||
videoStream,
|
||||
);
|
||||
} catch (e) {
|
||||
await electron.deleteFile(`${downloadPath}/${imageExportName}`);
|
||||
await electron.fs.rm(`${downloadPath}/${imageExportName}`);
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -181,6 +181,13 @@ export interface Electron {
|
|||
* Delete the directory at the {@link path} if it is empty.
|
||||
*/
|
||||
rmdir: (path: string) => Promise<void>;
|
||||
|
||||
/**
|
||||
* Equivalent of `rm`.
|
||||
*
|
||||
* Delete the file at {@link path}.
|
||||
*/
|
||||
rm: (path: string) => Promise<void>;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -301,7 +308,6 @@ export interface Electron {
|
|||
readTextFile: (path: string) => Promise<string>;
|
||||
isFolder: (dirPath: string) => Promise<boolean>;
|
||||
moveFile: (oldPath: string, newPath: string) => Promise<void>;
|
||||
deleteFile: (path: string) => Promise<void>;
|
||||
|
||||
// - Upload
|
||||
|
||||
|
|
Loading…
Reference in a new issue