void Agros2D::clear() { delete m_singleton.data()->m_scene; delete m_singleton.data()->m_problem; delete m_singleton.data()->m_configComputer; delete m_singleton.data()->m_solutionStore; delete m_singleton.data()->m_log; delete m_singleton.data()->m_memoryMonitor; // remove temp and cache plugins removeDirectory(cacheProblemDir()); removeDirectory(tempProblemDir()); }
static bool removeDirectory(QString dirName) { QDir dir(dirName); QString tmpdir =""; if(!dir.exists()){ return false; } QFileInfoList fileInfoList = dir.entryInfoList(); foreach(QFileInfo fileInfo, fileInfoList) { if(fileInfo.fileName()=="."|| fileInfo.fileName()=="..") continue; if(fileInfo.isDir()){ tmpdir = dirName +("/")+ fileInfo.fileName(); removeDirectory(tmpdir); dir.rmdir(fileInfo.fileName());/**< 移除子目录 */ } else if(fileInfo.isFile()){ QFile tmpFile(fileInfo.fileName()); dir.remove(tmpFile.fileName());/**< 删除临时文件 */ } else{ ; } } dir.cdUp(); /**< 返回上级目录,因为只有返回上级目录,才可以删除这个目录 */ if(dir.exists(dirName)){ if(!dir.rmdir(dirName)) return false; } return true; }
void cleanDirectory( const std::string &dir ) { // Remove directory if exist .. removeDirectory( dir ); // create directory createDirectory( dir ); }
void test() { std::vector<TestWrapper_t> fn; //fn.push_back([] { TestWrapper("Read Write", TestReadWrite); }); //fn.push_back([] { TestWrapper("File Header", TestHeader); }); //fn.push_back([] { TestWrapper("Concurrent Write", TestConcurrentWrite); }); //fn.push_back([] { TestWrapper("Concurrent Read Write", TestConcurrentReadWrite); }); //fn.push_back([] { TestWrapper("Concurrent Multi-File", TestConcurrentMultiFile); }); fn.push_back([] { TestWrapper("MVCC", TestMVCC); }); fn.push_back([] { TestWrapper("Concurrent Multi-File MVCC", TestConcurrentMultiFileMVCC); }); //fn.push_back([] { TestWrapper("Unlink", TestUnlink); }); SECURITY_ATTRIBUTES attr; attr.nLength = sizeof(SECURITY_ATTRIBUTES); attr.bInheritHandle = true; attr.lpSecurityDescriptor = NULL; if (!CreateDirectory("data", &attr)) { logEvent(ERROR,"data: " + ConvertLastErrorToString()); _mkdir("data"); } std::cout << "Test Results:" << std::endl; std::cout << std::setfill('-'); for (auto &func : fn) { func(); } std::cout << std::setfill(' '); #if defined(_WIN32) || defined(_WIN64) //std::cout << "\nPress enter to continue..." << std::endl; //std::getchar(); #endif removeDirectory("data"); }
MHWD::STATUS Mhwd::uninstallConfig(Config *config) { std::shared_ptr<Config> installedConfig{getInstalledConfig(config->name_, config->type_)}; // Check if installed if (nullptr == installedConfig) { return MHWD::STATUS::ERROR_NOT_INSTALLED; } else if (installedConfig->basePath_ != config->basePath_) { return MHWD::STATUS::ERROR_NO_MATCH_LOCAL_CONFIG; } else { // TODO: Should we check for local requirements here? // Run script if (!runScript(installedConfig, MHWD::TRANSACTIONTYPE::REMOVE)) { return MHWD::STATUS::ERROR_SCRIPT_FAILED; } if (!removeDirectory(installedConfig->basePath_)) { return MHWD::STATUS::ERROR_SET_DATABASE; } // Installed config vectors have to be updated manual with updateInstalledConfigData(Data*) return MHWD::STATUS::SUCCESS; } }
bool removeDirectory(const QString &str) { bool error = false; if (QDir(str).exists()) { QFileInfoList entries = QDir(str).entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files); int count = entries.size(); for (int idx = 0; idx < count; idx++) { QFileInfo entryInfo = entries[idx]; QString path = entryInfo.absoluteFilePath(); if (entryInfo.isDir()) { error = removeDirectory(path); } else { QFile file(path); if (!file.remove()) { error = true; break; } } } if (!QDir().rmdir(str)) error = true; } return error; }
int removeDirectory(char* name) { t2fs_file handle = t2fs_open(name); struct t2fs_record record[4]; t2fs_read(handle, (char*) record, 4*sizeof(struct t2fs_record)); int i; int erro; while ((record[i].TypeVal == 1 || record[i].TypeVal == 2) && i < 4) { if (record[i].TypeVal == 2) { erro = removeDirectory(record[i].name); } else { erro = t2fs_delete(record[i].name); } i++; } t2fs_close(handle); return erro; }
int main(int argc, char **argv) { if (argc != 2) { printf("usage: %s </path/of/the/folder>\n", argv[0]); return 1; } else { char *name = argv[1]; t2fs_file handle = t2fs_open(name); if (handle < 0) { printf("Incorrect folder name\n"); return 1; } t2fs_close(handle); int erro = removeDirectory(name); if (erro != 0) { printf("Deletion failed\n"); return 1; } return 0; } }
QGenieConfigFileMover::QGenieConfigFileMover() { #ifdef Q_OS_WIN32 QString old_dir_name =(QDir::home().absolutePath()+QString("/NETGEARGenie/")); #else QString old_dir_name =(QDir::home().absolutePath()+QString("/.NETGEARGenie/")); #endif //QString new_dir_name =(QStandardPaths::writableLocation(QStandardPaths::DataLocation)+"/NETGEARGenie/"); QString new_dir_name =QStandardPaths::writableLocation(QStandardPaths::DataLocation); bool old_exist=QDir::home().exists(old_dir_name); bool new_exist=QDir::home().exists(new_dir_name); if(!new_exist) { QDir::home().mkdir(new_dir_name); if(old_exist) { const char *cParas[]={"config.ini","function_statistics.dat" ,"routetype_statistics.dat","mapcustomdata.dat"}; QDir d(old_dir_name); for(int i=0;i<sizeof(cParas)/sizeof(cParas[0]);i++) { if(d.exists(cParas[i])) { QFile::copy(old_dir_name+"/"+cParas[i],new_dir_name+"/"+cParas[i]); } } } } if(old_exist) { removeDirectory(old_dir_name); } }
bool removeDirectory(const path& dirName) { bool result = true; QDir dir(toQString(dirName)); if (dir.exists()) { for (const QFileInfo& info : dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) { if (info.isDir()) { result = removeDirectory(toPath(info.absoluteFilePath())); } else { result = QFile::remove(info.absoluteFilePath()); } if (!result) { return result; } } result = QDir().rmdir(toQString(dirName)); } return result; }
static int _testRemoveDirectory(void) { CharString tempDir = _fileUtilitiesMakeTempDir(); assert(_fileExists(tempDir->data)); assert(removeDirectory(tempDir)); assertFalse(_fileExists(tempDir->data)); freeCharString(tempDir); return 0; }
bool safeRemoveDirectory( const std::string &dir ) { try { removeDirectory( dir ); return true; } catch (...) { printf( "[util::fs] Cannot remove directory: %s\n", dir.c_str() ); return false; } }
bool IHttpDirectory::removeDirectory(shared_ptr<IHttpDirectory> directory) { if(directory == nullptr) { OS_ASSERTFALSE(); return false; } return removeDirectory(directory->getName()); }
static int _testListEmptyDirectory(void) { CharString tempDir = _fileUtilitiesMakeTempDir(); LinkedList l = listDirectory(tempDir); assertIntEquals(linkedListLength(l), 0); removeDirectory(tempDir); freeCharString(tempDir); freeLinkedListAndItems(l, (LinkedListFreeItemFunc)freeCharString); return 0; }
void ManageLibraryDialog::slotRemoveDirectory() { QModelIndex i = ui->userDirectoriesListView->currentIndex(); QString dirToRemove = libraryModel->record(i.row()).value("path").toString(); if (QMessageBox::question(this, tr("Remove Directory"), QString("Remove %1 from database?").arg(dirToRemove), QMessageBox::Yes, QMessageBox::Cancel) == QMessageBox::Yes) { emit removeDirectory(dirToRemove); } }
LRESULT LocationsPage::onClickedRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { int i = -1; while((i = ctrlDirectories.GetNextItem(-1, LVNI_SELECTED)) != -1) { auto itemIter = getByPosition(i); if(removeDirectory(itemIter->first)) { ctrlDirectories.DeleteItem(i); i--; } } return 0; }
bool Mhwd::removeDirectory(const std::string& directory) { DIR *d = opendir(directory.c_str()); if (!d) { return false; } else { bool success = true; struct dirent *dir; while ((dir = readdir(d)) != nullptr) { std::string filename {dir->d_name}; if (("." == filename) || (".." == filename) || ("" == filename)) { continue; } else { std::string filepath {directory + "/" + filename}; struct stat filestatus; lstat(filepath.c_str(), &filestatus); if (S_ISREG(filestatus.st_mode)) { if (0 != unlink(filepath.c_str())) { success = false; } } else if (S_ISDIR(filestatus.st_mode)) { if (!removeDirectory(filepath)) { success = false; } } } } closedir(d); if (0 != rmdir(directory.c_str())) { success = false; } return success; } }
static int _testCopyInvalidFileToDirectory(void) { CharString tempDir = _fileUtilitiesMakeTempDir(); CharString testFilename = newCharStringWithCString(TEST_FILENAME); CharString invalid = newCharStringWithCString("invalid"); convertRelativePathToAbsolute(testFilename, invalid); assertFalse(copyFileToDirectory(invalid, tempDir)); removeDirectory(tempDir); freeCharString(testFilename); freeCharString(tempDir); freeCharString(invalid); return 0; }
// PreProcessor // PreProcessor::PreProcessor( std::string path ) { tempFolder = path; defines = new StringMap(); ifstate = false; ifgotone = false; ifcopen = false; names = "a"; removeDirectory( tempFolder ); mkdir( tempFolder.c_str(), 0777 ); tempFolder += "/"; };
void QSfwTestUtil::removeDirectory(const QString &path) { QDir dir(path); QFileInfoList fileList = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files); foreach(QFileInfo file, fileList) { if(file.isFile()) { QFile::remove (file.canonicalFilePath()); } if(file.isDir()) { QFile::Permissions perms = QFile::permissions(file.canonicalFilePath()); perms = perms | QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner; QFile::setPermissions(file.canonicalFilePath(), perms); removeDirectory(file.canonicalFilePath()); } } dir.rmpath(path); }
void errorReporterClose(ErrorReporter self) { #if HAVE_LIBARCHIVE struct archive* outArchive; CharString outputFilename = newCharString(); LinkedList reportContents = newLinkedList(); #endif // Always do this, just in case flushErrorLog(); #if HAVE_LIBARCHIVE // In case any part of the error report causes a segfault, this function will // be called recursively. A mutex would really be a better solution here, but // this will also work just fine. if(!self->completed) { self->completed = true; buildAbsolutePath(self->desktopPath, self->reportName, "tar.gz", outputFilename); listDirectory(self->reportDirPath->data, reportContents); if(self != NULL) { outArchive = archive_write_new(); archive_write_set_compression_gzip(outArchive); archive_write_set_format_pax_restricted(outArchive); archive_write_open_filename(outArchive, outputFilename->data); linkedListForeach(reportContents, _remapFileToErrorReportRelativePath, self); chdir(self->desktopPath->data); linkedListForeach(reportContents, _addFileToArchive, outArchive); archive_write_close(outArchive); archive_write_free(outArchive); } // Remove original error report removeDirectory(self->reportDirPath); } #endif printf("\n=== Error report complete ===\n"); printf("Created error report at %s\n", self->reportDirPath->data); #if HAVE_LIBARCHIVE printf("Please email the report to: %s\n", SUPPORT_EMAIL); #else printf("Please compress and email the report to: %s\n", SUPPORT_EMAIL); #endif printf("Thanks!\n"); }
int main(int numberOfArguments, char **arguments) { if (numberOfArguments != 2) { printf("usage: ZPGenProject <project-name>" kNewLine); return; } char *projectName = arguments[1]; printf("\nproject name: %s\n", projectName); // Create the project directory. char *directoryName = stringBuffer1; sprintf(directoryName, "Applications%s%s%s%s.xcodeproj", kDirectorySeparator, projectName, kDirectorySeparator, projectName); printf("making directory %s\n", directoryName); removeDirectory(directoryName); mkdir(directoryName, 0744); // Open the project file. char *projectFilename = stringBuffer2; sprintf(projectFilename, "%s%s%s", directoryName, kDirectorySeparator, "project.pbxproj"); printf("making file %s\n", projectFilename); FILE *file = fopen(projectFilename, "w+"); printf("file is %lu\n", (unsigned long)file); // Write the project file. fprintf(file, "// !$*UTF8*$!" kNewLine); fprintf(file, "{" kNewLine); fprintf(file, kTab "archiveVersion = 1;" kNewLine); fprintf(file, kTab "classes = {" kNewLine); fprintf(file, kTab "};" kNewLine); fprintf(file, kTab "objectVersion = 46;" kNewLine); fprintf(file, kTab "objects = {" kNewLine); writeStaticBlock(file, projectName); fprintf(file, kTab "};" kNewLine); fprintf(file, kTab "rootObject = %s /* Project object */;" kNewLine, kProjectIdentifier); fprintf(file, "}\n"); fclose(file); file = NULL; printf("\n"); }
void clearAgros2DCache() { QFileInfoList listExamples = QFileInfo(cacheProblemDir()).absoluteDir().entryInfoList(); for (int i = 0; i < listExamples.size(); ++i) { QFileInfo fileInfo = listExamples.at(i); if (fileInfo.fileName() == "." || fileInfo.fileName() == ".." || fileInfo.fileName() == QString::number(QCoreApplication::applicationPid())) continue; if (fileInfo.isDir()) { // process doesn't exists if (!SystemUtils::isProcessRunning(fileInfo.fileName().toInt())) removeDirectory(QString("%1/%2").arg(QFileInfo(cacheProblemDir()).absolutePath()).arg(fileInfo.fileName())); } } }
bool DirectoryUtilities::deleteDirectory(const QString &directoryPath, bool deleteRootDirectory) { bool result; result = removeDirectory(QDir(directoryPath), deleteRootDirectory); if (!result) { if (deleteRootDirectory) { ERROR_LOG("Hi ha hagut errors en l'esborrat del directori i del seu contingut de " + directoryPath); } else { ERROR_LOG("Hi ha hagut errors en l'esborrat del contingut del directori " + directoryPath); } } return result; }
static int _testCopyFileToDirectory(void) { CharString tempDir = _fileUtilitiesMakeTempDir(); CharString tempFile = newCharString(); CharString testFilename = newCharStringWithCString(TEST_FILENAME); FILE *fp = fopen(TEST_FILENAME, "w"); assertNotNull(fp); fclose(fp); convertRelativePathToAbsolute(testFilename, tempFile); assert(copyFileToDirectory(tempFile, tempDir)); assert(removeDirectory(tempDir)); unlink(TEST_FILENAME); freeCharString(tempDir); freeCharString(tempFile); freeCharString(testFilename); return 0; }
// Remove directory and files bool THFileUtil::removeDirectory(const char *dirPath) { std::string orgPath = dirPath; // printf("##### removeDirectory: (%s)\n", dirPath); DIR *dir; struct dirent *entry; char path[PATH_MAX]; if(path == NULL) { // printf("##### path == NULL\n"); return false; } dir = opendir(dirPath); if(dir == NULL) { perror("Error opendir()"); return false; } while((entry = readdir(dir)) != NULL) { // printf("##### > %s\n", entry->d_name); if(strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) { snprintf(path, (size_t)PATH_MAX, "%s/%s", dirPath, entry->d_name); // printf("##### == %s\n", path); if(entry->d_type == DT_DIR) { removeDirectory(path); } else { unlink(path); } } } closedir(dir); // printf("##### rmdir(%s)\n", orgPath.c_str()); rmdir(orgPath.c_str()); return true; }
bool DirectoryUtilities::removeDirectory(const QDir &dir, bool deleteRootDirectory) { bool ok = true; // QDir::NoDotAndDotDot if (dir.exists()) { QFileInfoList entries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files); int count = entries.size(); for (int i = 0; i < count && ok; i++) { QFileInfo entryInfo = entries[i]; QString path = entryInfo.absoluteFilePath(); if (entryInfo.isDir()) { ok = removeDirectory(QDir(path), true); } else { QFile file(path); if (!file.remove()) { ok = false; ERROR_LOG("No s'ha pogut esborrar el fitxer " + path); } else { emit directoryDeleted(); QCoreApplication::processEvents(); } } } if (deleteRootDirectory) { if (!dir.rmdir(dir.absolutePath())) { ok = false; ERROR_LOG("No s'ha pogut esborrar el directori " + dir.absolutePath()); } } } return ok; }
void MainWindow::on_treeView_customContextMenuRequested(QPoint pos) { QMenu *menu = new QMenu; QAction *action; action = new QAction(tr("&New"), this); action->setToolTip(tr("Create a new directory")); connect(action, SIGNAL(triggered()), this, SLOT(newDirectory())); menu->addAction(action); action = new QAction(tr("&Remove"), this); action->setToolTip(tr("Remove directory")); if (ui->treeView->selectionModel()->selection().isEmpty()) action->setEnabled(false); connect(action, SIGNAL(triggered()), this, SLOT(removeDirectory())); menu->addAction(action); menu->exec(ui->treeView->mapToGlobal(pos)); }
void CheckOption::deleteandBackupfunction() { pushButton_BackUp = new QPushButton(this); pushButton_BackUp->setText("BackUp"); pushButton_BackUp->setObjectName(QString::fromUtf8("pushButton_BackUp")); pushButton_BackUp->setGeometry(QRect(10, 190, 161, 121)); pushButton_BackUp->setStyleSheet(QString::fromUtf8("background-image: url(:/pictures/rectButton.png);\n" "font-size:26px bold;\n" "\n" "border-radius:20px;")); pushButton_BackUp->show(); Treeview_BackUp = new QTreeView(this); Treeview_BackUp->setObjectName(QString::fromUtf8("frame_BackUp")); Treeview_BackUp->setGeometry(QRect(20, 10, 601, 191)); Treeview_BackUp->setFrameShape(QFrame::StyledPanel); Treeview_BackUp->setFrameShadow(QFrame::Raised); //frame_BackUp->setStyleSheet("color: rgb(0, 0, 0);"); Treeview_BackUp->show(); pushButton_Cancel = new QPushButton(this); pushButton_Cancel->setText("Cancel"); pushButton_Cancel->setObjectName(QString::fromUtf8("pushButton_Cancel")); pushButton_Cancel->setGeometry(QRect(470, 190, 161, 121)); pushButton_Cancel->setStyleSheet(QString::fromUtf8("background-image: url(:/pictures/rectButton.png);\n" "font-size:26px bold;\n" "\n" "border-radius:20px;")); pushButton_Cancel->show(); pushButton_Delete = new QPushButton(this); pushButton_Delete->setText("Delete"); pushButton_Delete->setObjectName(QString::fromUtf8("pushButton_Delete")); pushButton_Delete->setGeometry(QRect(245, 190, 161, 121)); pushButton_Delete->setStyleSheet(QString::fromUtf8("background-image: url(:/pictures/rectButton.png);\n" "font-size:26px bold;\n" "\n" "border-radius:20px;")); pushButton_Delete->show(); connect(pushButton_Cancel,SIGNAL(clicked()),this,SLOT(SwitchToinput())); connect(pushButton_Delete,SIGNAL(clicked()),this,SLOT(removeDirectory())); connect(pushButton_BackUp,SIGNAL(clicked()),this,SLOT(BackUpData())); showDirectories(); }
//After calling this, the data-directory may be a new one void ItemRepositoryRegistry::deleteDataDirectory() { QMutexLocker lock(&m_mutex); //lockForWriting creates a file, that prevents any other KDevelop instance from using the directory as it is. //Instead, the other instance will try to delete the directory as well. lockForWriting(); // Have to release the lock here, else it will delete the new lock and windows needs all file-handles // to be released before deleting a directory that contains these files m_lock->unlock(); bool result = removeDirectory(m_path); Q_ASSERT(result); Q_UNUSED(result); Q_ASSERT(m_lock); //Just remove the old directory, and allocate a new one. Probably it'll be the same one. QPair<QString, KLockFile::Ptr> repo = allocateRepository(); m_path = repo.first; m_lock = repo.second; }