Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Audit rename

Manav Rathi72dd47fa7b7f
diff --git a/desktop/src/main/fs.ts b/desktop/src/main/fs.ts
index 0da89fb005..a9138471c0 100644
--- a/desktop/src/main/fs.ts
+++ b/desktop/src/main/fs.ts
@@ -8,6 +8,9 @@ import { Readable } from "node:stream";
export const fsExists = (path: string) => existsSync(path);
+export const fsRename = (oldPath: string, newPath: string) =>
+ fs.rename(oldPath, newPath);
+
/**
* Write a (web) ReadableStream to a file at the given {@link filePath}.
*
@@ -115,11 +118,6 @@ export const deleteFolder = async (folderPath: string) => {
await fs.rmdir(folderPath);
};
-export const rename = async (oldPath: string, newPath: string) => {
- if (!existsSync(oldPath)) throw new Error("Path does not exist");
- await fs.rename(oldPath, newPath);
-};
-
export const deleteFile = async (filePath: string) => {
// Ensure it exists
if (!existsSync(filePath)) return;
diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.ts
index 180e68cdcf..9addcc4eba 100644
--- a/desktop/src/main/ipc.ts
+++ b/desktop/src/main/ipc.ts
@@ -22,10 +22,10 @@ import {
deleteFile,
deleteFolder,
fsExists,
+ fsRename,
isFolder,
moveFile,
readTextFile,
- rename,
saveFileToDisk,
saveStreamToDisk,
} from "./fs";
@@ -169,6 +169,10 @@ export const attachIPCHandlers = () => {
ipcMain.handle("fsExists", (_, path) => fsExists(path));
+ ipcMain.handle("fsRename", (_, oldPath: string, newPath: string) =>
+ fsRename(oldPath, newPath),
+ );
+
// - FS Legacy
ipcMain.handle("checkExistsAndCreateDir", (_, dirPath) =>
@@ -197,10 +201,6 @@ export const attachIPCHandlers = () => {
ipcMain.handle("deleteFile", (_, path: string) => deleteFile(path));
- ipcMain.handle("rename", (_, oldPath: string, newPath: string) =>
- rename(oldPath, newPath),
- );
-
// - Upload
ipcMain.handle("getPendingUploads", () => getPendingUploads());
diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts
index 2db39e2290..2ea6a81bd7 100644
--- a/desktop/src/preload.ts
+++ b/desktop/src/preload.ts
@@ -99,6 +99,9 @@ const skipAppUpdate = (version: string) => {
const fsExists = (path: string): Promise<boolean> =>
ipcRenderer.invoke("fsExists", path);
+const fsRename = (oldPath: string, newPath: string): Promise<void> =>
+ ipcRenderer.invoke("fsRename", oldPath, newPath);
+
// - AUDIT below this
// - Conversion
@@ -244,9 +247,6 @@ const deleteFolder = (path: string): Promise<void> =>
const deleteFile = (path: string): Promise<void> =>
ipcRenderer.invoke("deleteFile", path);
-const rename = (oldPath: string, newPath: string): Promise<void> =>
- ipcRenderer.invoke("rename", oldPath, newPath);
-
// - Upload
const getPendingUploads = (): Promise<{
@@ -348,6 +348,7 @@ contextBridge.exposeInMainWorld("electron", {
// - FS
fs: {
exists: fsExists,
+ rename: fsRename,
},
// - FS legacy
@@ -360,7 +361,6 @@ contextBridge.exposeInMainWorld("electron", {
moveFile,
deleteFolder,
deleteFile,
- rename,
// - Upload
diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.ts
index 5e956b7e2b..fbc4e98741 100644
--- a/web/apps/photos/src/services/export/index.ts
+++ b/web/apps/photos/src/services/export/index.ts
@@ -513,7 +513,7 @@ class ExportService {
newCollectionExportName,
);
try {
- await ensureElectron().rename(
+ await ensureElectron().fs.rename(
oldCollectionExportPath,
newCollectionExportPath,
);
@@ -1168,7 +1168,7 @@ class ExportService {
};
rename = (oldPath: string, newPath: string) => {
- return ensureElectron().rename(oldPath, newPath);
+ return ensureElectron().fs.rename(oldPath, newPath);
};
checkExistsAndCreateDir = (path: string) => {
diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.ts
index 82e4c2eb11..534184ef4e 100644
--- a/web/packages/next/types/ipc.ts
+++ b/web/packages/next/types/ipc.ts
@@ -155,15 +155,14 @@ export interface Electron {
* or watching some folders for changes and syncing them automatically.
*
* Towards this end, this fs object provides some generic file system access
- * functions that are needed for such features. In addition, there are other
- * feature specific methods too in the top level electron object.
+ * functions that are needed for such features (in some cases, there are
+ * other feature specific methods too in the top level electron object).
*/
fs: {
- /**
- * Return true if there is a file or directory at the given
- * {@link path}.
- */
+ /** Return true if there is an item at the given {@link path}. */
exists: (path: string) => Promise<boolean>;
+ /** Rename {@link oldPath} to {@link newPath} */
+ rename: (oldPath: string, newPath: string) => Promise<void>;
};
/*
@@ -287,7 +286,6 @@ export interface Electron {
moveFile: (oldPath: string, newPath: string) => Promise<void>;
deleteFolder: (path: string) => Promise<void>;
deleteFile: (path: string) => Promise<void>;
- rename: (oldPath: string, newPath: string) => Promise<void>;
// - Upload