Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-watching a path does not honour ignoreInitial #1386

Open
TobyEalden opened this issue Nov 12, 2024 · 5 comments · May be fixed by #1388
Open

Re-watching a path does not honour ignoreInitial #1386

TobyEalden opened this issue Nov 12, 2024 · 5 comments · May be fixed by #1388

Comments

@TobyEalden
Copy link

Describe the bug
This is a duplicate of #1185, which has been closed, however the test case still fails.

With ignoreInitial set to false, when first adding a directory all the initial files are emitted. If the directory is un-watched and then watched again at some point in the future, the initial files are not emitted.

Versions (please complete the following information):

  • Chokidar version 4.0.1
  • Node version 18.18.2
  • OS version: macOS 15.1

To Reproduce:

import chokidar from "chokidar";
const directory = ".";
const options = {
  disableGlobbing: true,
  depth: 0,
};
let watcher = chokidar.watch(directory, options);
watcher.on("all", handleAll);
function handleAll(event, path) {
  console.log(`${event}: ${path}`);
}
watcher.on("ready", handleReady);
async function handleReady() {
  console.log("Ready!");
  await watcher.unwatch(directory);
  console.log("Unwatched!");
  watcher.add(directory);
  console.log("Re-watched!");
}

Expected behavior
Un-watching and then re-watching a directory should cause the initial files to be emitted if ignoreInitial is false.

@43081j
Copy link
Collaborator

43081j commented Nov 13, 2024

Seems to make sense, assuming that is the intended use of "initial files".

If we define "initial" as any time you start watching a directory, we should fix this

Good to get the opinion of @paulmillr here since it's from before me

@paulmillr
Copy link
Owner

paulmillr commented Nov 13, 2024

Idk how would we track these files

@43081j
Copy link
Collaborator

43081j commented Nov 13, 2024

Presumably we currently read the directory and emit all the children. Then when we unwatch and watch it, we won't read through it a second time

Maybe it's as simple as always reading the directory when you watch one?

So we don't need to track anything extra for it. I might be missing something though in my understanding

@TobyEalden TobyEalden linked a pull request Nov 13, 2024 that will close this issue
@TobyEalden
Copy link
Author

It looks like _handleRead already deals with the initial load, but it uses the previous directory entries to determine if it needs to emit or not

The pull request #1388 handles this by closing the descendants as well as the unwatched path in closePath, but I'm not sure of the function of (or interaction with) ignoredPaths...

@43081j
Copy link
Collaborator

43081j commented Nov 15, 2024

feels like it makes sense to me. when you remove a watched path, clearing all of its children

we just need to decide if this is a breaking change or not and if its the behaviour we're all agreed on

as it means we will start emitting events which we didn't used to emit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants