I’m using native/C++/Win32/MFC code on Windows to save a document file via MFC serialization. I’ve inserted my own CFile-derived class in the writing process giving me access to the data as its being written. This allows me to compute a checksum (or hash, etc) on the data as its going out to the file.
After the files has saved, I’d like to allow the option of verifying the file. The idea would be to re-open the file and read through it verifying the checksum/hash/etc.
I’m wondering, though, if its possible that after having just written the file, the OS could be giving me unwritten data when I read the file back right away. In this case, the test doesn’t really tell me that the file looks good on the disk.
Is my concern valid? If so, is there any way to avoid this issue?
If you are using CFile, you can call CFile::Flush to ensure everything is written to disk. According to the documenatation