Merge pull request #145 from ente-io/watch-folder-issue
Watch folder issue
This commit is contained in:
commit
98c4d3c111
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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 = (
|
||||
|
|
2
ui
2
ui
|
@ -1 +1 @@
|
|||
Subproject commit 570f96b3315346b868678f5ede065e5ebfe3d7c3
|
||||
Subproject commit 79f25d455f26650ad78147f3c6d8100ae16a4ca1
|
Loading…
Reference in a new issue