π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Unlegacy isDir
Manav Rathiee895069234a
diff --git a/desktop/src/main/fs.ts b/desktop/src/main/fs.tsindex 36de710c34..2428d3a80c 100644--- a/desktop/src/main/fs.ts+++ b/desktop/src/main/fs.ts@@ -22,10 +22,8 @@ export const fsReadTextFile = async (filePath: string) =>export const fsWriteFile = (path: string, contents: string) =>fs.writeFile(path, contents);-/* TODO: Audit below this */--export const isFolder = async (dirPath: string) => {+export const fsIsDir = async (dirPath: string) => {if (!existsSync(dirPath)) return false;- const stats = await fs.stat(dirPath);- return stats.isDirectory();+ const stat = await fs.stat(dirPath);+ return stat.isDirectory();};diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.tsindex 3d4e15c992..e307ad167d 100644--- a/desktop/src/main/ipc.ts+++ b/desktop/src/main/ipc.ts@@ -19,13 +19,13 @@ import {} from "./dialogs";import {fsExists,+ fsIsDir,fsMkdirIfNeeded,fsReadTextFile,fsRename,fsRm,fsRmdir,fsWriteFile,- isFolder,} from "./fs";import { logToDisk } from "./log";import {@@ -55,7 +55,6 @@ import {} from "./services/upload";import {addWatchMapping,- folderWatchesAndFilesTherein,getWatchMappings,removeWatchMapping,updateWatchMappingIgnoredFiles,@@ -133,6 +132,8 @@ export const attachIPCHandlers = () => {fsWriteFile(path, contents),);+ ipcMain.handle("fsIsDir", (_, dirPath: string) => fsIsDir(dirPath));+// - ConversionipcMain.handle("convertToJPEG", (_, fileData, filename) =>@@ -184,10 +185,6 @@ export const attachIPCHandlers = () => {ipcMain.handle("showUploadZipDialog", () => showUploadZipDialog());- // - FS Legacy-- ipcMain.handle("isFolder", (_, dirPath: string) => isFolder(dirPath));-// - UploadipcMain.handle("getPendingUploads", () => getPendingUploads());@@ -239,10 +236,6 @@ export const attachFSWatchIPCHandlers = (watcher: FSWatcher) => {removeWatchMapping(watcher, folderPath),);- ipcMain.handle("folderWatchesAndFilesTherein", () =>- folderWatchesAndFilesTherein(watcher),- );-ipcMain.handle("getWatchMappings", () => getWatchMappings());ipcMain.handle(diff --git a/desktop/src/main/services/watch.ts b/desktop/src/main/services/watch.tsindex 125d65bf9a..1d466d4156 100644--- a/desktop/src/main/services/watch.ts+++ b/desktop/src/main/services/watch.ts@@ -1,13 +1,7 @@import type { FSWatcher } from "chokidar";import ElectronLog from "electron-log";-import {- FolderWatch,- WatchStoreType,- type ElectronFile,-} from "../../types/ipc";-import { isFolder } from "../fs";+import { FolderWatch, WatchStoreType } from "../../types/ipc";import { watchStore } from "../stores/watch.store";-import { getDirFiles } from "./fs";export const addWatchMapping = async (watcher: FSWatcher,@@ -105,26 +99,3 @@ export function getWatchMappings() {function setWatchMappings(watchMappings: WatchStoreType["mappings"]) {watchStore.set("mappings", watchMappings);}--export const folderWatchesAndFilesTherein = async (- watcher: FSWatcher,-): Promise<[watch: FolderWatch, files: ElectronFile[]][]> => {- const mappings = await getWatchMappings();-- const activeMappings = [];- for (const mapping of mappings) {- const mappingExists = await isFolder(mapping.folderPath);- if (!mappingExists) {- await removeWatchMapping(watcher, mapping.folderPath);- } else {- activeMappings.push(mapping);- }- }-- return Promise.all(- activeMappings.map(async (mapping) => [- mapping,- await getDirFiles(mapping.folderPath),- ]),- );-};diff --git a/desktop/src/preload.ts b/desktop/src/preload.tsindex a3deb1fae0..9341f02f23 100644--- a/desktop/src/preload.ts+++ b/desktop/src/preload.ts@@ -118,6 +118,9 @@ const fsReadTextFile = (path: string): Promise<string> =>const fsWriteFile = (path: string, contents: string): Promise<void> =>ipcRenderer.invoke("fsWriteFile", path, contents);+const fsIsDir = (dirPath: string): Promise<boolean> =>+ ipcRenderer.invoke("fsIsDir", dirPath);+// - AUDIT below this// - Conversion@@ -220,10 +223,6 @@ const addWatchMapping = (const removeWatchMapping = (folderPath: string): Promise<void> =>ipcRenderer.invoke("removeWatchMapping", folderPath);-const folderWatchesAndFilesTherein = (): Promise<- [watch: FolderWatch, files: ElectronFile[]][]-> => ipcRenderer.invoke("folderWatchesAndFilesTherein");-const getWatchMappings = (): Promise<FolderWatch[]> =>ipcRenderer.invoke("getWatchMappings");@@ -239,11 +238,6 @@ const updateWatchMappingIgnoredFiles = (): Promise<void> =>ipcRenderer.invoke("updateWatchMappingIgnoredFiles", folderPath, files);-// - FS Legacy--const isFolder = (dirPath: string): Promise<boolean> =>- ipcRenderer.invoke("isFolder", dirPath);-// - Uploadconst getPendingUploads = (): Promise<{@@ -327,6 +321,7 @@ contextBridge.exposeInMainWorld("electron", {rm: fsRm,readTextFile: fsReadTextFile,writeFile: fsWriteFile,+ isDir: fsIsDir,},// - Conversion@@ -347,7 +342,6 @@ contextBridge.exposeInMainWorld("electron", {showUploadZipDialog,// - Watch- folderWatchesAndFilesTherein,registerWatcherFunctions,addWatchMapping,removeWatchMapping,@@ -355,10 +349,6 @@ contextBridge.exposeInMainWorld("electron", {updateWatchMappingSyncedFiles,updateWatchMappingIgnoredFiles,- // - FS legacy- // TODO: Move these into fs + document + rename if needed- isFolder,-// - UploadgetPendingUploads,diff --git a/web/apps/photos/src/services/watch.ts b/web/apps/photos/src/services/watch.tsindex e6e5004ce0..bb11fa67e1 100644--- a/web/apps/photos/src/services/watch.ts+++ b/web/apps/photos/src/services/watch.ts@@ -538,8 +538,7 @@ class WatchFolderService {async isFolder(folderPath: string) {try {- const isFolder = await ensureElectron().isFolder(folderPath);- return isFolder;+ return await ensureElectron().fs.isDir(folderPath);} catch (e) {log.error("error while checking if folder exists", e);}@@ -675,8 +674,8 @@ const syncWithDisk = async (const nonExistentFolderPaths: string[] = [];for (const mapping of mappings) {- const active = await electron.isFolder(mapping.folderPath);- if (!active) nonExistentFolderPaths.push(mapping.folderPath);+ const valid = await electron.fs.isDir(mapping.folderPath);+ if (!valid) nonExistentFolderPaths.push(mapping.folderPath);else activeMappings.push(mapping);}diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.tsindex 800befa7fb..348f815bb9 100644--- a/web/packages/next/types/ipc.ts+++ b/web/packages/next/types/ipc.ts@@ -199,6 +199,12 @@ export interface Electron {* @param contents The string contents to write.*/writeFile: (path: string, contents: string) => Promise<void>;++ /**+ * Return true if there is an item at {@link dirPath}, and it is as+ * directory.+ */+ isDir: (dirPath: string) => Promise<boolean>;};/*@@ -321,9 +327,6 @@ export interface Electron {files: FolderWatch["ignoredFiles"],) => Promise<void>;- // - FS legacy- isFolder: (dirPath: string) => Promise<boolean>;-// - UploadgetPendingUploads: () => Promise<{