Below operation happens very frequently in our application ,whenever power failure happens dest.xml will be corrupted and i see only NULNULNULNULNUL when opened with Notepad++ . I have tried disabling cache and using combination of remove() and rename() for renaming src.xml.ignore to dest.xml . Still the same issue .Is there any way to resolve this problem during power failure
MemoryOutputStream file;
file << dir << '\\' << relPath << idToUse << ".xml.ignore";
CSString temp = file.AsString(); /* CSString is our internalstring class it can be converted into const char* */
FileUtils::MakeDirsInFilePath( temp );
static const int NUM_RETRIES = 50;
static const int WAIT_AMT = 100;
int i;
for ( i = 0; i < NUM_RETRIES; ++i )
{
FILE * fp = ::_fsopen( temp, "wb", _SH_DENYRW );
if ( fp != 0 )
{
FileOutputStream fos( fp, true );
fos << xml;
if ( fos.Close() )
{
break;
}
FileUtils::Delete( temp );
}
Thread::SleepFor( WAIT_AMT );
}
if ( i == NUM_RETRIES )
{
return false;
}
// move into place
//
file.Reset();
file << dir << '\\' << idToUse << ".xml";
CSString dest = file.AsString();
DWORD flags = MOVEFILE_COPY_ALLOWED|MOVEFILE_WRITE_THROUGH;
if (overwrite) flags |= MOVEFILE_REPLACE_EXISTING;
BOOL rc = ::MoveFileEx( src, dest, flags ); ///Dest file is getting corrupted