Exemple #1
0
Fichier : du.c Projet : eskirk/MyDu
/*
   Similar to displayAll(), but only prints out folders and the size of those folders
   Also recursively enters sub-directories
*/
void displayFolders(DIR *directory, char *path, long *total, int depth, int human) {
   char *temp = malloc(sizeof(char) * MAX_LEN);
   char *curPath = malloc(sizeof(char) * MAX_LEN);
   struct dirent *tempdir = malloc(sizeof(struct dirent));
   struct stat *stats = malloc(sizeof(struct stat));

   if (directory) {
      while ((tempdir = readdir(directory))) {
         if ((path == NULL) && checkDir(tempdir->d_name) && strcmp(tempdir->d_name, "..") != 0 &&
          strcmp(tempdir->d_name, ".") != 0)
            sprintf(curPath, "./%s", tempdir->d_name);
         else if (checkDir(tempdir->d_name) && strcmp(tempdir->d_name, "..") != 0 && 
          strcmp(tempdir->d_name, ".") != 0)
            sprintf(curPath, "%s/%s", path, tempdir->d_name);

         if (checkDir(tempdir->d_name) && strcmp(tempdir->d_name, "..") != 0 &&
          strcmp(tempdir->d_name, ".") != 0 && depth > 0) {
            sprintf(temp, "./%s", tempdir->d_name);
            chdir(tempdir->d_name);
            displayFolders(opendir("."), curPath, total, depth - 1, human);
            chdir("..");
            lstat(tempdir->d_name, stats);
            *total += roundUp((stats->st_size + (BLOCKSIZE - 1)) / BLOCKSIZE);
            if (!human)
               printf("%d\t%s\n", roundUp((int)(stats->st_size + (BLOCKSIZE - 1)) / BLOCKSIZE), curPath);
            if (human)
               printHuman(stats, -1, curPath);
         }
      }
   }
}
Exemple #2
0
//indexFile will check directory vs file, and either write file or open new directory and call itself recurseively on the new directory.
void indexFileRec(char *pathName, SortedList1Ptr SL)
{
		printf("%s\n", pathName);
		if(checkDir(pathName)==1)//checks file vs directory
		{
			
			int Size = 0;
			FILE* fp =  fopen(pathName, "r");
			fseek(fp, 0L, SEEK_END);
			Size = ftell(fp);
			fseek(fp,0L, SEEK_SET);
			char* fileString = (char*)malloc((Size+1)*sizeof(char));
			fread(fileString,1,Size,fp);
			fileString[Size] = '\0';
			addToList(fileString, SL, pathName);
			free(fileString);
			fclose(fp);

		}

	else if(checkDir(pathName)==0)//checks for directory
	{
		DIR *dp;
		dp= opendir(pathName);
		struct dirent *ep;
		char* temp;

		if(dp!=NULL)
		{
			
			while(ep=readdir(dp))
			{
				if(strcmp(ep->d_name, ".")==0)
					{
						continue;
					}
				if(strcmp(ep->d_name, "..")==0)
					{
						continue;
					}

				int len = strlen(pathName)+strlen(ep->d_name)+3;
				temp = (char*)malloc(len*sizeof(char));
				temp = strcat(temp,pathName);
				temp = strcat(temp,"/");
				temp = strcat(temp,ep->d_name);
				indexFileRec(temp, SL);
				free(temp);

			}
		}
		(void)closedir(dp);

	}	

		
	
}
Exemple #3
0
void QWatermark::checkConditions()
{
    bool enable = true;

    enable &= checkDir(sourceLineEdit->text());
    enable &= checkDir(destinationLineEdit->text());

    startButton->setEnabled(enable);
}
void KPBinaryIface::setup()
{
    QString previous_dir = readConfig();
    m_searchPaths << previous_dir;
    checkDir(previous_dir);
    if (previous_dir != "" && !isValid())
    {
        m_searchPaths << "";
        checkDir("");
    }
}
Exemple #5
0
Fichier : du.c Projet : eskirk/MyDu
/*
   Traverses the directory tree and only ouputs files and directories that contain the substring 'sub'
*/ 
void findSub(DIR *directory, char *path, char *sub) {
   char *temp = malloc(sizeof(char) * MAX_LEN);
   char *curPath = malloc(sizeof(char) * MAX_LEN);
   struct dirent *tempdir = malloc(sizeof(struct dirent));
   struct stat *stats = malloc(sizeof(struct stat));

   if (directory) {
      while ((tempdir = readdir(directory)) ) {
         if (path == NULL)
            sprintf(curPath, "./%s", tempdir->d_name);
         else
            sprintf(curPath, "%s/%s", path, tempdir->d_name);
         if (checkDir(tempdir->d_name) && strcmp(tempdir->d_name, "..") != 0 && 
          strcmp(tempdir->d_name, ".") != 0) {
            sprintf(temp, "./%s", tempdir->d_name);
            chdir(tempdir->d_name);
            findSub(opendir("."), curPath, sub);
            chdir("..");
         }
         if (strstr(tempdir->d_name, sub)) {
            lstat(tempdir->d_name, stats);
            printf("%d\t%s\n", (int)(stats->st_size + BLOCKSIZE - 1) / BLOCKSIZE, curPath);
         }
      }
   }
}
Exemple #6
0
int XJudgerMain::getDir(string dir, int &count){
	struct direct *file = NULL;
	DIR *pdir = opendir(dir.c_str());
	dir = tDir(dir);
	if (pdir){
		while ((file = readdir(pdir)) != NULL){
			if (strcmp(file -> d_name, ".") == 0) continue;
			if (strcmp(file -> d_name, "..") == 0) continue;
			if (checkDir(dir + file -> d_name)){
				QTreeWidgetItem *item;
				if (MainViewScore -> topLevelItemCount() <= count) item = new QTreeWidgetItem(MainViewScore);
				else item = MainViewScore -> topLevelItem(count);
				item -> setData(0, 0, file -> d_name);
				item -> setData(3, 0, (dir + file -> d_name).c_str());
				PersonInfo info(dir + file -> d_name);
				char strout[30];
				snprintf(strout, 30, "%5.0lf", info.Score);
				item -> setData(1, 0, strout);
				snprintf(strout, 30, "%.3lf s", info.ACTime);
				item -> setData(2, 0, strout);
				item -> setIcon(0, QIcon(":/Icons/User.png"));
				count ++;
			}
			getDir(dir + file -> d_name, count);
		}
	}
	closedir(pdir);
	return 0;
}
Exemple #7
0
int LsnWeb::checkSysStatus(char * procdir)
{

	int iShell = -1;
	bool bDir = false;

	if(NULL == procdir)
	{
		trace_log(ERR, "Process direct is null");
		return iShell;
	}
	
	bDir = checkDir(g_Cfg.cfgProp.portdir);

	
	if(!bDir)
	{
		trace_log(ERR, "Shell dir is not exsits. %s",g_Cfg.cfgProp.portdir);
		return iShell;
	}
	
	iShell = analysAndDealSys(g_Cfg.cfgProp.portdir, procdir, 1);
	
	
	return iShell;
}
void KPBinaryIface::slotNavigateAndCheck()
{
    KUrl start;

    if (isValid() && !m_pathDir.isEmpty())
    {
        start = KUrl(m_pathDir);
    }
    else
    {
#if defined Q_OS_MAC
        start = KUrl(QString("/Applications/"));
#elif defined Q_OS_WIN
        start = KUrl(QString("C:/Program Files/"));
#else
        start = KUrl(QString("/usr/bin/"));
#endif
    }

    QString f = KFileDialog::getOpenFileName(start,
                                             QString(m_binaryBaseName),
                                             0,
                                             QString(i18n("Navigate to %1", m_binaryBaseName)));
    QString dir = KUrl(f).directory();
    m_searchPaths << dir;

    if (checkDir(dir))
    {
        emit signalSearchDirectoryAdded(dir);
    }
}
Exemple #9
0
bool CDDB::local_query(
    unsigned  long magicID,
    QString&  data,
    QStrList& titlelist,
    QStrList& extlist,
    QString&  _category,
    QStrList& discidlist,
    int&	 revision,
    QStrList& playlist
){

    if(pathlist.count() == 0)
	return false;

    for(int i = 0 ; i <(int) pathlist.count(); i++){

	if (debugflag) fprintf(stderr,"Checking %s\n",pathlist.at(i));

	if(checkDir(magicID,pathlist.at(i))){
	    getCategoryFromPathName(pathlist.at(i),category);
	    category.detach();
	    getData(data,titlelist,extlist,_category,discidlist,revision,playlist);
	    return true;
	}
    }

    return false;

}
Exemple #10
0
bool checkStoragePaths(QString *probs)
{
    bool problemFound = false;

    QString recordFilePrefix = gContext->GetSetting("RecordFilePrefix", "EMPTY");

    MSqlQuery query(MSqlQuery::InitCon());

    query.prepare("SELECT count(groupname) FROM storagegroup;");
    if (!query.exec() || !query.isActive() || query.size() < 1)
    {
        MythContext::DBError("checkStoragePaths", query);
        return false;
    }

    query.next();
    if (query.value(0).toInt() == 0)
    {
        QString trMesg;

        trMesg = QObject::tr("No Storage Group directories are defined.  You "
                             "must add at least one directory to the Default "
                             "Storage Group where new recordings will be "
                             "stored.");
        probs->append(trMesg + "\n");
        VERBOSE(VB_IMPORTANT, trMesg);
        return true;
    }

    query.prepare("SELECT groupname, dirname "
                  "FROM storagegroup "
                  "WHERE hostname = :HOSTNAME;");
    query.bindValue(":HOSTNAME", gContext->GetHostName());
    if (!query.exec() || !query.isActive() || query.size() < 1)
    {
        MythContext::DBError("checkStoragePaths", query);
        return false;
    }

    QDir checkDir("");
    while (query.next())
    {
        QString sgDir = query.value(0).toString();
        QStringList tokens = QStringList::split(",", query.value(1).toString());
        unsigned int curToken = 0;
        while (curToken < tokens.size())
        {
            checkDir.setPath(tokens[curToken]);
            if (checkPath(tokens[curToken], probs))
            {
                problemFound = true;
            }
            curToken++;
        }
    }

    return problemFound;
}
Exemple #11
0
/* Passing a copy to rootDir is on purpose here */
static int isValidEncFS(std::string rootDir) {
    if( !checkDir( rootDir ))
	return EXIT_FAILURE;

#ifdef ENCFS_SVN
    EncfsConfig config;
#else
    shared_ptr<EncFSConfig> config(new EncFSConfig);
#endif
    ConfigType type = readConfig( rootDir, config );

#ifdef ENCFS_SVN
    std::string config_creator = config.creator();
    int config_revision = config.revision();
#else
    std::string config_creator = config->creator;
    int config_revision = config->subVersion;
#endif

    std::ostringstream info;
    // show information stored in config..
    switch(type)
    {
    case Config_None:
        info << "Unable to load or parse config file in " << rootDir;
	LOGI(info.str().c_str());
	return EXIT_FAILURE;
    case Config_Prehistoric:
	LOGI("A really old EncFS filesystem was found.\n"
             "It is not supported in this EncFS build.");
	return EXIT_FAILURE;
    case Config_V3:
        info << "Version 3 configuration; created by " << config_creator.c_str();
        break;
    case Config_V4:
        info << "Version 4 configuration; created by " << config_creator.c_str();
        break;
    case Config_V5:
        info << "Version 5 configuration; created by " << config_creator.c_str()
             << " (revision " << config_revision << ")";
	break;
    case Config_V6:
        info << "Version 6 configuration; created by " << config_creator.c_str()
             << " (revision " << config_revision << ")";
	break;
#ifdef ENCFS_SVN
    case Config_V7:
        info << "Version 7 configuration; created by " << config_creator.c_str()
             << " (revision " << config_revision << ")";
	break;
#endif
    }
    LOGI(info.str().c_str());

    showFSInfo( config );

    return EXIT_SUCCESS;
}
void testRAMDirectoryString (CuTest *tc) {

    MockRAMDirectory * ramDir = _CLNEW MockRAMDirectory(indexDir);

    checkDir(tc, ramDir);

    ramDir->close();
    _CLLDELETE(ramDir);
}
Exemple #13
0
void MainWindow::CheckDirectory()
{
    QStringList dir = SelectFilesToCheck(QFileDialog::DirectoryOnly);
    if (dir.isEmpty())
        return;

    QDir checkDir(dir[0]);
    QStringList filters;
    filters << "*.cppcheck";
    checkDir.setFilter(QDir::Files | QDir::Readable);
    checkDir.setNameFilters(filters);
    QStringList projFiles = checkDir.entryList();
    if (!projFiles.empty()) {
        if (projFiles.size() == 1) {
            // If one project file found, suggest loading it
            QMessageBox msgBox(this);
            msgBox.setWindowTitle(tr("Cppcheck"));
            const QString msg(tr("Found project file: %1\n\nDo you want to "
                                 "load this project file instead?").arg(projFiles[0]));
            msgBox.setText(msg);
            msgBox.setIcon(QMessageBox::Warning);
            msgBox.addButton(QMessageBox::Yes);
            msgBox.addButton(QMessageBox::No);
            msgBox.setDefaultButton(QMessageBox::Yes);
            int dlgResult = msgBox.exec();
            if (dlgResult == QMessageBox::Yes) {
                QString path = checkDir.canonicalPath();
                if (!path.endsWith("/"))
                    path += "/";
                path += projFiles[0];
                LoadProjectFile(path);
            } else {
                DoCheckFiles(dir);
            }
        } else {
            // If multiple project files found inform that there are project
            // files also available.
            QMessageBox msgBox(this);
            msgBox.setWindowTitle(tr("Cppcheck"));
            const QString msg(tr("Found project files from the directory.\n\n"
                                 "Do you want to proceed checking without "
                                 "using any of these project files?"));
            msgBox.setText(msg);
            msgBox.setIcon(QMessageBox::Warning);
            msgBox.addButton(QMessageBox::Yes);
            msgBox.addButton(QMessageBox::No);
            msgBox.setDefaultButton(QMessageBox::Yes);
            int dlgResult = msgBox.exec();
            if (dlgResult == QMessageBox::Yes) {
                DoCheckFiles(dir);
            }
        }
    } else {
        DoCheckFiles(dir);
    }
}
Exemple #14
0
// Loads the index file
void Cache::load()
{
	std::string path = cacheDir();
	PDEBUG << "Using cache dir: " << path << endl;

	m_index.clear();
	m_loaded = true;

	bool created;
	checkDir(path, &created);
	lock();
	if (created) {
		return;
	}

	// For git repositories, the hardest part is calling uuid()
	sys::datetime::Watch watch;

	GZIStream *in = new GZIStream(path+"/index");
	if (!in->ok()) {
		Logger::info() << "Cache: Empty cache for '" << uuid() << '\'' << endl;
		return;
	}

	uint32_t version;
	*in >> version;
	switch (checkVersion(version)) {
		case OutOfDate:
			delete in;
			throw PEX(str::printf("Cache is out of date - please run the check_cache report", version));
		case UnknownVersion:
			delete in;
			throw PEX(str::printf("Unknown cache version number %u - please run the check_cache report", version));
		default:
			break;
	}

	Logger::status() << "Loading cache index... " << ::flush;

	std::string buffer;
	std::pair<uint32_t, uint32_t> pos;
	uint32_t crc;
	while (!(*in >> buffer).eof()) {
		if (buffer.empty()) {
			break;
		}
		*in >> pos.first >> pos.second;
		*in >> crc;
		m_index[buffer] = pos;
	}

	Logger::status() << "done" << endl;
	delete in;
	Logger::info() << "Cache: Loaded " << m_index.size() << " revisions in " << watch.elapsedMSecs() << " ms" << endl;
}
Exemple #15
0
QString StorageGroup::FindNextDirMostFree(void)
{
    QString nextDir;
    long long nextDirFree = 0;
    long long thisDirTotal;
    long long thisDirUsed;
    long long thisDirFree;

    LOG(VB_FILE, LOG_DEBUG, LOC + QString("FindNextDirMostFree: Starting"));

    if (m_allowFallback)
        nextDir = kDefaultStorageDir;

    if (m_dirlist.size())
        nextDir = m_dirlist[0];

    QDir checkDir("");
    int curDir = 0;
    while (curDir < m_dirlist.size())
    {
        checkDir.setPath(m_dirlist[curDir]);
        if (!checkDir.exists())
        {
            LOG(VB_GENERAL, LOG_ERR, LOC +
                QString("FindNextDirMostFree: '%1' does not exist!")
                    .arg(m_dirlist[curDir]));
            curDir++;
            continue;
        }

        thisDirFree = getDiskSpace(m_dirlist[curDir], thisDirTotal,
                                   thisDirUsed);
        LOG(VB_FILE, LOG_DEBUG, LOC +
            QString("FindNextDirMostFree: '%1' has %2 KiB free")
                .arg(m_dirlist[curDir])
                .arg(QString::number(thisDirFree)));

        if (thisDirFree > nextDirFree)
        {
            nextDir     = m_dirlist[curDir];
            nextDirFree = thisDirFree;
        }
        curDir++;
    }

    if (nextDir.isEmpty())
        LOG(VB_FILE, LOG_ERR, LOC + 
            "FindNextDirMostFree: Unable to find any directories to use.");
    else
        LOG(VB_FILE, LOG_DEBUG, LOC +
            QString("FindNextDirMostFree: Using '%1'").arg(nextDir));

    nextDir.detach();
    return nextDir;
}
Exemple #16
0
void ScanThread::scanDirs()
{
    db_iterator const itDirsEnd = db_.dirs_end();
        
    for (db_iterator itDir = db_.dirs_begin(); 
         itDir != itDirsEnd && !shouldBreak(); 
                                      ++itDir)
    {
        checkDir(*itDir);
    }
}
Exemple #17
0
//main sprawdzanie argumentow i wywolanie funkcji
int main(int argc, char** argv) {
    int i;
    for (i = 1; i < argc; i++) {
        if (strcmp("-w", argv[i]) == 0) w = 1;
        if (strcmp("-v", argv[i]) == 0) v = 1;
    }
    exeName=argv[0];
    parseExtensions();
    checkDir(argv);
    return (EXIT_SUCCESS);
}
Exemple #18
0
WSLUA_METHOD Dir_close(lua_State* L) {
	/* Closes the directory */
	Dir dir = checkDir(L,1);

	if (dir->dir) {
		CLOSEDIR_OP(dir->dir);
		dir->dir = NULL;
	}

	return 0;
}
Exemple #19
0
void KPBinaryIface::slotAddPossibleSearchDirectory(const QString& dir)
{
    if (!isValid())
    {
        m_searchPaths << dir;
        checkDir(dir);
    }
    else
    {
        m_searchPaths << dir;
    }
}
Exemple #20
0
JNIEXPORT jint JNICALL Java_csh_cryptonite_Cryptonite_jniExport(JNIEnv * env, jobject thiz, jobjectArray exportpaths,
                                                                jstring exportroot, jstring destdir)
{
    int res = checkGRoot();

    if (res != EXIT_SUCCESS) {
        return res;
    }

    int npaths = env->GetArrayLength(exportpaths);
    if (npaths==0)
        return res;
    
    // std::ostringstream info;
    // info << "Received " << npaths << " paths";
    // LOGI(info.str().c_str());

    jniStringManager mexportroot = jniStringManager(env, exportroot);
    
    jclass stringClass = env->FindClass("java/lang/String");
     
    std::set<std::string> std_exportpaths;
    for (int nstr = 0; nstr < npaths; ++nstr) {
        jobject obj = env->GetObjectArrayElement(exportpaths, nstr);
        if (env->IsInstanceOf(obj, stringClass)) {
            std_exportpaths.insert(jniStringManager(env, (jstring)obj).str());
        }
    }

    // std::set<std::string> allPaths(fullTree(std_exportpaths, mexportroot.str()));
    std::set<std::string> allPaths(std_exportpaths);
    
    // info.str("");
    // info << "Full size of tree is " << allPaths.size();
    // LOGI(info.str().c_str());

    
    std::set<std::string>::const_iterator it = allPaths.begin();
    // for (; it != allPaths.end(); ++it) {
    //     LOGI((*it).c_str());
    // }

    jniStringManager mdestdir(env, destdir);

    // if the dir doesn't exist, then create it (with user permission)
    if(!checkDir(mdestdir.str()) && !userAllowMkdir(mdestdir.c_str(), 0700))
	return EXIT_FAILURE;

    // LOGI((std::string("Exporting to ") + mdestdir.str()).c_str());
    res = (int)exportFiles(gRootInfo, "/", mdestdir.str(), allPaths);

    return res;
}
Exemple #21
0
JNIEXPORT jint JNICALL
Java_csh_cryptonite_Cryptonite_jniCreate(JNIEnv* env, jobject thiz, jstring srcdir, jstring password, jint config)
{
    int pw_len = (int)env->GetStringLength(password);
    if (pw_len  == 0) {
        return EXIT_FAILURE;
    }

    jniStringManager msrcdir(env, srcdir);
    jniStringManager mpassword(env, password);

    RootPtr result;
    shared_ptr<EncFS_Opts> opts( new EncFS_Opts() );
    opts->createIfNotFound = true;
    opts->checkKey = true;
    opts->password.assign(mpassword.str());
    opts->rootDir.assign(msrcdir.str());

    switch ((int)config) {
     case 0:
         opts->configMode = Config_Paranoia;
         break;
     case 1:
         opts->configMode = Config_Standard;
         break;
     case 2:
         opts->configMode = Config_Compatible;
         break;
     case 3:
         opts->configMode = Config_Quick;
         break;
     default:
         opts->configMode = Config_Standard;
    }
    
    if(checkDir( opts->rootDir )) {
        LOGI((std::string("Initialising file system with root ") + msrcdir.str()).c_str());
        result = initFS( NULL, opts );
    }

    // clear buffer
    opts->password.assign(opts->password.length(), '\0');

    if(!result) {
        LOGE("Unable to initialize encrypted filesystem - check path.");
        return EXIT_FAILURE;
    }

    /* clear password copy */
    mpassword.release();

    return EXIT_SUCCESS;
}
void testRAMDirectory (CuTest *tc) {

    Directory * dir = FSDirectory::getDirectory(indexDir);
    MockRAMDirectory * ramDir = _CLNEW MockRAMDirectory(dir);

    // close the underlaying directory
    dir->close();
    _CLDELETE( dir );

    checkDir(tc, ramDir);

    ramDir->close();
    _CLLDELETE(ramDir);
}
bool KPBinaryIface::recheckDirectories()
{
    if (isValid())
    {
        // No need for recheck if it is already valid...
        return true;
    }
    foreach(QString dir, m_searchPaths)
    {
        checkDir(dir);
        if (isValid())
        {
            return true;
        }
    }
Exemple #24
0
static int wslua_Dir__gc(lua_State* L) {
	Dir dir = checkDir(L,1);

	if (dir->dir) {
		CLOSEDIR_OP(dir->dir);
	}

	g_free(dir->dummy);

	if (dir->ext) g_free(dir->ext);

	g_free(dir);

	return 0;
}
Exemple #25
0
bool CModManager::removeModDir(QString path)
{
	// issues 2673 and 2680 its why you do not recursively remove without sanity check
	QDir checkDir(path);
	if(!checkDir.cdUp() || QString::compare("Mods", checkDir.dirName(), Qt::CaseInsensitive))
		return false;
	if(!checkDir.cdUp() || QString::compare("vcmi", checkDir.dirName(), Qt::CaseInsensitive))
		return false;

	QDir dir(path);
	if(!dir.absolutePath().contains("vcmi", Qt::CaseInsensitive))
		return false;
	if(!dir.absolutePath().contains("Mods", Qt::CaseInsensitive))
		return false;

	return dir.removeRecursively();
}
Exemple #26
0
WSLUA_METAMETHOD Dir__call(lua_State* L) {
	/* At every invocation will return one file (nil when done) */

	Dir dir = checkDir(L,1);
	const FILE_T* file;
	const gchar* filename;
	const char* ext;

	if (!dir) {
		luaL_argerror(L,1,"must be a Dir");
		return 0;
	}

	if (!dir->dir) {
		return 0;
	}

	if ( ! ( file = DIRGETNEXT_OP(dir->dir ) )) {
		CLOSEDIR_OP(dir->dir);
		dir->dir = NULL;
		return 0;
	}


	if ( ! dir->ext ) {
		filename = GETFNAME_OP(file);
		lua_pushstring(L,filename);
		return 1;
	}

	do {
		filename = GETFNAME_OP(file);

		/* XXX strstr returns ptr to first match,
			this fails ext=".xxx" filename="aaa.xxxz.xxx"  */
		if ( ( ext = strstr(filename,dir->ext)) && g_str_equal(ext,dir->ext) ) {
			lua_pushstring(L,filename);
			return 1;
		}
	} while(( file = DIRGETNEXT_OP(dir->dir) ));

	CLOSEDIR_OP(dir->dir);
	dir->dir = NULL;
	return 0;
}
Exemple #27
0
JNIEXPORT jint JNICALL
Java_csh_cryptonite_Cryptonite_jniBrowse(JNIEnv* env, jobject thiz,
        jstring srcdir, jstring destdir, jstring password,
        jboolean useAnyKey, jstring configOverride)
{
    int res = setupRootDir(env, srcdir, password, useAnyKey, configOverride);
    if (res != EXIT_SUCCESS) {
        return res;
    }

    jniStringManager mdestdir(env, destdir);

    // if the dir doesn't exist, then create it (with user permission)
    if(!checkDir(mdestdir.str()) && !userAllowMkdir(mdestdir.c_str(), 0700))
	return EXIT_FAILURE;

    std::set<std::string> empty;
    res = traverseDirs(gRootInfo, "/", mdestdir.str(), empty);

    return res;
}
Exemple #28
0
WSLUA_METAMETHOD Dir__call(lua_State* L) {
    /* At every invocation will return one file (nil when done). */

    Dir dir = checkDir(L,1);
    const gchar* file;
    const gchar* filename;
    const char* ext;

    if (!dir->dir) {
        return 0;
    }

    if ( ! ( file = g_dir_read_name(dir->dir ) )) {
        g_dir_close(dir->dir);
        dir->dir = NULL;
        return 0;
    }


    if ( ! dir->ext ) {
        lua_pushstring(L,file);
        return 1;
    }

    do {
        filename = file;

        /* XXX strstr returns ptr to first match,
            this fails ext=".xxx" filename="aaa.xxxz.xxx"  */
        if ( ( ext = strstr(filename,dir->ext)) && g_str_equal(ext,dir->ext) ) {
            lua_pushstring(L,filename);
            return 1;
        }
    } while(( file = g_dir_read_name(dir->dir) ));

    g_dir_close(dir->dir);
    dir->dir = NULL;
    return 0;
}
Exemple #29
0
/**
 * Searches in the "name" directory for the "find" file,
 * if file is found and the user wanted to find that filetype
 * the path is added to a list that will be printed at the end.
 * Also puts all directories found in a list for it to be
 * searched.
 */
bool searchForFile(char* name, char *find, int t, struct Node* list) {
	DIR *dir;

	struct dirent *ent;
	struct stat f_info;
	bool foundFile = false;

	if (openDir(&dir, name, &ent)) {
		do {
			if ((lstat(ent->d_name, &f_info)) < 0) {
				fprintf(stderr, "lstat error: ");
				perror(ent->d_name);
			} else {
				if (t == 0 && compareName(ent->d_name, find)) {
					foundFile = true;
				} else if (checkDir(t, f_info, ent->d_name, find)) {
					foundFile = true;
				} else if (checkReg(t, f_info, ent->d_name, find)) {
					foundFile = true;
				} else if (checkLink(t, f_info, ent->d_name, find)) {
					foundFile = true;
				}
				if (checkDirAndRights(f_info) && !isDot(ent->d_name)) {
					int l = strlen(name) + strlen(ent->d_name);
					char *str = calloc(1, sizeof(char[l + 2]));

					strcpy(str, name);
					strcat(str, "/");
					strcat(str, ent->d_name);
					insert(list, str);
				}
			}
		} while ((ent = readdir(dir)));

	}
	closedir(dir);

	return foundFile;
}
Exemple #30
0
static RootPtr initRootInfo(const std::string& rootDir, const std::string& password, bool useAnyKey, const std::string& configOverride)
{
    RootPtr result;
    shared_ptr<EncFS_Opts> opts( new EncFS_Opts() );
    opts->createIfNotFound = false;
    opts->checkKey = !useAnyKey;
    opts->password.assign(password);
    opts->configOverride.assign(configOverride);
    opts->rootDir.assign(rootDir);
    if(checkDir( opts->rootDir )) {
        LOGI((std::string("Initialising file system with root ") + rootDir).c_str());
        result = initFS( NULL, opts );
    }

    // clear buffer
    opts->password.assign(opts->password.length(), '\0');

    if(!result) {
        LOGE("Unable to initialize encrypted filesystem - check path.");
    }

    return result;
}