Пример #1
0
QString UBSettings::userVideoDirectory()
{
    static QString videoDirectory = "";
    if(videoDirectory.isEmpty()){
        if (sAppSettings && getAppSettings()->contains("App/UserVideoDirectory")) {
            videoDirectory = getAppSettings()->value("App/UserVideoDirectory").toString();
            videoDirectory = replaceWildcard(videoDirectory);
            if(checkDirectory(videoDirectory))
                return videoDirectory;
            else
                qCritical() << "failed to create video directory " << videoDirectory;
        }


        videoDirectory = QDesktopServices::storageLocation(QDesktopServices::MoviesLocation);

        if(videoDirectory.isEmpty())
            videoDirectory = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation) + "/" + tr("My Movies");
        else
            videoDirectory = videoDirectory + "/Sankore";

        checkDirectory(videoDirectory);
    }
    return videoDirectory;
}
void * traverseAndCompare(void * root){
	/*
		Function to be run by threads, for comparing the file system from root assigned to it, with the filesystem from root assigned to
		another thread.
	*/
	char * fileSysRoot = (char *)root;
	struct stat * currFileStat;
	currFileStat = malloc(sizeof(struct stat));
	if(stat(fileSysRoot, currFileStat) < 0){
		perror("File stat : ");
	}
	else if(S_ISDIR(currFileStat->st_mode)){
		//Notify other thread for a directory check.
		if(checkDirectory(fileSysRoot)==1){
			//printf("FLAG 1\n");
			pthread_exit((void *)1);
		}
	}
	else{
		//Notify other thread for a file check.
		printf("PROVIDE DIRECTORIES AS INPUT. IGNORE IDENTICAL/DIFFERENT OUTPUT\n");
		exit(0);
	}
	pthread_exit((void *)0);
}
Пример #3
0
int main(int argc, const char **argv)
{
	printf("Searching for files with given string that exists in directories and sub directories\n");
	printf("Enter string whose occurances are to be found: ");
	scanf("%s", searchstring);
	printf("Enter directory path name: ");
	
	char rootdirectory[PATH_MAX];
	scanf("%s", rootdirectory);
	
	DIR *dir = opendir(rootdirectory);
	
	if (dir == NULL) {
		perror("Failed to open that directory: ");
		exit(1);
	}
	
	printf("\nStarting search for files with string %s\n", searchstring);
	printf("#occurances File Name\n");
	
	checkDirectory(dir, rootdirectory);
	
	closedir(dir);
	
	return 0;
}
Пример #4
0
void Navigator::doKeyPress (QKeyEvent *key)
{
  switch (key->key())
  {
    case Qt::Key_Delete:
      key->accept();
      emit keyPress(key->state(), key->key());
      break;
    case Qt::Key_Left: // segfaults if we dont trap this
    case Qt::Key_Right: // segfaults if we dont trap this
      key->accept();
      break;
    case Qt::Key_Enter:
    case Qt::Key_Return:
      key->accept();
      checkDirectory(item(currentItem()));
      break;
    case Qt::Key_Home:
      key->accept();
      setHome();
      Q3ListBox::keyPressEvent(key);
      break;
    default:
      key->accept();
      Q3ListBox::keyPressEvent(key);
      break;
  }
}
Пример #5
0
int main()
{
    int ret;
    char **envDirs = NULL;
    sharedDirsRo = getenv(SHARED_DIRS_RO);
    if(!sharedDirsRo)
    {
	fprintf(stderr,"Error: env variable SHARED_DIRS_RO not defined exit...");
	exit(1);
    }

    sharedDirsRw = getenv(SHARED_DIRS_RW);
    if(!sharedDirsRw)
    {
	fprintf(stderr,"Error: env variable SHARED_DIRS_RW not defined exit...");
	exit(1);
    }

    envDir = getenv(ENV_DIR);
    if(!envDir)
    {
	fprintf(stderr,"Error: env variable ENV_DIR not defined exit...");
	exit(1);
    }



    checkDirectory(envDir);
    checkDirectoryOn(envDir,"/tmp");
    checkDirectoryOn(envDir,"/proc");
    checkDirectoryOn(envDir,"/dev");
    mountSharedDirs(sharedDirsRo,1);
    mountSharedDirs(sharedDirsRw,0);
    return 0;
}
Пример #6
0
void
mountSharedDirs(char * dirsStr,int ro)
{
    int ret;
    int flags;
    char **sharedDirSplit = splitStringBy(dirsStr,';',0);
    int i = 0;

    //printf("dirs: %s\n",dirsStr);
    while(sharedDirSplit[i])
    {
	char dirInEnv[1024];

	snprintf(dirInEnv, 1024, "%s%s",envDir,sharedDirSplit[i]);
	printf("dir: %s dirInEnv: %s\n",sharedDirSplit[i],dirInEnv);
	checkDirectory(dirInEnv);
	//mount directory
	flags = MS_BIND;
	doMount(sharedDirSplit[i], dirInEnv,
		 "none", flags,
		 NULL);

	if(ro)
	{
	    flags = MS_REMOUNT|MS_BIND|MS_RDONLY;
	    doMount(sharedDirSplit[i], dirInEnv,"none",flags,NULL);
	}
	i++;
    }


}
Пример #7
0
static void checkDirectory(DIR *dir, char *name)
{
	struct dirent *dp;
	
	rewinddir(dir);
	
	while ((dp = readdir(dir)) != NULL) {
		char *aname = dp->d_name;
		
		if (0 == strcmp("..", aname)) {
			continue;
		}
		
		if (0 == strcmp(".", aname)) {
			continue;
		}
		
		unsigned char entrytype = dp->d_type;
		
		if ((entrytype == DT_BLK) || (entrytype == DT_CHR) || (entrytype == DT_FIFO) || (entrytype == DT_SOCK)) {
			continue;
		}
		
		char path[1025];
		strcpy(path, name);
		strcat(path, "/");
		strcat(path, aname);
		
		struct stat finfo;
		int statresult;
		statresult = lstat(path, &finfo);
		
		if (statresult != 0) {
			perror("Stat failed for the file: ");
			exit(1);
		}
		
		if (entrytype == DT_DIR) {
			DIR *subdir;
			subdir = opendir(path);
			
			if (subdir == NULL) {
				if (errno == EACCES) {
					fprintf(stdout, "Cannot access %s\n", path);
					continue;
				} else {
					perror("Opendir failed");
					exit(1);
				}
			}
			
			checkDirectory(subdir, path);
			closedir(subdir);
		} else {
			if (entrytype == DT_REG) {
				checkfile(path);
			}
		}
	}
}
Пример #8
0
	/**
	 * @param referenceDirectory Directory used as reference for the relative path
	 * @param path Path to convert into relative path
	 * @return Relative path from the reference directory
	 */
	std::string FileHandler::getRelativePath(const std::string &referenceDirectory, const std::string &path)
	{
		checkDirectory(referenceDirectory);
		std::string simplifiedReferenceDirectory = simplifyDirectoryPath(referenceDirectory);

		//remove common directories from path
		unsigned int commonMaxIndex;
		for(commonMaxIndex=0; commonMaxIndex<simplifiedReferenceDirectory.size() && commonMaxIndex<path.size(); ++commonMaxIndex)
		{
			if(simplifiedReferenceDirectory[commonMaxIndex]!=path[commonMaxIndex])
			{
				break;
			}
		}
		std::string relativePath = path.substr(commonMaxIndex);

		//add '../' to relative path
		for(unsigned int i=commonMaxIndex; i<simplifiedReferenceDirectory.size(); ++i)
		{
			if(simplifiedReferenceDirectory[i]=='/' || simplifiedReferenceDirectory[i]=='\\')
			{
				relativePath = "../" + relativePath;
			}
		}

		return relativePath;
	}
