void ModelBackendOneFile::addDir ( const QString& dirPath )
{
    // IMPORTANT: Keep in mind that the dirPath is not guaranteed to exist during the whole function (i.e a SD card may be extracted)
    QString path(QDir::cleanPath(dirPath));// Copy of the reference dirPath

    m_pathsMount.insert(path, false);

    // Load path files MetaInfo
    bool bRet = loadMetaInfo(path);
    if(!bRet)
    {
        qWarning() << Q_FUNC_INFO << "Error loading metaInfo, exiting";
        removeDir(path);// TODO: Do partial remove to make it faster
        return;
    }

    // Load path dir looking for new files
    QStringList booksPaths;
    bRet = booksToLoad(path, booksPaths);
    if(!bRet)
    {
        qDebug() << Q_FUNC_INFO << "Error loading books, Exiting";
        removeDir(path);// TODO: Do partial remove to make it faster
        return;
    }

    qDebug() << Q_FUNC_INFO << "Books to load: " << booksPaths;

    int totalBooks = booksPaths.size();
    if(path != _privatePartition)
    {
        if(totalBooks > BOOKS_LOADED_TO_SHOW_DIALOG) // For 20 books or more it shows progress dialog
            emit loadingBooks(totalBooks);
    }

    bRet = load(booksPaths);
    if(!bRet)
    {
        qDebug() << Q_FUNC_INFO << "Error. Exiting";
        removeDir(path);// TODO: Do partial remove to make it faster
        emit loadFinished();
        return;
    }

    qDebug() << Q_FUNC_INFO << "Before load finished";

    emit loadFinished();

    qDebug() << Q_FUNC_INFO << "After load finished";

    qDebug() << Q_FUNC_INFO << "dir path: " << path << "_privatePartition: " << _privatePartition;
    if(QDir::cleanPath(path) == QDir::cleanPath(_privatePartition))
        loadArchivedBooks();

    messDir(path, UPDATE_FULL);
}
void WorkInfoCacheTester::cleanupTestCase()
{
    QString kdehome = getenv("KDEHOME");
    removeDir( kdehome + "/workinfocachetester/Africa" );
    removeDir( kdehome + "/workinfocachetester/America" );
    removeDir( kdehome + "/workinfocachetester/Europe" );
    removeDir( kdehome + "/workinfocachetester" );
    removeDir( kdehome + "/share/config" );
    QDir().rmpath(kdehome +"/share/workinfocachetester");
}
void CalendarTester::cleanupTestCase()
{
    QString kdehome = getenv("KDEHOME");
    removeDir( kdehome + "/calendartest/Africa" );
    removeDir( kdehome + "/calendartest/America" );
    removeDir( kdehome + "/calendartest/Europe" );
    removeDir( kdehome + "/calendartest" );
    removeDir( kdehome + "/share/config" );
    QDir().rmpath(kdehome +"/share/calendartest");
}
void SchedulerTester::cleanupTimezone()
{
    QString kdehome = getenv("KDEHOME");
    removeDir( kdehome + "/tjtest/Africa" );
    removeDir( kdehome + "/tjtest/America" );
    removeDir( kdehome + "/tjtest/Europe" );
    removeDir( kdehome + "/tjtest" );
    removeDir( kdehome + "/share/config" );
    QDir().rmpath(kdehome +"/share/tjtest");
}
/*!
    \internal

    Recursively removes directories.
  */
