示例#1
0
boost::filesystem::path naive_uncomplete(boost::filesystem::path const path, 
    boost::filesystem::path const base) {
    if (path.has_root_path()){
        if (path.root_path() != base.root_path()) {
            return path;
        } else {
            return naive_uncomplete(path.relative_path(), base.relative_path());
        }
    } else {
        if (base.has_root_path()) {
            throw "cannot uncomplete a path relative path from a rooted base";
        } else {
            typedef boost::filesystem::path::const_iterator path_iterator;
            path_iterator path_it = path.begin();
            path_iterator base_it = base.begin();
            while ( path_it != path.end() && base_it != base.end() ) {
                if (*path_it != *base_it) break;
                ++path_it; ++base_it;
            }
            boost::filesystem::path result;
            for (; base_it != base.end(); ++base_it) {
                result /= "..";
            }
            for (; path_it != path.end(); ++path_it) {
                result /= *path_it;
            }
            return result;
        }
    }
}
示例#2
0
/**
 * Iterate over a directory.
 *
 * @param dir Directory to iterate over.
 */
void Dir_Parse::iterate(fs::path dir) {
	fs::directory_iterator end_iter;
	vector<fs::path> dirs;

	#ifdef DEBUG
	cout << endl << "==== " << string(dir.relative_path().c_str()).substr(cut_path) << " ===="  << endl;
	#endif

	for (fs::directory_iterator dir_itr(dir); dir_itr != end_iter; ++dir_itr) {
		try {
			// Ignore hidden directories.
			if (dir_itr->path().filename().c_str()[0] != '.') {
				if (fs::is_directory(dir_itr->status())) {
					// Directory
					#ifdef DEBUG
					cout << dir_itr->path().filename() << " - Directory" << endl;
					#endif

					dirs.push_back(dir_itr->path());
				} else if (fs::is_regular_file(dir_itr->status())) {
					// File
					vector<string> datasheet;
					vector<string> tags = get_tags(dir_itr->path());

					datasheet.push_back(string(dir_itr->path().c_str()));
					datasheet.push_back(boost::algorithm::join(tags, ","));

					datasheets.push_back(datasheet);

					#ifdef DEBUG
					cout << trim_path(dir_itr->path()) << endl;
					cout << dir_itr->path().filename() << " - File" << endl;

					for (size_t i = 0; i < tags.size(); ++i) {
						cout << tags[i];

						if (i < tags.size() - 1) {
							cout << ", ";
						} else {
							cout << endl << endl;
						}
					}
					#endif
				}
				#ifdef DEBUG
				else {
					// Other
					cout << dir_itr->path().filename() << ": WTF is this?!" << endl;
				}
				#endif
			}
		} catch (const exception &e) {
			cout << dir_itr->path().filename() << ": " << e.what() << endl;
		}
	}

	for (size_t i = 0; i < dirs.size(); ++i) {
		iterate(dirs[i]);
	}
}
示例#3
0
文件: CryDevice.cpp 项目: cryfs/cryfs
CryDevice::BlobWithParent CryDevice::LoadBlobWithParent(const bf::path &path) {
  optional<unique_ref<DirBlobRef>> parentBlob = none;
  optional<unique_ref<FsBlobRef>> currentBlobOpt = _fsBlobStore->load(_rootKey);
  if (currentBlobOpt == none) {
    LOG(ERROR) << "Could not load root blob. Is the base directory accessible?";
    throw FuseErrnoException(EIO);
  }
  unique_ref<FsBlobRef> currentBlob = std::move(*currentBlobOpt);

  for (const bf::path &component : path.relative_path()) {
    auto currentDir = dynamic_pointer_move<DirBlobRef>(currentBlob);
    if (currentDir == none) {
      throw FuseErrnoException(ENOTDIR); // Path component is not a dir
    }

    auto childOpt = (*currentDir)->GetChild(component.c_str());
    if (childOpt == boost::none) {
      throw FuseErrnoException(ENOENT); // Child entry in directory not found
    }
    Key childKey = childOpt->key();
    auto nextBlob = _fsBlobStore->load(childKey);
    if (nextBlob == none) {
      throw FuseErrnoException(ENOENT); // Blob for directory entry not found
    }
    parentBlob = std::move(*currentDir);
    currentBlob = std::move(*nextBlob);
  }

  return BlobWithParent{std::move(currentBlob), std::move(parentBlob)};

  //TODO (I think this is resolved, but I should test it)
  //     Running the python script, waiting for "Create files in sequential order...", then going into dir ~/tmp/cryfs-mount-.../Bonnie.../ and calling "ls"
  //     crashes cryfs with a sigsegv.
  //     Possible reason: Many parallel changes to a directory blob are a race condition. Need something like ParallelAccessStore!
}
示例#4
0
 void
 TeaSafe::removeDeletedParentFromCache(boost::filesystem::path const &path)
 {
     auto it(m_folderCache.find(path.relative_path().string()));
     if (it != m_folderCache.end()) {
         m_folderCache.erase(it);
     }
 }
示例#5
0
 boost::filesystem::path MultiresImagePlugin::MakePathRelative(boost::filesystem::path path, boost::filesystem::path base)
 {
   // Borrowed from: https://svn.boost.org/trac/boost/ticket/1976#comment:2
   if (path.has_root_path())
   {
     if (path.root_path() != base.root_path())
     {
       return path;
     }
     else
     {
       return MakePathRelative(path.relative_path(), base.relative_path());
     }
   }
   else
   {
     if (base.has_root_path())
     {
       ROS_WARN("Cannot uncomplete a path relative path from a rooted base.");
       return path;
     }
     else
     {
       typedef boost::filesystem::path::const_iterator path_iterator;
       path_iterator path_it = path.begin();
       path_iterator base_it = base.begin();
       while (path_it != path.end() && base_it != base.end())
       {
         if (*path_it != *base_it)
           break;
         ++path_it;
         ++base_it;
       }
       boost::filesystem::path result;
       for (; base_it != base.end(); ++base_it)
       {
         result /= "..";
       }
       for (; path_it != path.end(); ++path_it)
       {
         result /= *path_it;
       }
       return result;
     }
   }
 }
示例#6
0
/**
 * Function to return list of images in a directory (searched recursively).
 * The output paths are w.r.t. the path imgsDir
 */
void genImgsList(const fs::path& imgsDir, vector<fs::path>& list) {
  if(!fs::exists(imgsDir) || !fs::is_directory(imgsDir)) return;
  vector<string> imgsExts = {".jpg", ".png", ".jpeg", ".JPEG", ".PNG", ".JPG"};

  fs::recursive_directory_iterator it(imgsDir);
  fs::recursive_directory_iterator endit;
  while(it != endit) {
    if(fs::is_regular_file(*it) && 
        find(imgsExts.begin(), imgsExts.end(), 
          it->path().extension()) != imgsExts.end())
      // write out paths but clip out the initial relative path from current dir 
      list.push_back(fs::path(it->path().relative_path().string().
            substr(imgsDir.relative_path().string().length())));
    ++it;
  }
  LOG(INFO) << "Found " << list.size() << " image file(s) in " << imgsDir;
}
SUBSHADERTYPE AssetManager::GetSubShaderTypeFromFile(boost::filesystem::path path)
{
  std::string subshaderfile = path.relative_path().stem().string();
  subshaderfile = subshaderfile.substr(subshaderfile.find("_") + 1);

  std::transform(subshaderfile.begin(), subshaderfile.end(), subshaderfile.begin(), ::tolower);

  SUBSHADERTYPE sstype;
  if (subshaderfile == VSfilstr)
    sstype = VERTEX_SHADER;
  else if (subshaderfile == PSfilstr)
    sstype = PIXEL_SHADER;
  else if (subshaderfile == CSfilstr)
	sstype = COMPUTE_SHADER;
  else if (subshaderfile == GSfilstr)
	sstype = GEOMETRY_SHADER;

  return sstype;
}
示例#8
0
    void
    CoreFS::removeFolderFromCache(::boost::filesystem::path const &path)
    {

        auto strPath = path.relative_path().string();
        // need to reset root path if root, otherwise
        // we'll continue to use 'cached' version
        if(strPath == "/") {
            removeAllChildFoldersToo(path, m_rootFolder);
            m_rootFolder = std::make_shared<CompoundFolder>(m_io, m_io->rootBlock, "root");
            return;
        }

        // else belongs to cache
        auto it(m_folderCache.find(strPath));
        if (it != m_folderCache.end()) {
            removeAllChildFoldersToo(path, it->second);
            m_folderCache.erase(it);
        }
    }