diff --git a/src/api/watch.ts b/src/api/watch.ts index d8ff2d1d3..20008375e 100644 --- a/src/api/watch.ts +++ b/src/api/watch.ts @@ -4,13 +4,14 @@ import { ipcRenderer } from 'electron'; import { ElectronFile, WatchMapping } from '../types'; import { getElectronFile } from '../services/fs'; import { getWatchMappings, setWatchMappings } from '../services/watch'; +import ElectronLog from 'electron-log'; export async function addWatchMapping( rootFolderName: string, folderPath: string, uploadStrategy: number ) { - folderPath = path.normalize(folderPath); + ElectronLog.log(`Adding watch mapping: ${folderPath}`); const watchMappings = getWatchMappings(); if (isMappingPresent(watchMappings, folderPath)) { throw new Error(`Watch mapping already exists`); @@ -93,23 +94,19 @@ export function registerWatcherFunctions( ) { ipcRenderer.removeAllListeners('watch-add'); ipcRenderer.removeAllListeners('watch-change'); - ipcRenderer.removeAllListeners('watch-unlink'); + ipcRenderer.removeAllListeners('watch-unlink-dir'); ipcRenderer.on('watch-add', async (_, filePath: string) => { - filePath = path.normalize( - filePath.split(path.sep).join(path.posix.sep) - ); + filePath = filePath.split(path.sep).join(path.posix.sep); + await addFile(await getElectronFile(filePath)); }); ipcRenderer.on('watch-unlink', async (_, filePath: string) => { - filePath = path.normalize( - filePath.split(path.sep).join(path.posix.sep) - ); + filePath = filePath.split(path.sep).join(path.posix.sep); + await removeFile(filePath); }); ipcRenderer.on('watch-unlink-dir', async (_, folderPath: string) => { - folderPath = path.normalize( - folderPath.split(path.sep).join(path.posix.sep) - ); + folderPath = folderPath.split(path.sep).join(path.posix.sep); await removeFolder(folderPath); }); } diff --git a/src/services/fs.ts b/src/services/fs.ts index 9565cb086..b5ef8eb11 100644 --- a/src/services/fs.ts +++ b/src/services/fs.ts @@ -184,12 +184,22 @@ export const getZipFileStream = async ( }; export async function isFolder(dirPath: string) { - return await fs - .stat(dirPath) - .then((stats) => { - return stats.isDirectory(); - }) - .catch(() => false); + try { + const stats = await fs.stat(dirPath); + return stats.isDirectory(); + } catch (e) { + let err = e; + // if code is defined, it's an error from fs.stat + if (typeof e.code !== 'undefined') { + // ENOENT means the file does not exist + if (e.code === 'ENOENT') { + return false; + } + err = Error(`fs error code: ${e.code}`); + } + logError(err, 'isFolder failed'); + return false; + } } export const convertBrowserStreamToNode = ( diff --git a/ui b/ui index 570f96b33..79f25d455 160000 --- a/ui +++ b/ui @@ -1 +1 @@ -Subproject commit 570f96b3315346b868678f5ede065e5ebfe3d7c3 +Subproject commit 79f25d455f26650ad78147f3c6d8100ae16a4ca1