bool WsdlConverter::removeDir(const QString &path)
{
    QDir dir(path);
    bool err = false;
    if (dir.exists()) {
        QFileInfoList entries = dir.entryInfoList(QDir::NoDotAndDotDot
                                                  | QDir::Dirs
                                                  | QDir::Files);

        int count = entries.size();
        for (int i = 0; ((i < count) && (err == false)); i++) {
            QFileInfo entryInfo = entries[i];
            QString tpath = entryInfo.absoluteFilePath();

            if (entryInfo.isDir()) {
                err = removeDir(tpath);
            } else {
                QFile file(tpath);
                if (!file.remove())
                    err = true;
            }
        }

        if (!dir.rmdir(dir.absolutePath()))
            err = true;
    }
    return(err);
}
Exemple #6
0
static int dbRemoveColumn(tableInfo *tbl, char *columnName, response *res, error *err) {

	char *tableName = tbl->name;
	
	char currentPath[BUFSIZE];

	columnPath(currentPath, tableName, columnName);

	if (!dirExists(currentPath)) {
		ERROR(err, E_NOCOL);
		goto exit;
	}

	if (removeDir(currentPath, err)) {
		goto exit;
	}

	printf("Removed column %s\n", columnName);
	RESPONSE_SUCCESS(res);

	return 0;

exit:
	return 1;
}
Exemple #7
0
bool VideoMetadataImp::removeDir(const QString &dirName)
{
    QDir d(dirName);

    QFileInfoList contents = d.entryInfoList();
    if (!contents.size())
    {
        return d.rmdir(dirName);
    }

    for (QFileInfoList::iterator p = contents.begin(); p != contents.end(); ++p)
    {
        if (p->fileName() == "." ||
            p->fileName() == "..")
        {
            continue;
        }
        if (p->isDir())
        {
            QString fileName = p->fileName();
            if (!removeDir(fileName))
                return false;
        }
        else
        {
            if (!QFile(p->fileName()).remove())
                return false;
        }
    }
    return d.rmdir(dirName);
}
Exemple #8
0
axStatus	axFileSystem::removeDirT ( const T* src, bool recursive ) {

	axStatus st;
	if( !recursive ) return _removeDir( src );

	axDir::Entry e;
	axString_< T, 1024> path;

	axDir dir;
	st = dir.open( src ); if( !st ) return st;

	while( dir.next( e ) ) { 		

		st = path.format( "{?}/{?}", src, e.name );	if( !st ) return st;

		if( e.isDir() ) {
			st = removeDir( path, recursive );	if( !st ) return st;
		}else {
			st = deleteFile( path ); if( !st ) return st;
		}
	}

	st = _removeDir( src );				if( !st ) return st;

	return 0;
}
Exemple #9
0
void HPSKnotDirModel::removeWithSubs(const QString &str)
{
    QStringList list = str.split('/',QString::SkipEmptyParts);
    if(!list.isEmpty()){
        removeDir(mRoot,list,true);
    }
}
void 
AssemblyFactoryImpl::destroy (Components::Cookie* c)
throw (Components::Deployment::InvalidAssembly, Components::RemoveFailure)
{
	//
	// exclusive
	//
	QedoLock lock(&mutex_);

	AssemblyImpl* ass;
	std::list < AssemblyImpl* > ::iterator iter;
	for(iter = assemblies_.begin();
		iter != assemblies_.end();
		iter++)
	{
		ass = (*iter);
		if( *ass == c)
		{
			root_poa_->deactivate_object( *(root_poa_->servant_to_id(ass)) );

			std::string dir = getPath( packageDirectory_ ) + ass->get_cookie();
			if( removeDir(dir) )
			{
				NORMAL_ERR2( "AssemblyFactoryImpl: could not remove directory ", dir );
			}
			ass->_remove_ref();
			assemblies_.erase( iter );
			return;
		}
	}

	throw Components::Deployment::InvalidAssembly();
}
Exemple #11
0
TextOdt::~TextOdt()
{
    if(m_document != NULL) delete m_document;
    removeDir("tmp");
    for(int i=0; i < m_textCibles.size();i++)
        delete m_textCibles[i];
}
Exemple #12
0
void HPSKnotDirModel::removeDir(DirKnot *parent, QStringList &list,bool withSub)
{
    const QString name = list.takeFirst();
    QList<DirKnot*> children = parent->children;
    DirKnot* child;
    bool last = false;
    int var;
    const int size = children.size();
    for (var = 0; var < size; ++var) {
        child = children.at(var);
        if(child->name == name){
            if(!list.isEmpty()){
                removeDir(child,list,withSub);
            }else {
                qDebug() << Q_FUNC_INFO << child->item->data(Qt::UserRole).toString();
                deactiveKnot(child);
                last=true;
            }
            break;
        }
    }
    if(child->children.size()==0 || (last&&withSub)){
        delete parent->item->takeRow(var).first();
        delete parent->children.takeAt(var);
    }
}
Exemple #13
0
int removeDir(char *directory, int root)
{
    struct dirent *d;
    DIR *dir;
    char buf[400];
    struct stat sbuf;

    if (!(dir = opendir(directory))) return 0;

    while ((d = readdir(dir))) {
	if ((!strcmp(d->d_name, ".") || !(strcmp(d->d_name, "..")))) continue;
	snprintf(buf, sizeof(buf), "%s/%s", directory, d->d_name);
	stat(buf, &sbuf);

	if (S_ISDIR(sbuf.st_mode)) {
	    /* remove all dirs recursive */
	    removeDir(buf, 1);
	} else {
	    remove(buf);
	}
    }

    /* delete also the root directory */
    if (root) {
	remove(directory);
    }

    closedir(dir);
    return 1;
}
Exemple #14
0
/// Deletes the file associated with a metadata entry
bool VideoMetadataImp::DeleteFile()
{
    bool isremoved = false;

    if (!m_host.isEmpty())
    {
        QString url = generate_file_url("Videos", m_host, m_filename);
        isremoved = RemoteFile::DeleteFile(url);
    }
    else
    {
        QFileInfo fi(m_filename);
        if (fi.isDir())
        {
            isremoved = removeDir(m_filename);
        }
        else
        {
            isremoved = QFile::remove(m_filename);
        }
    }

    if (!isremoved)
    {
        LOG(VB_GENERAL, LOG_DEBUG, QString("Could not delete file: %1")
                                       .arg(m_filename));
    }

    return isremoved;
}
Exemple #15
0
bool Util::removeDir(QDir *subDir)
{
    const QFileInfoList *filist = subDir->entryInfoList();
    if (filist != 0) {
        QFileInfoListIterator it(*filist);
        QFileInfo *fi;
        while ((fi = it.current()) != 0) {
            ++it;
            if (fi->fileName() == "." || fi->fileName() == "..") {
                continue;
            }
            else if (fi->isDir()) {
                QDir dir(fi->filePath());
                if (!removeDir(&dir)) {
                    // error, directory is not empty!
                    return false;
                }
            }
            else if (!QFile(fi->filePath()).remove()) {
                return false;
            }
        }
    }

    return subDir->rmdir(subDir->absPath());
}
Exemple #16
0
bool TextOdt::decompress()
{
    m_document = new QDomDocument();

    if(!QFile().exists(EXE_UNZIP))
    {
        emit error(true,QObject::tr("Le programme nécessaire pour lire ce type de ficier est absent.\n\nVeuillez réinstaller l'application pour corriger le problème"));
        return false;
    }

    if(!QDir().exists("tmp"))
        QDir().mkdir("tmp");

    QProcess::execute(QString(L_EXE_UNZIP) +" -o \""+m_file +"\" -d tmp");

    QFile file("tmp/content.xml");

    if(!file.exists("tmp/content.xml"))
    {
        emit error(true,QObject::tr("Le fichier est endommagé ou d'un format inconnu. Impossible de continuer"));
        return false;
    }
    file.open(QFile::ReadOnly);
    m_document->setContent(&file);
    file.close();
    removeDir("tmp");

    return true;
}
Exemple #17
0
void SongbookEditor::removeTmpDir_()
{
    if(! songbookTmpDir_.isEmpty())
    {
        removeDir(QDir(songbookTmpDir_));
        songbookTmpDir_ = QString();
    }
}
Exemple #18
0
bool HPSKnotDirModel::remove(const QString &str)
{
    QStringList list = str.split('/',QString::SkipEmptyParts);
    if(!list.isEmpty()){
        removeDir(mRoot,list,false);
    }
    return true;
}
bool EmptyDirsFix2::removeDir(QString path)
{
	path = QDir::toNativeSeparators(path);
	QDir dir(path);
	QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
	for (int i = 0; i < dirs.size(); i++)
	{ removeDir(path+"/"+dirs.at(i)); }
	return QDir().rmdir(path);
}
Exemple #20
0
void
TestBookCategory::cleanup() {
    BaseTestCase::cleanup();

    auto dbPath = PublicBook::databasePath();
    QFileInfo fi(dbPath);
    if (fi.exists())
        removeDir(fi.absolutePath());
}
void ProfileSelect::deleteProfile()
{
    QString name=ui->listView->currentIndex().data().toString();
    if (QMessageBox::question(this,tr("Question"),tr("Are you sure you want to trash the profile \"%1\"?").arg(name),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes){
        if (QMessageBox::question(this,tr("Question"),tr("Double Checking:\n\nDo you really want \"%1\" profile to be obliterated?").arg(name),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes){
            if (QMessageBox::question(this,tr("Question"),tr("Okay, I am about to totally OBLITERATE the profile \"%1\" and all it's contained data..\n\nDon't say you weren't warned. :-p").arg(name),QMessageBox::Cancel,QMessageBox::Ok)==QMessageBox::Ok){
                bool reallydelete=false;
                Profile *profile=Profiles::profiles[name];
                if (!profile) {
                    QMessageBox::warning(this,tr("WTH???"),tr("If you can read this you need to delete this profile directory manually (It's under %1)").arg(GetAppRoot()+"/Profiles/"+PROFILE.user->userName()),QMessageBox::Ok);
                    return;
                }
                if (profile->user->hasPassword()) {
                    QDialog dialog(this,Qt::Dialog);
                    QLineEdit *e=new QLineEdit(&dialog);
                    e->setEchoMode(QLineEdit::Password);
                    dialog.connect(e,SIGNAL(returnPressed()),&dialog,SLOT(accept()));
                    dialog.setWindowTitle(tr("Enter Password for %1").arg(name));
                    dialog.setMinimumWidth(300);
                    QVBoxLayout *lay=new QVBoxLayout();
                    dialog.setLayout(lay);
                    lay->addWidget(e);
                    int tries=0;
                    do {
                        e->setText("");
                        if (dialog.exec()!=QDialog::Accepted) break;
                        tries++;
                        if (profile->user->checkPassword(e->text())) {
                            reallydelete=true;
                            break;
                        } else {
                            if (tries<3) {
                                QMessageBox::warning(this,STR_MESSAGE_ERROR,tr("Incorrect Password"),QMessageBox::Ok);
                            } else {
                                QMessageBox::warning(this,STR_MESSAGE_ERROR,tr("Meheh... If your trying to delete because you forgot the password, your going the wrong way about it. Read the docs.\n\nSigned: Nasty Programmer"),QMessageBox::Ok);
                            }
                        }
                    } while (tries<3);
                } else reallydelete=true;

                if (reallydelete) {
                    QString path=profile->Get(PrefMacro(STR_GEN_DataFolder));
                    if (!path.isEmpty()) {
                        if (!removeDir(path)) {
                            QMessageBox::information(this,tr("Whoops."),tr("There was an error deleting the profile directory.. You need to manually remove %1").arg(path),QMessageBox::Ok);
                        }
                    }
                    model->removeRow(ui->listView->currentIndex().row());

                    qDebug() << "Delete" << path;
                }
            }
        }
    }
}
Exemple #22
0
void Filesystem::removeDir(const std::string& dir) {
    std::vector<std::string> c;
    if(readDirectory(dir, c)) {
        for(unsigned i = 0; i < c.size(); i++) {
            std::string name(append(dir, c[i]));
            removeDir(name);
            removeFile(name);
        }
        removeEmptyDir(dir.c_str());
    }
}
Exemple #23
0
//============= TESTING APPLICATION USING THESE FS CALLS ==============
// Menu driven testing application for creation of fs, 
// and all file and directory related operations
int main(int argc, char** argv){
	int fd = openDevice(0);
	init_FS(fd);
	makeDir(fd, "Folder 1", 1, 1, 1);
	makeDir(fd, "Folder 2", 1, 1, 1);
	makeDir(fd, "Folder 3", 1, 1, 1);
	removeDir(fd, "Folder 2");
	int dirhandle = openDir(fd, "Folder 1");
	closeDir(dirhandle);
	shutdownDevice(0);
}
Exemple #24
0
void Preferences::deleteProfile()
{
    QString name = ui->startProfile->currentText();
    QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Confirmation"),
                                         tr("Are you sure to permanently delete \"%1\" profile? This action cannot be undone!").arg(name), QMessageBox::Yes | QMessageBox::No);
    if (button != QMessageBox::Yes) {
        return;
    }

    removeDir(mApp->PROFILEDIR + "profiles/" + name);
    ui->startProfile->removeItem(ui->startProfile->currentIndex());
}
void DownloadsManager::removeDir(QString dirName)
{
    dirName.replace(QRegExp("[<|>|:|\"|/|\\|||?|*]"), "");
    changeToDir(dirName);

    foreach (QString entry, downloadDir.entryList(QDir::NoDotAndDotDot|QDir::Dirs|QDir::Files))
        if (!downloadDir.remove(entry))
            removeDir(entry);

    upDir();

    downloadDir.rmdir(dirName);
}
Exemple #26
0
void QgsWFSUtils::releaseCacheDirectory()
{
  QMutexLocker locker( &sMutex );
  sCounter --;
  if ( sCounter == 0 )
  {
    if ( sThread )
    {
      sThread->exit();
      sThread->wait();
      delete sThread;
      sThread = nullptr;
    }

    // Destroys our cache directory, and the main cache directory if it is empty
    QString tmpDirname( getCacheDirectory( false ) );
    if ( QDir( tmpDirname ).exists() )
    {
      QgsDebugMsg( QString( "Removing our cache dir %1" ).arg( tmpDirname ) );
      removeDir( tmpDirname );

      QString baseDirname( getBaseCacheDirectory( false ) );
      QDir baseDir( baseDirname );
      QFileInfoList fileList( baseDir.entryInfoList( QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files ) );
      if ( fileList.size() == 0 )
      {
        QgsDebugMsg( QString( "Removing main cache dir %1" ).arg( baseDirname ) );
        removeDir( baseDirname );
      }
      else
      {
        QgsDebugMsg( QString( "%1 entries remaining in %2" ).arg( fileList.size() ).arg( baseDirname ) );
      }
    }
  }
}
void EmptyDirsFix2::deleteSel()
{
	QStringList folders;
	QList<QListWidgetItem*> sel = ui->listWidget->selectedItems();
	for (int i = 0; i < sel.size(); i++)
	{ folders.append(sel.at(i)->text()); }

	int reponse = QMessageBox::question(this, tr("Réparateur de dossiers vides"), tr("Vous vous apprêtez à supprimer %n dossier(s). Êtes-vous sûr de vouloir continuer ?", "", folders.size()), QMessageBox::Yes | QMessageBox::No);
	if (reponse == QMessageBox::Yes)
	{
		for (int i = 0; i < folders.size(); i++)
		{ removeDir(folders.at(i)); }
		close();
	}
}
Exemple #28
0
RemoveAll::RemoveAll(const char *path)
{
	set_show_all();
	update(path);
	for( int i=0; i<dir_list.total; ++i ) {
		FileItem *fi = get_entry(i);
		const char *fp = fi->get_path();
		if( fi->get_is_dir() )
			removeDir(fp);
		else
			RemoveFile::removeFileWait(fp);
	}
printf("RemoveAll::deleting directory %s\n", path);
	rmdir(path);
}
Exemple #29
0
void filestuff::removeDir(QString dirName)
{
    QDir dir(dirName);
    QStringList dirList(dir.entryList(QDir::Files));
    for (int i = 0; i < dirList.count(); i++){
        QString fName(dirName + "/" + dirList[i]);
        QFile::remove(fName);
    }
    dirList.clear();
    dirList = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
    for (int i = 0; i < dirList.count(); i++){
        QString fName(dirName + "/" + dirList[i]);
        removeDir(fName);
    }
    dir.rmdir(dirName);
}
/*!
    Performs the WSDL => Qt/C++ code conversion.
  */
void WsdlConverter::convert()
{
    if (errorState) {
        enterErrorState(QLatin1String("Converter is in error state and cannot continue."));
        return;
    }

    displayIntro();
    QString mainPath = qApp->applicationDirPath()
            + QLatin1String("/") + webServiceName();
    QDir mainDir;
    if (outputDir != QString()) {
        if (outputDir.at(0) != QChar('/'))
            mainPath = qApp->applicationDirPath() + QLatin1String("/") + outputDir;
        else
            mainPath = outputDir;
    }
    mainDir.setPath(mainPath);

    if (mainDir.exists() && (flags->isForced() == false)) {
        // Might be good to add an interactive menu here
        enterErrorState(QLatin1String("Error - directory already exists! "
                                      "Use -f or --force to force deleting "
                                      "existing directories."));
        return;
    } else {
        if (flags->isForced() == true) {
            if(removeDir(mainPath)) {
                enterErrorState(QLatin1String("When using '--force': Removing "
                                "preexisting directory failed."));
                return;
            }
        }

        mainDir.mkdir(mainPath);
        mainDir.cd(mainPath);

        if (!CodeGenerator::create(wsdl, mainDir, flags, baseClassName, this)) {
            enterErrorState(QLatin1String("Error - code creation failed."));
            return;
        }
    }
    displayOutro();
    return;
}