This commit is contained in:
Benjamin Toby
2025-07-15 10:02:20 +01:00
parent 8865292893
commit a71614cb0f
18 changed files with 99 additions and 34 deletions
+17 -10
View File
@@ -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 ...");
}