@@ -52,27 +52,30 @@ common.refreshTmpDir();
5252// time, the callback should be invoked again with proper values in stat object
5353let fileExists = false ;
5454
55- fs . watchFile ( enoentFile , { interval : 0 } , common . mustCall ( function ( curr , prev ) {
56- if ( ! fileExists ) {
57- // If the file does not exist, all the fields should be zero and the date
58- // fields should be UNIX EPOCH time
59- assert . deepStrictEqual ( curr , expectedStatObject ) ;
60- assert . deepStrictEqual ( prev , expectedStatObject ) ;
61- // Create the file now, so that the callback will be called back once the
62- // event loop notices it.
63- fs . closeSync ( fs . openSync ( enoentFile , 'w' ) ) ;
64- fileExists = true ;
65- } else {
66- // If the ino (inode) value is greater than zero, it means that the file is
67- // present in the filesystem and it has a valid inode number.
68- assert ( curr . ino > 0 ) ;
69- // As the file just got created, previous ino value should be lesser than
70- // or equal to zero (non-existent file).
71- assert ( prev . ino <= 0 ) ;
72- // Stop watching the file
73- fs . unwatchFile ( enoentFile ) ;
74- }
75- } , 2 ) ) ;
55+ const watcher =
56+ fs . watchFile ( enoentFile , { interval : 0 } , common . mustCall ( ( curr , prev ) => {
57+ if ( ! fileExists ) {
58+ // If the file does not exist, all the fields should be zero and the date
59+ // fields should be UNIX EPOCH time
60+ assert . deepStrictEqual ( curr , expectedStatObject ) ;
61+ assert . deepStrictEqual ( prev , expectedStatObject ) ;
62+ // Create the file now, so that the callback will be called back once the
63+ // event loop notices it.
64+ fs . closeSync ( fs . openSync ( enoentFile , 'w' ) ) ;
65+ fileExists = true ;
66+ } else {
67+ // If the ino (inode) value is greater than zero, it means that the file
68+ // is present in the filesystem and it has a valid inode number.
69+ assert ( curr . ino > 0 ) ;
70+ // As the file just got created, previous ino value should be lesser than
71+ // or equal to zero (non-existent file).
72+ assert ( prev . ino <= 0 ) ;
73+ // Stop watching the file
74+ fs . unwatchFile ( enoentFile ) ;
75+ }
76+ } , 2 ) ) ;
77+
78+ watcher . start ( ) ; // should not crash
7679
7780// Watch events should callback with a filename on supported systems.
7881// Omitting AIX. It works but not reliably.
0 commit comments