void OFile::backupAllFiles( const std::string& str ) { if(str=="/dev/null") return; plumed_assert( backstring!="bck" && !checkRestart()); size_t found=str.find_last_of("/\\"); std::string filename = appendSuffix(str,getSuffix()); std::string directory=filename.substr(0,found+1); std::string file=filename.substr(found+1); if( FileExist(filename) ) backupFile("bck", filename); for(int i=0;; i++) { std::string num; Tools::convert(i,num); std::string filestr = directory + backstring + "." + num + "." + file; if( !FileExist(filestr) ) break; backupFile( "bck", filestr); } }
void UpdateInstaller::installFile(const UpdateScriptFile& file) { std::string sourceFile = file.source; std::string destPath = file.dest; std::string absDestPath = FileUtils::makeAbsolute(destPath.c_str(), m_installDir.c_str()); LOG(Info,"Installing file " + sourceFile + " to " + absDestPath); // backup the existing file if any backupFile(absDestPath); // create the target directory if it does not exist std::string destDir = FileUtils::dirname(absDestPath.c_str()); if (!FileUtils::fileExists(destDir.c_str())) { LOG(Info,"Destination path missing. Creating " + destDir); if(!m_dryRun) { FileUtils::mkpath(destDir.c_str()); } } if (!FileUtils::fileExists(sourceFile.c_str())) { throw "Source file does not exist: " + sourceFile; } if(!m_dryRun) { FileUtils::copyFile(sourceFile.c_str(),absDestPath.c_str()); // set the permissions on the newly extracted file FileUtils::chmod(absDestPath.c_str(),file.permissions); } }
OFile& OFile::open(const std::string&path) { plumed_assert(!cloned); eof=false; err=false; fp=NULL; gzfp=NULL; this->path=path; this->path=appendSuffix(path,getSuffix()); if(checkRestart()) { fp=std::fopen(const_cast<char*>(this->path.c_str()),"a"); mode="a"; if(Tools::extension(this->path)=="gz") { #ifdef __PLUMED_HAS_ZLIB gzfp=(void*)gzopen(const_cast<char*>(this->path.c_str()),"a9"); #else plumed_merror("file " + getPath() + ": trying to use a gz file without zlib being linked"); #endif } } else { backupFile( backstring, this->path ); if(comm)comm->Barrier(); fp=std::fopen(const_cast<char*>(this->path.c_str()),"w"); mode="w"; if(Tools::extension(this->path)=="gz") { #ifdef __PLUMED_HAS_ZLIB gzfp=(void*)gzopen(const_cast<char*>(this->path.c_str()),"w9"); #else plumed_merror("file " + getPath() + ": trying to use a gz file without zlib being linked"); #endif } } if(plumed) plumed->insertFile(*this); return *this; }
bool RbUtilQt::installAuto() { QString file = RbSettings::value(RbSettings::ReleaseUrl).toString(); file.replace("%MODEL%", RbSettings::value(RbSettings::CurBuildserverModel).toString()); file.replace("%RELVERSION%", versmap.value("rel_rev")); buildInfo.open(); QSettings info(buildInfo.fileName(), QSettings::IniFormat, this); buildInfo.close(); // check installed Version and Target QString warning = check(false); if(!warning.isEmpty()) { if(QMessageBox::warning(this, tr("Really continue?"), warning, QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort) == QMessageBox::Abort) { logger->addItem(tr("Aborted!"), LOGERROR); logger->setFinished(); return false; } } // check version RockboxInfo rbinfo(RbSettings::value(RbSettings::Mountpoint).toString()); if(rbinfo.version() != "") { if(QMessageBox::question(this, tr("Installed Rockbox detected"), tr("Rockbox installation detected. Do you want to backup first?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { logger->addItem(tr("Starting backup..."),LOGINFO); QString backupName = RbSettings::value(RbSettings::Mountpoint).toString() + "/.backup/rockbox-backup-" + rbinfo.version() + ".zip"; //! create dir, if it doesnt exist QFileInfo backupFile(backupName); if(!QDir(backupFile.path()).exists()) { QDir a; a.mkpath(backupFile.path()); } //! create backup RbZip backup; connect(&backup,SIGNAL(zipProgress(int,int)),logger, SLOT(setProgress(int,int))); if(backup.createZip(backupName, RbSettings::value(RbSettings::Mountpoint).toString() + "/.rockbox") == Zip::Ok) { logger->addItem(tr("Backup successful"),LOGOK); } else { logger->addItem(tr("Backup failed!"),LOGERROR); logger->setFinished(); return false; } } }
int tt_schedule_lookup_write(char *filename) { backupFile(filename); FILE *f = fopen(filename, "w"); if (!f) return EXIT_FAILURE; hashmapWrite(timetable->schedId, writeUID, f); fclose(f); return EXIT_SUCCESS; }
void UpdateInstaller::installFile(const UpdateScriptFile& file) { std::string destPath = m_installDir + '/' + file.path; std::string target = file.linkTarget; // backup the existing file if any backupFile(destPath); // create the target directory if it does not exist std::string destDir = FileUtils::dirname(destPath.c_str()); if (!FileUtils::fileExists(destDir.c_str())) { FileUtils::mkpath(destDir.c_str()); } if (target.empty()) { // locate the package containing the file if (!file.package.empty()) { std::string packageFile = m_packageDir + '/' + file.package + ".zip"; if (!FileUtils::fileExists(packageFile.c_str())) { throw "Package file does not exist: " + packageFile; } // extract the file from the package and copy it to // the destination FileUtils::extractFromZip(packageFile.c_str(),file.path.c_str(),destPath.c_str()); } else { // if no package is specified, look for an uncompressed file in the // root of the package directory std::string sourceFile = m_packageDir + '/' + FileUtils::fileName(file.path.c_str()); if (!FileUtils::fileExists(sourceFile.c_str())) { throw "Source file does not exist: " + sourceFile; } FileUtils::copyFile(sourceFile.c_str(),destPath.c_str()); } // set the permissions on the newly extracted file FileUtils::chmod(destPath.c_str(),file.permissions); } else { // create the symlink FileUtils::createSymLink(destPath.c_str(),target.c_str()); } }
void ExportNotesJob::backupConfig() { setProgressDialogLabel(i18n("Backing up config...")); const QString knotesStr(QStringLiteral("knotesrc")); const QString knotesrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + knotesStr; backupFile(knotesrc, Utils::configsPath(), knotesStr); const QString globalNoteSettingsStr(QStringLiteral("globalnotesettings")); const QString globalNoteSettingsrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + globalNoteSettingsStr; if (QFile(globalNoteSettingsrc).exists()) { KSharedConfigPtr globalnotesettingsrc = KSharedConfig::openConfig(globalNoteSettingsrc); QTemporaryFile tmp; tmp.open(); KConfig *knoteConfig = globalnotesettingsrc->copyTo(tmp.fileName()); const QString selectFolderNoteStr(QStringLiteral("SelectNoteFolder")); if (knoteConfig->hasGroup(selectFolderNoteStr)) { KConfigGroup selectFolderNoteGroup = knoteConfig->group(selectFolderNoteStr); const QString selectFolderNoteGroupStr(QStringLiteral("DefaultFolder")); Utils::convertCollectionIdsToRealPath(selectFolderNoteGroup, selectFolderNoteGroupStr); } knoteConfig->sync(); backupFile(tmp.fileName(), Utils::configsPath(), globalNoteSettingsStr); delete knoteConfig; } backupUiRcFile(QStringLiteral("knotesappui.rc"), QStringLiteral("knotes")); backupUiRcFile(QStringLiteral("knotesui.rc"), QStringLiteral("knotes")); backupUiRcFile(QStringLiteral("knotes_part.rc"), QStringLiteral("knotes")); backupConfigFile(QStringLiteral("akonadi_notes_agent.notifyrc")); storeDirectory(QStringLiteral("/knotes/print/theme/")); Q_EMIT info(i18n("Config backup done.")); }
void BackupDialog::backup(void) { if(QFileInfo(m_backupName).isFile()) { if(QMessageBox::warning(this, tr("File exists"), tr("The selected backup file already exists. Overwrite?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) { return; } } m_logger = new ProgressLoggerGui(this); connect(m_logger, SIGNAL(closed()), this, SLOT(close())); m_logger->show(); m_logger->addItem(tr("Starting backup ..."),LOGINFO); QCoreApplication::processEvents(); // create dir, if it doesnt exist QFileInfo backupFile(m_backupName); if(!QDir(backupFile.path()).exists()) { QDir a; a.mkpath(backupFile.path()); } // create backup ZipUtil zip(this); connect(&zip, SIGNAL(logProgress(int, int)), m_logger, SLOT(setProgress(int, int))); connect(&zip, SIGNAL(logItem(QString, int)), m_logger, SLOT(addItem(QString, int))); zip.open(m_backupName, QuaZip::mdCreate); QString mp = m_mountpoint + "/.rockbox"; if(zip.appendDirToArchive(mp, m_mountpoint)) { m_logger->addItem(tr("Backup successful."), LOGINFO); } else { m_logger->addItem(tr("Backup failed!"), LOGERROR); } zip.close(); m_logger->setFinished(); }
void LoggingWindow::on_loadBackupButton_clicked() { QString path = QDir::currentPath(); if (backupFolder != "") { path = backupFolder; } QString fileToOpen = QFileDialog::getOpenFileName(this, "Open Backup", path, tr("Backup File (*.backup)")); if (fileToOpen != "") { QFile backupFile(fileToOpen); QTextStream fileInput(&backupFile); if (backupFile.open(QIODevice::ReadOnly | QIODevice::Text)) { while (!fileInput.atEnd()) { qDebug() << "Loading line of Backup File"; QString line = fileInput.readLine(); data[dataPointer] = new DataPoint(this); data[dataPointer]->addBackupData(line); emit updateGraphs(data[dataPointer]); this->addToTable(data[dataPointer]->className(), data[dataPointer]->airQuality(), data[dataPointer]->deltaAirQuality(), data[dataPointer]->year(), data[dataPointer]->boys(), data[dataPointer]->girls(), data[dataPointer]->timeOfLog()); lastValue = data[dataPointer]->airQuality(); dataPointer++; } } } }
bool RbUtilQt::installAuto() { QString file = SystemInfo::value(SystemInfo::ReleaseUrl).toString(); file.replace("%MODEL%", SystemInfo::value(SystemInfo::CurBuildserverModel).toString()); file.replace("%RELVERSION%", ServerInfo::value(ServerInfo::CurReleaseVersion).toString()); // check installed Version and Target QString warning = Utils::checkEnvironment(false); if(!warning.isEmpty()) { if(QMessageBox::warning(this, tr("Really continue?"), warning, QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort) == QMessageBox::Abort) { logger->addItem(tr("Aborted!"), LOGERROR); logger->setFinished(); return false; } } // check version RockboxInfo rbinfo(RbSettings::value(RbSettings::Mountpoint).toString()); if(rbinfo.version() != "") { if(QMessageBox::question(this, tr("Installed Rockbox detected"), tr("Rockbox installation detected. Do you want to backup first?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { bool result; logger->addItem(tr("Starting backup..."),LOGINFO); QString backupName = RbSettings::value(RbSettings::Mountpoint).toString() + "/.backup/rockbox-backup-" + rbinfo.version() + ".zip"; //! create dir, if it doesnt exist QFileInfo backupFile(backupName); if(!QDir(backupFile.path()).exists()) { QDir a; a.mkpath(backupFile.path()); } logger->addItem(tr("Beginning Backup..."),LOGINFO); QCoreApplication::processEvents(); //! create backup ZipUtil zip(this); connect(&zip, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int))); connect(&zip, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int))); zip.open(backupName, QuaZip::mdCreate); QString mp = RbSettings::value(RbSettings::Mountpoint).toString(); QString folder = mp + "/.rockbox"; result = zip.appendDirToArchive(folder, mp); zip.close(); if(result) { logger->addItem(tr("Backup successful"),LOGOK); } else { logger->addItem(tr("Backup failed!"),LOGERROR); logger->setFinished(); return false; } } }
bool PackageUtils::writeBackupConfigFile() { QString backupFileDirPath = m_packageRootPath + BACKUP_CONFIG_FILE_DIR; QDir backupFileDir(backupFileDirPath); if (!backupFileDir.exists()) backupFileDir.mkpath(backupFileDirPath); QString backupFilePath = QString("%1/widget_%2.conf").arg(backupFileDirPath, m_appId); QFile backupFile(backupFilePath); if (!backupFile.open(QIODevice::WriteOnly)) return false; QString widgetService = QString("com.nokia.webwidgetrunner%1wrtwidgetdesktop").arg(m_appId); QXmlStreamWriter backupXmlStream(&backupFile); backupXmlStream.setAutoFormatting(true); backupXmlStream.writeStartElement("backup-configuration"); backupXmlStream.writeTextElement("application-type", "nokia"); backupXmlStream.writeTextElement("application-name", m_appName); QString backupScriptsDirPath = BACKUP_SCRIPTS_DIR + "/" + m_appId; backupXmlStream.writeTextElement("backup-method", "permanent-backup-files,backup-scripts"); backupXmlStream.writeStartElement("backup-scripts"); backupXmlStream.writeTextElement("backup-script-name", QString("%1/%2-backup").arg(backupScriptsDirPath).arg(m_appId)); backupXmlStream.writeTextElement("restore-script-name", QString("%1/%2-restore").arg(backupScriptsDirPath).arg(m_appId)); backupXmlStream.writeEndElement(); // backup-scripts backupXmlStream.writeStartElement("backup-dbus"); backupXmlStream.writeTextElement("prestart", "no"); backupXmlStream.writeStartElement("dbus-service"); backupXmlStream.writeAttribute("object", "/wrt/webwidgetrunner/backup"); backupXmlStream.writeCharacters(widgetService); backupXmlStream.writeEndElement(); // dbus-service backupXmlStream.writeEndElement(); // backup-dbus backupXmlStream.writeStartElement("locations"); backupXmlStream.writeStartElement("location"); backupXmlStream.writeAttribute("type", "permanent-backup-file"); backupXmlStream.writeAttribute("category", "settings"); //should be the same as in wrt.conf // Removing user-specific home path from resourcePath and prepending // $HOME env variable, so it can be flexible enough for backup app. QString resourcePath = QDir::cleanPath(m_properties->resourcePath()); QString homePath = QDir::homePath(); if (resourcePath.startsWith(homePath)) { resourcePath.remove(homePath); resourcePath.prepend(QString("$HOME")); } backupXmlStream.writeCharacters(resourcePath); // widget data path backupXmlStream.writeEndElement(); backupXmlStream.writeStartElement("location"); backupXmlStream.writeAttribute("type", "file"); backupXmlStream.writeAttribute("category", "settings"); QString privateEncryptedStoragePath = QString("/var/tmp/%1_Pe.tar.gz").arg(m_appId); backupXmlStream.writeCharacters(privateEncryptedStoragePath); backupXmlStream.writeEndElement(); backupXmlStream.writeEndElement(); // locations backupXmlStream.writeEndElement(); // backup-configuration backupXmlStream.writeEndDocument(); backupFile.flush(); return true; }