On Sun, Apr 14, 2013 at 6:16 PM, Gagle <[email protected]> wrote: > From docs: > >> Filename Argument >> >> Providing filename argument in the callback is not supported on every >> platform (currently it's only supported on Linux and Windows). Even on >> supported platforms filename is not always guaranteed to be provided. >> Therefore, don't assume that filename argument is always provided in the >> callback, and have some fallback logic if it is null. >> >> fs.watch('somedir', function (event, filename) { >> console.log('event is: ' + event); >> if (filename) { >> console.log('filename provided: ' + filename); >> } else { >> console.log('filename not provided'); >> } >> }); > > > There are 2 available events: rename and change. When a file/dir is deleted > a rename event is emitted and the filename is null. This is the only case > where the filename parameter is null. With other operations the filename > seems that is always provided. > > My question is: > > The example from the docs doesn't show if the filename can be null because > the underlying mechanism is not reliable and sometimes the filename is > provided and sometimes is null, or it can be null depending on the event and > the operation. > > For example, when a file is modified, a change event and the filename are > returned. Can I rely on the filename or it can be null even in change > events? > > Thanks
The short answer is: No, you can't. The long answer is: Don't depend on it. The change event may be generated by a rename(), in which case the watched file path no longer exists. The details vary across platforms. -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
