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 { ElectronFile, WatchMapping } from '../types';
|
||||||
import { getElectronFile } from '../services/fs';
|
import { getElectronFile } from '../services/fs';
|
||||||
import { getWatchMappings, setWatchMappings } from '../services/watch';
|
import { getWatchMappings, setWatchMappings } from '../services/watch';
|
||||||
|
import ElectronLog from 'electron-log';
|
||||||
|
|
||||||
export async function addWatchMapping(
|
export async function addWatchMapping(
|
||||||
rootFolderName: string,
|
rootFolderName: string,
|
||||||
folderPath: string,
|
folderPath: string,
|
||||||
uploadStrategy: number
|
uploadStrategy: number
|
||||||
) {
|
) {
|
||||||
folderPath = path.normalize(folderPath);
|
ElectronLog.log(`Adding watch mapping: ${folderPath}`);
|
||||||
const watchMappings = getWatchMappings();
|
const watchMappings = getWatchMappings();
|
||||||
if (isMappingPresent(watchMappings, folderPath)) {
|
if (isMappingPresent(watchMappings, folderPath)) {
|
||||||
throw new Error(`Watch mapping already exists`);
|
throw new Error(`Watch mapping already exists`);
|
||||||
|
@ -93,23 +94,19 @@ export function registerWatcherFunctions(
|
||||||
) {
|
) {
|
||||||
ipcRenderer.removeAllListeners('watch-add');
|
ipcRenderer.removeAllListeners('watch-add');
|
||||||
ipcRenderer.removeAllListeners('watch-change');
|
ipcRenderer.removeAllListeners('watch-change');
|
||||||
ipcRenderer.removeAllListeners('watch-unlink');
|
ipcRenderer.removeAllListeners('watch-unlink-dir');
|
||||||
ipcRenderer.on('watch-add', async (_, filePath: string) => {
|
ipcRenderer.on('watch-add', async (_, filePath: string) => {
|
||||||
filePath = path.normalize(
|
filePath = filePath.split(path.sep).join(path.posix.sep);
|
||||||
filePath.split(path.sep).join(path.posix.sep)
|
|
||||||
);
|
|
||||||
await addFile(await getElectronFile(filePath));
|
await addFile(await getElectronFile(filePath));
|
||||||
});
|
});
|
||||||
ipcRenderer.on('watch-unlink', async (_, filePath: string) => {
|
ipcRenderer.on('watch-unlink', async (_, filePath: string) => {
|
||||||
filePath = path.normalize(
|
filePath = filePath.split(path.sep).join(path.posix.sep);
|
||||||
filePath.split(path.sep).join(path.posix.sep)
|
|
||||||
);
|
|
||||||
await removeFile(filePath);
|
await removeFile(filePath);
|
||||||
});
|
});
|
||||||
ipcRenderer.on('watch-unlink-dir', async (_, folderPath: string) => {
|
ipcRenderer.on('watch-unlink-dir', async (_, folderPath: string) => {
|
||||||
folderPath = path.normalize(
|
folderPath = folderPath.split(path.sep).join(path.posix.sep);
|
||||||
folderPath.split(path.sep).join(path.posix.sep)
|
|
||||||
);
|
|
||||||
await removeFolder(folderPath);
|
await removeFolder(folderPath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,12 +184,22 @@ export const getZipFileStream = async (
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function isFolder(dirPath: string) {
|
export async function isFolder(dirPath: string) {
|
||||||
return await fs
|
try {
|
||||||
.stat(dirPath)
|
const stats = await fs.stat(dirPath);
|
||||||
.then((stats) => {
|
return stats.isDirectory();
|
||||||
return stats.isDirectory();
|
} catch (e) {
|
||||||
})
|
let err = e;
|
||||||
.catch(() => false);
|
// 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 = (
|
export const convertBrowserStreamToNode = (
|
||||||
|
|
2
ui
2
ui
|
@ -1 +1 @@
|
||||||
Subproject commit 570f96b3315346b868678f5ede065e5ebfe3d7c3
|
Subproject commit 79f25d455f26650ad78147f3c6d8100ae16a4ca1
|
Loading…
Reference in a new issue