Updates
This commit is contained in:
+17
-10
@@ -11,10 +11,6 @@ export default async function watchFolders({
|
||||
let timeout: any;
|
||||
const UPDATE_TIMEOUT = 200;
|
||||
|
||||
if (global.SYNCING) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const dirs = folders;
|
||||
|
||||
@@ -89,17 +85,26 @@ export default async function watchFolders({
|
||||
await delay();
|
||||
|
||||
fs.watch(dirPath, { recursive: true }, (evt, fileName) => {
|
||||
if (global.SYNCING) return;
|
||||
console.log("Folder Changed", evt, fileName);
|
||||
|
||||
if (fs.existsSync(global.SYNCING_FILE)) {
|
||||
console.log("Existing Sync found. Returning ...");
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(timeout);
|
||||
|
||||
timeout = setTimeout(() => {
|
||||
global.SYNCING = true;
|
||||
console.log("Folder Syncing in progress ...");
|
||||
console.log(
|
||||
`Writing Sync File =>${global.SYNCING_FILE}`
|
||||
);
|
||||
fs.writeFileSync(
|
||||
global.SYNCING_FILE,
|
||||
`SYNCING Folder: evt:${evt} :: fileName:${fileName}`
|
||||
);
|
||||
sync({ dirPath, dirs, options });
|
||||
setTimeout(() => {
|
||||
global.SYNCING = false;
|
||||
process.exit(global.SYNC_SUCCESS_EXIT_CODE);
|
||||
}, 500);
|
||||
process.exit(global.SYNC_SUCCESS_EXIT_CODE);
|
||||
}, INTERVAL);
|
||||
});
|
||||
}
|
||||
@@ -188,4 +193,6 @@ function sync({ options, dirs, dirPath, init }: SyncFoldersSyncFnParams) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Folder Sync Complete. Exiting ...");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user