Move into fs

This commit is contained in:
Manav Rathi 2024-04-14 18:12:19 +05:30
parent 0f1c2fa1cd
commit 59b9e3e586
No known key found for this signature in database
5 changed files with 18 additions and 14 deletions

View file

@ -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;

View file

@ -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));

View file

@ -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

View file

@ -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) {

View file

@ -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