Merge pull request #3662 from lohxt1/revert/rename-item-watcher-fix

revert: rename-item watcher fix -- tbd
This commit is contained in:
lohit 2024-12-16 14:53:12 +05:30 committed by GitHub
commit b9ec0acab4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -349,10 +349,10 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
// rename item // rename item
ipcMain.handle('renderer:rename-item', async (event, oldPath, newPath, newName) => { ipcMain.handle('renderer:rename-item', async (event, oldPath, newPath, newName) => {
const tempDir = path.join(os.tmpdir(), `temp-folder-${Date.now()}`); const tempDir = path.join(os.tmpdir(), `temp-folder-${Date.now()}`);
const parentDir = path.dirname(oldPath); // const parentDir = path.dirname(oldPath);
const isWindowsOSAndNotWSLAndItemHasSubDirectories = isDirectory(oldPath) && isWindowsOS() && !isWSLPath(oldPath) && hasSubDirectories(oldPath); const isWindowsOSAndNotWSLAndItemHasSubDirectories = isDirectory(oldPath) && isWindowsOS() && !isWSLPath(oldPath) && hasSubDirectories(oldPath);
let parentDirUnwatched = false; // let parentDirUnwatched = false;
let parentDirRewatched = false; // let parentDirRewatched = false;
try { try {
// Normalize paths if they are WSL paths // Normalize paths if they are WSL paths
@ -376,8 +376,8 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
moveRequestUid(bruFile, newBruFilePath); moveRequestUid(bruFile, newBruFilePath);
} }
watcher.unlinkItemPathInWatcher(parentDir); // watcher.unlinkItemPathInWatcher(parentDir);
parentDirUnwatched = true; // parentDirUnwatched = true;
/** /**
* If it is windows OS * If it is windows OS
@ -396,8 +396,8 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
} else { } else {
await fs.renameSync(oldPath, newPath); await fs.renameSync(oldPath, newPath);
} }
watcher.addItemPathInWatcher(parentDir); // watcher.addItemPathInWatcher(parentDir);
parentDirRewatched = true; // parentDirRewatched = true;
return newPath; return newPath;
} }
@ -424,9 +424,9 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
} catch (error) { } catch (error) {
// in case an error occurs during the rename file operations after unlinking the parent dir // in case an error occurs during the rename file operations after unlinking the parent dir
// and the rewatch fails, we need to add it back to watcher // and the rewatch fails, we need to add it back to watcher
if (parentDirUnwatched && !parentDirRewatched) { // if (parentDirUnwatched && !parentDirRewatched) {
watcher.addItemPathInWatcher(parentDir); // watcher.addItemPathInWatcher(parentDir);
} // }
// in case the rename file operations fails, and we see that the temp dir exists // in case the rename file operations fails, and we see that the temp dir exists
// and the old path does not exist, we need to restore the data from the temp dir to the old path // and the old path does not exist, we need to restore the data from the temp dir to the old path