Пример #1
0
/**
 * Atomically save \a doc to specified name. Prior to saving, back up
 * of old config data is created, and only then data is saved.
 */
bool AtomicXmlFile::saveDocument(const QDomDocument& doc) const
{
	if (!saveDocument(doc, tempFileName())) {
		qWarning("AtomicXmlFile::saveDocument(): Unable to save '%s'. Possibly drive is full.",
		         qPrintable(tempFileName()));
		return false;
	}

	if (QFile::exists(backupFileName()))
		QFile::remove(backupFileName());

	if (QFile::exists(fileName_)) {
		if (!QFile::rename(fileName_, backupFileName())) {
			qWarning("AtomicXmlFile::saveDocument(): Unable to rename '%s' to '%s'.",
			         qPrintable(fileName_), qPrintable(backupFileName()));
			return false;
		}
	}

	if (!QFile::rename(tempFileName(), fileName_)) {
		qWarning("AtomicXmlFile::saveDocument(): Unable to rename '%s' to '%s'.",
		         qPrintable(tempFileName()), qPrintable(fileName_));
		return false;
	}

	return true;
}
Пример #2
0
/**
 * Tries to load \a doc from config file, or if that fails, from a back up.
 */
bool AtomicXmlFile::loadDocument(QDomDocument* doc) const
{
	Q_ASSERT(doc);

	QStringList fileNames;
	fileNames << tempFileName()
	          << fileName_
	          << backupFileName();

	foreach(QString fileName, fileNames)
		if (loadDocument(doc, fileName))
			return true;

	return false;
}
Пример #3
0
bool LIB_EDIT_FRAME::backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt )
{
    if( aOriginalFile.FileExists() )
    {
        wxFileName backupFileName( aOriginalFile );
        backupFileName.SetExt( "bck" );

        if( backupFileName.FileExists() )
            wxRemoveFile( backupFileName.GetFullPath() );

        if( !wxCopyFile( aOriginalFile.GetFullPath(), backupFileName.GetFullPath() ) )
        {
            DisplayError( this, wxString::Format( _( "Failed to save backup to \"%s\"" ),
                                                  backupFileName.GetFullPath() ) );
            return false;
        }
    }

    return true;
}
//------------------------------------------------------------------------------
// Replace the currently specified db file with it's corresponding backup file.
// The backup file is a complete backup, not just a backup of a single chunk.
//------------------------------------------------------------------------------
void BulkRollbackFileCompressedHdfs::restoreFromBackup(const char* colType,
    OID       columnOID,
    u_int32_t dbRoot,
    u_int32_t partNum,
    u_int32_t segNum)
{
    // Construct file name for db file to be restored
    char dbFileName[FILE_NAME_SIZE];
    int rc = fDbFile.getFileName( columnOID, dbFileName,
        dbRoot, partNum, segNum );
    if (rc != NO_ERROR)
    {
        std::ostringstream oss;
        oss << "Error restoring " << colType <<
            " HDFS file for OID " << columnOID <<
            "; Can't construct file name for DBRoot"  << dbRoot <<
            "; partition-"   << partNum <<
            "; segment-"     << segNum;
        throw WeException( oss.str(), rc );
    }

    // Construct file name for backup copy of db file
    std::ostringstream ossFile;
    ossFile << "/" << columnOID << ".p" << partNum << ".s" << segNum;
    std::string backupFileName( fMgr->getMetaFileName() );
    backupFileName += DATA_DIR_SUFFIX;
    backupFileName += ossFile.str();

    std::string dbFileNameTmp = dbFileName;
    dbFileNameTmp += OLD_FILE_SUFFIX;

    // Log msg but don't abort if backup file does not exist
    if ( !IDBPolicy::exists(backupFileName.c_str()) )
    {
        std::ostringstream msgText;
        msgText << "No restore needed for " << colType << " HDFS file" <<
        ": dbRoot-" << dbRoot  <<
        "; part#-"  << partNum <<
        "; seg#-"   << segNum  <<
        " (no backup exists)";
        fMgr->logAMessage( logging::LOG_TYPE_INFO,
            logging::M0075, columnOID, msgText.str() );
        return;
    }
    
    // Rename current db file to make room for restored file
    rc = IDBPolicy::rename( dbFileName, dbFileNameTmp.c_str() );
    if (rc != 0)
    {
        std::ostringstream oss;
        oss << "Error restoring " << colType <<
            " HDFS file for OID " << columnOID <<
            "; Can't move old file for DBRoot"  << dbRoot <<
            "; partition-"   << partNum <<
            "; segment-"     << segNum;
        throw WeException( oss.str(), ERR_COMP_RENAME_FILE );
    }

    // Rename backup file to replace current db file
    rc = IDBPolicy::rename( backupFileName.c_str(), dbFileName );
    if (rc != 0)
    {
        std::ostringstream oss;
        oss << "Error restoring " << colType <<
            " HDFS file for OID " << columnOID <<
            "; Can't rename backup file for DBRoot"  << dbRoot <<
            "; partition-"   << partNum <<
            "; segment-"     << segNum;
        throw WeException( oss.str(), ERR_METADATABKUP_COMP_RENAME );
    }

    // Delete db file we just replaced with backup
    IDBPolicy::remove( dbFileNameTmp.c_str() );
}