Example #1
0
int
CXMLDb::LoadBackupFile(void)
{
	if(m_BackupFile)
		return true;

	m_BackupFile = new XMLDocument();

	if(m_BackupFile->LoadFile(m_FileName.c_str()) != XML_NO_ERROR)
	{
		if(m_BackupFile->ErrorID() == XML_ERROR_FILE_NOT_FOUND)
			return CreateBackupFile();
		else
		{
			syslog(LOG_ERR, "Error Opening backup.xml: %d\n",
					m_BackupFile->ErrorID());

			delete m_BackupFile;
			m_BackupFile = 0;
			return false;
		}
	}

	return true;
}
Example #2
0
bool SafeCopyFile(const CString &src, const CString &dst, bool bBackup)
{
    HANDLE hFile = INVALID_HANDLE_VALUE;
    DWORD dwSize = 0;
    bool bRet = true;
  
    hFile = ::CreateFile((LPCTSTR)src, 
                         GENERIC_READ, 
                         FILE_SHARE_READ, 
                         NULL,
                         OPEN_EXISTING, 
                         FILE_ATTRIBUTE_NORMAL, 
                         NULL);
    if (hFile == INVALID_HANDLE_VALUE) {
            //            theLog("!!!Fail to open %s while copying to %s (Error %d)\n", src, dst, GetLastError());
        bRet = false;
        return bRet;
    }

    
    dwSize = ::GetFileSize(hFile, NULL);
    CloseHandle(hFile);

    if (bBackup)
        CreateBackupFile(dst);
        
    CString dir = dst;
    ::GetParentDirectory(dir);
    ::CreateDirectoryPath(dir);
        
    if (::CopyFile(src, dst, FALSE) == 0) {
        // There seems to be a weird bug with remote drives.
        // Try to guess a bit more about the failure.
        DWORD dwErrCode = GetLastError();
        if (dwErrCode != ERROR_ACCESS_DENIED) {
            //                theLog("Error: Fail to copy %s to %s (Error %lu)\n", src, dst, dwErrCode);
            bRet = false;
        }
        else {
            hFile = ::CreateFile((LPCTSTR)dst, 
                                 GENERIC_READ|GENERIC_WRITE, 
                                 FILE_SHARE_READ | FILE_SHARE_WRITE, 
                                 NULL,
                                 OPEN_ALWAYS, 
                                 FILE_ATTRIBUTE_NORMAL, 
                                 NULL);
            CloseHandle(hFile);
            if (::CopyFile(src, dst, FALSE) == 0) {
                dwErrCode = GetLastError();
                //                    theLog("!!!Fail to copy %s to %s (Error %lu)\n", src, dst, dwErrCode);
                bRet = false;
            }
            else {
                //                    theLog("Copy %s to %s\n", src, dst);
            }
        }
    }
    else {
        //            theLog("Copy %s to %s\n", src, dst);
    }
    if (bRet && ::SetFileAttributes(dst, FILE_ATTRIBUTE_NORMAL) == 0) {
        //            theLog("!!!Fail to reset file attributes for %s (Error %lu)\n", dst, GetLastError());
        bRet = false;
    }
    //    DoProgress(dwSize);
  
    return bRet;
}