c# - File existence check after a folder rename returns an incorrect value on UNC share -


on windows 7 (or server) box, have folder on unc share (cross machine unc, not localhost). rename folder, , check existence of file @ new folder location. though exists, takes 5 seconds file.exists return true on it.

full repro can found on https://github.com/davidebbo/npmfolderrenameissue. here core code:

// file doesn't exist yet // note presence of existence check triggers bug below!! console.writeline("exists (should false): " + file.exists("test/test2/myfile"));  // create directory, file in directory.createdirectory("test/subdir/test"); file.writealltext("test/subdir/test/myfile", "hello");  // rename directory directory.move("test/subdir/test", "test/test2");  var start = datetime.utcnow;  // list files @ new location. here, our file shows fine foreach (var path in directory.getfiles("test/test2")) {     console.writeline(path); }  (; ; ) {     // simple existence test. should true, when     // running on (cross machine) unc share, takes 5 seconds become true!     if (file.exists("test/test2/myfile")) break;      console.writeline("after {0} milliseconds, test/test2/myfile doesn't show existing",         (datetime.utcnow - start).totalmilliseconds);     thread.sleep(100); }  console.writeline("after {0} milliseconds, test/test2/myfile correctly shows existing!",     (datetime.utcnow - start).totalmilliseconds); 

so seems initial existence check causes existence value cached, causing bogus behavior.

questions: explanation this? what's best way avoid it?

note: issue arose when using npm (node package manager) on windows. code have here c# port of repro. see https://github.com/isaacs/npm/issues/2230 original node/npm issue. goal find way address it.

david, redirector implements negative "file not found" cache prevents client flooding server file not found requests. default cache time 5 seconds can modify filenotfoundcachelifetime registry value control cache or disable setting value 0.

details: http://technet.microsoft.com/en-us/library/ff686200(v=ws.10).aspx


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -