예제 #1
0
      bool MemFileSystem::rename(const Path& from,const Path& to)
      {         
         // Source must exist
         FileNodeRef source = mRootDir->resolve(from);
         if (source.isNull())
            return false;
          
         // Destination must not exist
         FileNodeRef dest = mRootDir->resolve(to);
         if (source.isValid())
            return false;

         // Get source parent
         FileNodeRef sourceParentRef;
         MemDirectory* sourceDir = getParentDir(from, sourceParentRef);

         // Get dest parent
         FileNodeRef destRef;
         MemDirectory* mDir = getParentDir(to, destRef);

         // Now move it/rename it
         if (dynamic_cast<MemDirectory*>(source.getPointer()))
         {
            MemDirectoryData* sourcedd;
            MemDirectoryData* d = sourceDir->mDirectoryData;
            for (U32 i = 0; i < d->mDirectories.size(); i++)
            {
               if (d->mDirectories[i]->mPath == from)
               {
                  sourcedd = d->mDirectories[i];
                  d->mDirectories.erase_fast(i);
                  sourcedd->mPath = to;
                  mDir->mDirectoryData->mDirectories.push_back(sourcedd);            
                  return true;
               }
            }
         } else {
            MemFileData* sourceFile;
            MemDirectoryData* d = sourceDir->mDirectoryData;
            for (U32 i = 0; i < d->mFiles.size(); i++)
            {
               if (d->mFiles[i]->mPath == from)
               {
                  sourceFile = d->mFiles[i];
                  d->mFiles.erase_fast(i);
                  sourceFile->mPath = to;
                  mDir->mDirectoryData->mFiles.push_back(sourceFile);            
                  return true;
               }
            }
         }
         return false;
      }
예제 #2
0
 bool MemFileSystem::remove(const Path& path)
 {
    FileNodeRef parentRef;
    MemDirectory* mDir = getParentDir(path, parentRef);
    MemDirectoryData* mdd = mDir->mDirectoryData;
    for (U32 i = 0; i < mdd->mDirectories.size(); i++)
    {
       if (mdd->mDirectories[i]->mPath == path)
       {
          delete mdd->mDirectories[i];
          mdd->mDirectories.erase_fast(i);
          return true;
       }
    }
    for (U32 i = 0; i < mdd->mFiles.size(); i++)
    {
       if (mdd->mFiles[i]->mPath == path)
       {
          delete mdd->mFiles[i];
          mdd->mFiles.erase_fast(i);
          return true;
       }
    }
    return false;
 }
예제 #3
0
bool TFilePath::match(const TFilePath &fp) const
{
	return getParentDir() == fp.getParentDir() &&
		   getName() == fp.getName() &&
		   getFrame() == fp.getFrame() &&
		   getType() == fp.getType();
}
예제 #4
0
int deteleFiles (int fd, char web_root[], char offset_dir[])
{
    int len = strlen(offset_dir);
    if ( ( *(offset_dir+len-1) != '.') )
    {
        printf("_dir%s\n", offset_dir);
        printf("The last character is not '.',not delete command\n");
        return -1;
    }
    *(offset_dir+len-1) = '\0';

    char path[DIR_LENGTH];
    memset(path,0,DIR_LENGTH*sizeof(char));
    strcpy(path,web_root);
    strcat(path,offset_dir);
    printf("delete file %s\n",path);

    char parent_dir[DIR_LENGTH] ;
    memset(parent_dir,0,DIR_LENGTH*sizeof(char));
    getParentDir(parent_dir,offset_dir);
    printf("uri %s  parent dir %s\n",offset_dir,parent_dir);

    if( remove(path) != 0 )
    {
        perror("delete file error!");
        return -1;
    }
    printDir(fd, web_root, parent_dir);
    return 0;
}
예제 #5
0
TFilePath TFilePath::decode(const std::map<string, string> &dictionary) const {
  TFilePath parent   = getParentDir();
  TFilePath filename = withParentDir("");
  std::map<string, string>::const_iterator it =
      dictionary.find(filename.getFullPath());
  if (it != dictionary.end()) filename = TFilePath(it->second);
  if (parent.isEmpty())
    return filename;
  else
    return parent.decode(dictionary) + filename;
}
예제 #6
0
파일: SD.cpp 프로젝트: Defragster/SD
File SDClass::open(const char *filepath, uint8_t mode) {
  /*

     Open the supplied file path for reading or writing.

     The file content can be accessed via the `file` property of
     the `SDClass` object--this property is currently
     a standard `SdFile` object from `sdfatlib`.

     Defaults to read only.

     If `write` is true, default action (when `append` is true) is to
     append data to the end of the file.

     If `append` is false then the file will be truncated first.

     If the file does not exist and it is opened for writing the file
     will be created.

     An attempt to open a file for reading that does not exist is an
     error.

   */

  int pathidx;

  // do the interative search
  SdFile parentdir = getParentDir(filepath, &pathidx);
  // no more subdirs!

  filepath += pathidx;

  if (! filepath[0]) {
    // it was the directory itself!
    return File(parentdir, "/");
  }

  // Open the file itself
  SdFile file;

  // failed to open a subdir!
  if (!parentdir.isOpen())
    return File();

  if ( ! file.open(parentdir, filepath, mode)) {
    return File();
  }
  // close the parent
  parentdir.close();

  if (mode & (O_APPEND | O_WRITE)) 
    file.seekSet(file.fileSize());
  return File(file, filepath);
}
예제 #7
0
파일: SAction.cpp 프로젝트: Gaerzi/SLADE
/* SAction::initActions
 * Loads and parses all SActions configured in actions.cfg in the
 * program resource archive
 *******************************************************************/
bool SAction::initActions()
{
	// Get actions.cfg from slade.pk3
	auto cfg_entry = theArchiveManager->programResourceArchive()->entryAtPath("actions.cfg");
	if (!cfg_entry)
		return false;

	Parser parser(cfg_entry->getParentDir());
	if (parser.parseText(cfg_entry->getMCData(), "actions.cfg"))
	{
		auto root = parser.parseTreeRoot();
		for (unsigned a = 0; a < root->nChildren(); a++)
		{
			auto node = root->getChildPTN(a);

			// Single action
			if (S_CMPNOCASE(node->type(), "action"))
			{
				auto action = new SAction(node->getName(), node->getName());
				if (action->parse(node))
					actions.push_back(action);
				else
					delete action;
			}

			// Group of actions
			else if (S_CMPNOCASE(node->getName(), "group"))
			{
				int group = newGroup();

				for (unsigned b = 0; b < node->nChildren(); b++)
				{
					auto group_node = node->getChildPTN(b);
					if (S_CMPNOCASE(group_node->type(), "action"))
					{
						auto action = new SAction(group_node->getName(), group_node->getName());
						if (action->parse(group_node))
						{
							action->group = group;
							actions.push_back(action);
						}
						else
							delete action;
					}
				}
			}
		}
	}

	return true;
}
예제 #8
0
void getBg(Mat &bgIm, vector<string> &imPaths, float bgSub, int w, int h)
{
	if (bgSub == 0.0) // not doing background subtraction
		return;
	
	std::cout <<"Starting Background Subtraction:" << std::endl;
	int choose = (int)(imPaths.size() * bgSub);

	map<double, int> meanToIndex;
	for (int i = 0; i < imPaths.size(); i++)
	{
		cout << imPaths[i] << endl;
		Mat im;
		loadFloatTiff(imPaths[i], im, w, h);
		double mean = cv::mean(abs(im))[0];
		while (!meanToIndex.insert(pair<double, int>(mean, i)).second)
		{
			// deal with duplicate means
			mean += DBL_MIN;
		}
	}

	Mat bg = Mat::zeros(h, w, CV_32F);
	int count = 0;
	for (auto it = meanToIndex.begin(); it != meanToIndex.end(); ++it)
	{
		if (count >= choose) break;
		std::cout << it->first << " => " << it->second << '\n';
		Mat im;
		loadFloatTiff(imPaths[it->second], im, w, h);
		bg += im;
		count++;
	}

	bg /= choose;

	ostringstream ss;
	ss << getParentDir(imPaths[0]) << "bgimage.tif";
	saveFloatTiff(ss.str(), bg);

	bgIm = bg.clone();
}
예제 #9
0
      FileNodeRef MemFileSystem::create(const Path& path, FileNode::Mode mode)
      {
         // Already exists
         FileNodeRef result = mRootDir->resolve(path);
         if (result.isValid())
            return result;

         // Doesn't exist, try to get parent node.
         FileNodeRef parentRef;
         MemDirectory* mDir = getParentDir(path, parentRef);
         if (mDir)
         {
            MemDirectoryData* mdd = mDir->mDirectoryData;
            switch (mode)
            {
               case FileNode::File :
                  {
                     MemFileData* mfd = new MemFileData(this, path);
                     mdd->mFiles.push_back(mfd);
                     return new MemFile(this, mfd);
                  }
                  break;
               case FileNode::Directory :
                  {
                     MemDirectoryData* mfd = new MemDirectoryData(this, path);
                     mdd->mDirectories.push_back(mfd);
                     return new MemDirectory(this, mfd);
                  }
                  break;
               default:
                  // anything else we ignore
                  break;
            }
         }         
         return NULL;
      }
예제 #10
0
파일: Parser.cpp 프로젝트: Talon1024/SLADE
// ----------------------------------------------------------------------------
// ParseTreeNode::parsePreprocessor
//
// Parses a preprocessor directive at [tz]'s current token
// ----------------------------------------------------------------------------
bool ParseTreeNode::parsePreprocessor(Tokenizer& tz)
{
	//Log::debug(S_FMT("Preprocessor %s", CHR(tz.current().text)));

	// #define
	if (tz.current() == "#define")
		parser_->define(tz.next().text);

	// #if(n)def
	else if (tz.current() == "#ifdef" || tz.current() == "#ifndef")
	{
		// Continue if condition succeeds
		bool test = true;
		if (tz.current() == "#ifndef")
			test = false;
		string define = tz.next().text;
		if (parser_->defined(define) == test)
			return true;

		// Failed condition, skip section
		int skip = 0;
		while (true)
		{
			auto& token = tz.next();
			if (token == "#endif")
				skip--;
			else if (token == "#ifdef")
				skip++;
			else if (token == "#ifndef")
				skip++;
			// TODO: #else

			if (skip < 0)
				break;
		}
	}

	// #include
	else if (tz.current() == "#include")
	{
		// Include entry at the given path if we have an archive dir set
		if (archive_dir_)
		{
			// Get entry to include
			auto inc_path = tz.next().text;
			auto archive = archive_dir_->archive();
			auto inc_entry = archive->entryAtPath(archive_dir_->getPath() + inc_path);
			if (!inc_entry) // Try absolute path
				inc_entry = archive->entryAtPath(inc_path);

			//Log::debug(S_FMT("Include %s", CHR(inc_path)));

			if (inc_entry)
			{
				// Save the current dir and set it to the included entry's dir
				auto orig_dir = archive_dir_;
				archive_dir_ = inc_entry->getParentDir();

				// Parse text in the entry
				Tokenizer inc_tz;
				inc_tz.openMem(inc_entry->getMCData(), inc_entry->getName());
				bool ok = parse(inc_tz);

				// Reset dir and abort if parsing failed
				archive_dir_ = orig_dir;
				if (!ok)
					return false;
			}
			else
				logError(tz, S_FMT("Include entry %s not found", CHR(inc_path)));
		}
		else
			tz.adv();	// Skip include path
	}

	// #endif (ignore)
	else if (tz.current() == "#endif")
		return true;

	// TODO: #else

	// Unrecognised
	else
		logError(tz, S_FMT("Unrecognised preprocessor directive \"%s\"", CHR(tz.current().text)));

	return true;
}
예제 #11
0
int printDir (int fd, char web_root[], char offset_dir[])
{
    DIR *dir;
    struct dirent *dirp;
    struct stat statbuf;

    char buf[DIR_LENGTH];
    int num_dir,num_reg;
    char msg_head[MAX_BUFFER_SIZE], msg_txt[MAX_BUFFER_SIZE];
    memset(buf,0,DIR_LENGTH*sizeof(char));
    memset(msg_txt,0,MAX_BUFFER_SIZE*sizeof(char));
    memset(msg_head,0,MAX_BUFFER_SIZE*sizeof(char));
    //head
    sprintf(msg_head, "HTTP/1.1 WEB SERVER\r\n");
    sprintf(msg_head, "%sServer: Web Server\r\n",msg_head);
    sprintf(msg_head, "%sContent-Type:text/html\r\n",msg_head);
    //txt
    sprintf(msg_txt, "<html><meta charset=\"UTF-8\">");
    sprintf(msg_txt, "%s<head><title>WEB SERVER</title></head>",msg_txt);
    sprintf(msg_txt, "%s<body><h1>WEB SERVER</h1>",msg_txt);
    if ( strcmp(offset_dir,"/") != 0 )
    {
        getParentDir(buf,offset_dir);
        printf("buf = %s\n", buf);
        sprintf(msg_txt,"%s<p><a href=\"/\">根目录: /</a>&#160&#160<a href=\"%s\">父目录: %s</a></p>",
                msg_txt,buf,buf);
    }
    sprintf(msg_txt, "%s<p>----当前目录: %s</p>",msg_txt,offset_dir);
    sprintf(msg_txt,"%s<form action=\"rename.%s\" method=\"get\">", msg_txt,offset_dir);
    int len = strlen(offset_dir);
    if ( ( *(offset_dir+len-1) == '/') )
    {
        if (len == 1)
        {
            offset_dir = "\0";
        }
        else
        {
            *(offset_dir+len-1) = '\0';
        }
    }

    char  path[DIR_LENGTH];
    memset(path, 0, DIR_LENGTH*sizeof(char));
    strcpy(path,web_root);
    strcat(path,offset_dir);
    printf("当前磁盘目录: %s\n", path);
    printf("在服务器器中的偏移目录%s\n", offset_dir);

    //open dir
    if ( (dir = opendir(path))  ==  NULL )
    {
        printf("can't open %s", path);
        exit(1);
        //		sprintf(msg_txt, "%s<p>can't open %s</p>",msg_txt,path);
    }

    //tranvers dir
    num_dir = 0;
    num_reg = 0;
    //				   <form action="/html" method="get">
    //sprintf(msg_txt,"%s<form action=\"rename\" method=\"get\">", msg_txt);
    while ( (dirp = readdir(dir)) != NULL)
    {
        sprintf(buf,"%s/%s",path,dirp->d_name);
        if (stat(buf, &statbuf) == -1)
        {
            printf("Get stat on %s\n", buf);
            exit(1);
            //        	sprintf(msg_txt, "%s<p>can't get stat on %s</p>",msg_txt,path);
        }
        if ( S_ISREG(statbuf.st_mode) )
        {
            printf("%s\t\t%ld字节\t\t%s\n",dirp->d_name, statbuf.st_size, ctime(&statbuf.st_mtime));
            sprintf(msg_txt,"%s<p><a href=\"%s/%s\">%s</a>&#160&#160&#160&#160 %ld -字节&#160&#160%s",
                    msg_txt,offset_dir,dirp->d_name,dirp->d_name,statbuf.st_size,ctime(&statbuf.st_mtime));
            sprintf(msg_txt,"%s&#160&#160<a href=\"%s/%s\">下载</a>&#160&#160<a href=\"%s/%s.\">删除</a>",
                    msg_txt,offset_dir,dirp->d_name,offset_dir,dirp->d_name);
            sprintf(msg_txt,"%s&#160&#160<input type=\"text\"name=\"%s/%s\"style=\"width:50px\"/>",
                    msg_txt,offset_dir,dirp->d_name);
            sprintf(msg_txt,"%s<input type=\"submit\"value=\"更名\"style=\"width:50px\"/></p>",
                    msg_txt);//style=\"height:22px;width:50px\"
            num_reg++;
        }
        else
        {
            if ( strcmp(dirp->d_name,".")  && strcmp(dirp->d_name,"..") )
            {
                printf("%s\t\t文件夹\t\t%s\n",dirp->d_name,ctime(&statbuf.st_mtime));
                sprintf(msg_txt,"%s<p><a href=\"%s/%s\">%s</a>&#160&#160文件夹&#160&#160%s",
                        msg_txt,offset_dir,dirp->d_name,dirp->d_name,ctime(&statbuf.st_mtime));
                sprintf(msg_txt,"%s&#160&#160<a href=\"%s/%s\">打开</a>&#160&#160<a href= \"%s/%s.\">删除</a>",
                        msg_txt,offset_dir,dirp->d_name,offset_dir,dirp->d_name);
                sprintf(msg_txt,"%s&#160&#160<input type=\"text\"name=\"%s/%s\"style=\"width:50px\"/>",
                        msg_txt,offset_dir,dirp->d_name);
                sprintf(msg_txt,"%s<input type=\"submit\"value=\"更名\"style=\"width:50px\"/></p>",
                        msg_txt);
                num_dir++;
            }
        }
    }//while
    sprintf(msg_txt,"%s</form>",msg_txt);
    //close dir
    closedir(dir);
    printf("路径\"%s\"下有%d个目录,%d个文件!\n", path, num_dir, num_reg);
    sprintf(msg_txt, "%s<p>当前路径下有%d个目录,%d个文件!</p>",msg_txt,num_dir,num_reg);
    sprintf(msg_txt, "%s<form enctype=\"multipart/form-data\" action=\"/\" method=post>\n", msg_txt);
    sprintf(msg_txt, "%s<input name=\"uploadFile\" type=\"file\"><br> \n", msg_txt);
    sprintf(msg_txt, "%s<input type=\"submit\" value=\"提交\"><input type=reset></form> </body></html>", msg_txt);
    sprintf(msg_head,"%sContent-Length:%d\r\n\r\n",msg_head,(int) strlen(msg_txt));
    if (send(fd, msg_head, strlen(msg_head), 0) == -1)
    {
        perror("Send Head Fail --printDir\n");
        exit(1);
    }
    if (send(fd, msg_txt, strlen(msg_txt), 0) == -1)
    {
        perror("Send Txt Fail --printDir\n");
        exit(1);
    }
    return 0;
}
static int
_upload (const char *iRODSPath) {
    int status;
    rcComm_t *conn;
    rodsPathInp_t rodsPathInp;
    rErrMsg_t errMsg;
    char bufferPath[MAX_NAME_LEN];
    char destiRODSDir[MAX_NAME_LEN];

    status = getParentDir(iRODSPath, destiRODSDir);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "_upload: failed to get parent dir - %s", iRODSPath);
        return status;
    }

    status = _getBufferPath(iRODSPath, bufferPath);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "_upload: failed to get Buffered lazy upload file path - %s", iRODSPath);
        return status;
    }

    // set src path
    memset( &rodsPathInp, 0, sizeof( rodsPathInp_t ) );
    addSrcInPath( &rodsPathInp, bufferPath );
    status = parseLocalPath (&rodsPathInp.srcPath[0]);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "_upload: parseLocalPath error : %d", status);
        return status;
    }

    // set dest path
    rodsPathInp.destPath = ( rodsPath_t* )malloc( sizeof( rodsPath_t ) );
    memset( rodsPathInp.destPath, 0, sizeof( rodsPath_t ) );
    rstrcpy( rodsPathInp.destPath->inPath, destiRODSDir, MAX_NAME_LEN );
    status = parseRodsPath (rodsPathInp.destPath, LazyUploadRodsEnv);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "_upload: parseRodsPath error : %d", status);
        return status;
    }

    // Connect
    conn = rcConnect (LazyUploadRodsEnv->rodsHost, LazyUploadRodsEnv->rodsPort, LazyUploadRodsEnv->rodsUserName, LazyUploadRodsEnv->rodsZone, RECONN_TIMEOUT, &errMsg);
    if (conn == NULL) {
        rodsLog (LOG_DEBUG, "_upload: error occurred while connecting to irods");
        return -EPIPE;
    }

    // Login
    if (strcmp (LazyUploadRodsEnv->rodsUserName, PUBLIC_USER_NAME) != 0) { 
        status = clientLogin(conn);
        if (status != 0) {
            rodsLog (LOG_DEBUG, "_upload: ClientLogin error : %d", status);
            rcDisconnect(conn);
            return status;
        }
    }

    // upload Buffered file
    rodsLog (LOG_DEBUG, "_upload: upload %s", bufferPath);
    bool prev = LazyUploadRodsArgs->force;
    LazyUploadRodsArgs->force = True;
    status = putUtil (&conn, LazyUploadRodsEnv, LazyUploadRodsArgs, &rodsPathInp);
    LazyUploadRodsArgs->force = prev;
    rodsLog (LOG_DEBUG, "_upload: complete uploading %s -> %s", bufferPath, destiRODSDir);

    // Disconnect 
    rcDisconnect(conn);

    if(status < 0) {
        rodsLog (LOG_DEBUG, "_upload: putUtil error : %d", status);
        return status;
    }

    return 0;
}