My question is a slight variation in the question What is the best way to check if a file exists on Windows? with some specific reservations. In particular, the data is located on a mapped drive, and the SMB 2.0 protocol is used. (By definition, this requires that the drive be mapped to a Vista machine on a Vista or Server 2008 machine.)
The problem with the answers received in response to the above question is that SMB 2.0 caches a bunch of metadata, including the file names in this directory. As a result, if you test the existence of the file you just created, then the _access, access, GetFileAttributes and CreateFile functions (and possibly others) will use cached information to answer the question “does this file exist?” If the file was recently created by another user, the cache indicates that the file is missing, despite the fact that it really exists. I installed test environments to test this, and I can confirm that the SMB2 client does not generate traffic for a few seconds [presumably, the cache expires in 5 seconds or so].
Has anyone else seen this? (If so, have you found a workaround other than adding a delay / snooze?) Does anyone know of an API similar to the one described above that can check for a file without using the SMB cache? Or, better yet, does anyone know of a Windows API that simply flushes metadata in the SMB cache?
source
share