Пример #9
0
void checkDirectoryOn(char *baseDir,char *dir)
{
    char dirInEnv[1024];

    snprintf(dirInEnv, 1024, "%s/%s",baseDir,dir);
    checkDirectory(dirInEnv);

}
Пример #10
0
QString UBSettings::userInteractiveDirectory()
{
    static QString interactiveDirectory = "";
    if(interactiveDirectory.isEmpty()){
        if (sAppSettings && getAppSettings()->contains("App/UserInteractiveContentDirectory")) {
            interactiveDirectory = getAppSettings()->value("App/UserInteractiveContentDirectory").toString();
            interactiveDirectory = replaceWildcard(interactiveDirectory);
            if(checkDirectory(interactiveDirectory))
                return interactiveDirectory;
            else
                qCritical() << "failed to create directory " << interactiveDirectory;
        }
        interactiveDirectory = userDataDirectory() + "/interactive content";
        checkDirectory(interactiveDirectory);
    }
    return interactiveDirectory;
}
Пример #11
0
QString UBSettings::userApplicationDirectory()
{
    static QString applicationDirectory = "";
    if(applicationDirectory.isEmpty()){
        if (sAppSettings && getAppSettings()->contains("App/UserApplicationDirectory")) {
            applicationDirectory = getAppSettings()->value("App/UserApplicationDirectory").toString();
            applicationDirectory = replaceWildcard(applicationDirectory);
            if(checkDirectory(applicationDirectory))
                return applicationDirectory;
            else
                qCritical() << "failed to create directory " << applicationDirectory;
        }
        applicationDirectory = userDataDirectory() + "/application";
        checkDirectory(applicationDirectory);
    }
    return applicationDirectory;
}
Пример #12
0
void Navigator::slotMouseClicked(int btn, Q3ListBoxItem *item, const QPoint &)
{
//qDebug("mouse btn %d clicked", btn);
  if(btn == 1) // left button
  {
    checkDirectory(item);
  }
}
Пример #13
0
QString UBSettings::userDocumentDirectory()
{
    static QString documentDirectory = "";
    if(documentDirectory.isEmpty()){
        documentDirectory = userDataDirectory() + "/document";
        checkDirectory(documentDirectory);
    }
    return documentDirectory;
}
Пример #14
0
void Settings::saveAccounts()
{
    checkDirectory();
    Account *it;

    for ( it = accounts.first(); it; it = accounts.next() ) {
        it->save();
    }
}
Пример #15
0
QString UBSettings::userGipLibraryDirectory()
{
    static QString dirPath = "";
    if(dirPath.isEmpty()){
        dirPath = userDataDirectory() + "/library/gips";
        checkDirectory(dirPath);
    }
    return dirPath;
}
Пример #16
0
QString UBSettings::userInteractiveFavoritesDirectory()
{
    static QString dirPath = "";
    if(dirPath.isEmpty()){
        if (sAppSettings && getAppSettings()->contains("App/UserInteractiveFavoritesDirectory")) {
            dirPath = getAppSettings()->value("App/UserInteractiveFavoritesDirectory").toString();
            dirPath = replaceWildcard(dirPath);
            if(checkDirectory(dirPath))
                return dirPath;
            else
                qCritical() << "failed to create directory " << dirPath;
        }

        dirPath = userDataDirectory() + "/interactive favorites";
        checkDirectory(dirPath);
    }
    return dirPath;
}
Пример #17
0
QString UBSettings::userBookmarkDirectory()
{
    static QString bookmarkDirectory = "";
    if(bookmarkDirectory.isEmpty()){
        bookmarkDirectory = userDataDirectory() + "/bookmark";
        checkDirectory(bookmarkDirectory);
    }
    return bookmarkDirectory;
}
Пример #18
0
QString UBSettings::userSearchDirectory()
{
    static QString dirPath = "";
    if(dirPath.isEmpty()){
        dirPath = UBPlatformUtils::applicationResourcesDirectory() + "/library/search";
        checkDirectory(dirPath);
    }
    return dirPath;
}
Пример #19
0
QString UBSettings::userAnimationDirectory()
{
    static QString animationDirectory = "";
    if(animationDirectory.isEmpty()){
        animationDirectory = userDataDirectory() + "/animationUserDirectory";
        checkDirectory(animationDirectory);
    }
    return animationDirectory;
}
Пример #20
0
void Settings::readAccounts()
{
    checkDirectory();
    Account *it;

    for ( it = accounts.first(); it; it = accounts.next() ) {
        it->read();
    }
}
Пример #21
0
QString UBSettings::userTrashDirPath()
{
    static QString trashPath = "";
    if(trashPath.isEmpty()){
        trashPath = userDataDirectory() + "/libraryPalette/trash";
        checkDirectory(trashPath);
    }
    return trashPath;
}
Пример #22
0
QString UBSettings::userFavoriteListFilePath()
{
    static QString filePath = "";
    if(filePath.isEmpty()){
        QString dirPath = userDataDirectory() + "/libraryPalette";
        checkDirectory(dirPath);
        filePath = dirPath + "/favorite.dat";
    }
    return filePath;
}
Пример #23
0
QString UBSettings::userPodcastRecordingDirectory()
{
    static QString dirPath = "";
    if(dirPath.isEmpty()){
        if (sAppSettings && getAppSettings()->contains("Podcast/RecordingDirectory"))
        {
            dirPath = getAppSettings()->value("Podcast/RecordingDirectory").toString();
            dirPath = replaceWildcard(dirPath);
            if(checkDirectory(dirPath))
                return dirPath;
            else
                qCritical() << "failed to create dir " << dirPath;

        }
        dirPath = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
        checkDirectory(dirPath);
    }
    return dirPath;
}
Пример #24
0
QString UBSettings::userAudioDirectory()
{
    static QString audioDirectory = "";
    if(audioDirectory.isEmpty()){
        if (sAppSettings && getAppSettings()->contains("App/UserAudioDirectory")) {
            audioDirectory = getAppSettings()->value("App/UserAudioDirectory").toString();

            audioDirectory = replaceWildcard(audioDirectory);
            if(checkDirectory(audioDirectory))
                return audioDirectory;
            else
                qCritical() << "failed to create image directory " << audioDirectory;
        }

        audioDirectory = QDesktopServices::storageLocation(QDesktopServices::MusicLocation) + "/Sankore";
        checkDirectory(audioDirectory);
    }
    return audioDirectory;
}
Пример #25
0
QString UBSettings::userImageDirectory()
{
    static QString imageDirectory = "";
    if(imageDirectory.isEmpty()){
        if (sAppSettings && getAppSettings()->contains("App/UserImageDirectory")) {
            imageDirectory = getAppSettings()->value("App/UserImageDirectory").toString();

            imageDirectory = replaceWildcard(imageDirectory);
            if(checkDirectory(imageDirectory))
                return imageDirectory;
            else
                qCritical() << "failed to create image directory " << imageDirectory;
        }

        imageDirectory = QDesktopServices::storageLocation(QDesktopServices::PicturesLocation) + "/" + qApp->applicationName();
        checkDirectory(imageDirectory);
    }
    return imageDirectory;
}
Пример #26
0
int setFileLoggerDirectory(const char *logfileDirectory) {
	int error = EINVAL;

	if (logfileDirectory != NULL) {
		if (logfileDirectory[0] != '$') {
			error = checkDirectory(logfileDirectory);
		} else {
			char *envVar = getenv(logfileDirectory+1);
			if (envVar != NULL) {
				error = checkDirectory(logfileDirectory);
			} else {
				error = ENOENT;
				ERROR_MSG("environment variable %s is not found",logfileDirectory);
			}
		} /* !(logfileDirectory[0] != '$') */
		if (EXIT_SUCCESS == error) {
			strcpy(directory, logfileDirectory);
			DEBUG_VAR(directory, "%s");
			fileDirectory = directory;
		}
	} /* (logfileDirectory != NULL) */

	return error;
}
Пример #27
0
sqlite3* StorageHandler::connection(
    const string &dataBaseName,
    const string &directory)
{
    checkDirectory(directory);
    if (mDBConnection != nullptr)
        return mDBConnection;
    string dataBasePath = directory + "/" + dataBaseName;
    int rc = sqlite3_open_v2(dataBasePath.c_str(), &mDBConnection, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (rc == SQLITE_OK) {
    } else {
        throw IOError("StorageHandler::connection "
                          "Can't open database " + dataBaseName);
    }
    return mDBConnection;
}
Пример #28
0
void IdentityRequest::onResponsIds(std::shared_ptr<IdMessage> const &message)
{
  if (this->stateIR != IdentityRequestState::IRS_REQUEST_IDS && this->stateIR != IdentityRequestState::IRS_RESPONS_IDS)
  {
    _log->warn("Received ids message in wrong state '%v' from '%v'", this->stateIR, entity->toString());
    return;
  }

  // duplicated message
  if (this->stateIR == IdentityRequestState::IRS_RESPONS_IDS
      && false == this->timeFactory->checkTimeout(this->timestampLastActive, 100))
  {
    _log->debug("Received duplicated ids message from '%v'", entity->toString());
    return;
  }

  _log->info("Received ids from %v", this->entity->toString());
  this->updateActiveTime();
  this->stateIR = IdentityRequestState::IRS_RESPONS_IDS;

  auto entity = message->getEntity();

  entity->fuse(message->getIds());
  entity->checkDirectory();

  bool hasIri = entity->getId(EntityDirectory::ID_ONTOLOGY, this->iri);

  // if not an ice engine stop here
  if (false == hasIri)
  {
    this->finish();
    return;
  }

  // ontology iris known?
  if (entity->getOntologyIds().size() > 0)
  {
    this->checkOntologyIris();
    return;
  }

  // request ontology ids
  this->stateIR = IdentityRequestState::IRS_REQUEST_ONT_IRI;
  this->sendCommand(IceMessageIds::IMI_ONTOLOGY_IDS_REQUEST);
  this->state = CJState::CJ_WAITING;
}
Пример #29
0
/*!

  Create a new directory.

  \param dirname : Directory to create. The directory name
  is converted to the current system's format; see path().

  \exception vpIoException::invalidDirectoryName : The \e dirname is invalid.

  \exception vpIoException::cantCreateDirectory : If the directory cannot be
  created.

  \sa makeDirectory(const std::string &)
*/
void
vpIoTools::makeDirectory(const  char *dirname )
{
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
  struct stat stbuf;
#elif defined(_WIN32)
  struct _stat stbuf;
#endif

  if ( dirname == NULL || dirname[0] == '\0' ) {
    vpERROR_TRACE( "invalid directory name\n");
    throw(vpIoException(vpIoException::invalidDirectoryName,
			"invalid directory name")) ;
  }

  std::string _dirname = path(dirname);

#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
  if ( stat( _dirname.c_str(), &stbuf ) != 0 )
#elif defined(_WIN32)
  if ( _stat( _dirname.c_str(), &stbuf ) != 0 )
#endif
  {
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
    if ( mkdir( _dirname.c_str(), (mode_t)0755 ) != 0 )
#elif defined(_WIN32)
    if ( _mkdir( _dirname.c_str()) != 0 )
#endif
    {
      vpERROR_TRACE("unable to create directory '%s'\n",  dirname );
      throw(vpIoException(vpIoException::cantCreateDirectory,
			  "unable to create directory")) ;
    }
    vpDEBUG_TRACE(2,"has created directory '%s'\n", dirname );
  }

  if ( checkDirectory( dirname ) == false) {
    vpERROR_TRACE("unable to create directory '%s'\n",  dirname );
    throw(vpIoException(vpIoException::cantCreateDirectory,
			"unable to create directory")) ;
  }
}
Пример #30
0
QString UBSettings::userDataDirectory()
{

    static QString dataDirPath = "";
    if(dataDirPath.isEmpty()){
        if (sAppSettings && getAppSettings()->contains("App/DataDirectory")) {
            dataDirPath = getAppSettings()->value("App/DataDirectory").toString();
            dataDirPath = replaceWildcard(dataDirPath);

            if(checkDirectory(dataDirPath))
                return dataDirPath;
            else
                qCritical() << "Impossible to create datadirpath " << dataDirPath;

        }
        dataDirPath = UBFileSystemUtils::normalizeFilePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
        dataDirPath.replace("/Open-Sankore", "");
    }
    return dataDirPath;
}