示例#1
0
/**
 * @brief Get the plug-in name of the filename provided.
 *
 * @code
 * // return "toto".
 * utils::Module::getPluginName("/home/foo/bar/libtoto.so");
 * @endcode
 *
 * @param path The path of the file to convert;
 * @return The plug-in name;
 *
 * TODO function from ModuleManager
 */
static std::string TMPgetLibraryName(const boost::filesystem::path& file)
{
    namespace fs = boost::filesystem;
    std::string library;

#if BOOST_VERSION > 104500
    if (file.filename().string().compare(0, 3, "lib") == 0) {
        library.append(file.filename().string(), 3, std::string::npos);
    }
#else
    if (file.filename().compare(0, 3, "lib") == 0) {
        library.append(file.filename(), 3, std::string::npos);
    }
#endif

#ifdef BOOST_WINDOWS
    if (fs::extension(file) == ".dll") {
        library.assign(library, 0, library.size() - 4);
    }
#else
    if (fs::extension(file) == ".so") {
        library.assign(library, 0, library.size() - 3);
    }
#endif

    return library;
}
示例#2
0
文件: CryNode.cpp 项目: cryfs/cryfs
void CryNode::rename(const bf::path &to) {
  device()->callFsActionCallbacks();
  if (_parent == none) {
    //We are the root direcory.
    throw FuseErrnoException(EBUSY);
  }
  auto targetDirWithParent = _device->LoadDirBlobWithParent(to.parent_path());
  auto targetDir = std::move(targetDirWithParent.blob);
  auto targetDirParent = std::move(targetDirWithParent.parent);

  auto old = (*_parent)->GetChild(_key);
  if (old == boost::none) {
    throw FuseErrnoException(EIO);
  }
  fsblobstore::DirEntry oldEntry = *old; // Copying this (instead of only keeping the reference) is necessary, because the operations below (i.e. RenameChild()) might make a reference invalid.
  auto onOverwritten = [this] (const blockstore::Key &key) {
      device()->RemoveBlob(key);
  };
  _updateParentModificationTimestamp();
  if (targetDir->key() == (*_parent)->key()) {
    targetDir->RenameChild(oldEntry.key(), to.filename().native(), onOverwritten);
  } else {
    _updateTargetDirModificationTimestamp(*targetDir, std::move(targetDirParent));
    targetDir->AddOrOverwriteChild(to.filename().native(), oldEntry.key(), oldEntry.type(), oldEntry.mode(), oldEntry.uid(), oldEntry.gid(),
                                   oldEntry.lastAccessTime(), oldEntry.lastModificationTime(), onOverwritten);
    (*_parent)->RemoveChild(oldEntry.name());
    // targetDir is now the new parent for this node. Adapt to it, so we can call further operations on this node object.
    _parent = cpputils::to_unique_ptr(std::move(targetDir));
  }
}
示例#3
0
    inline std::string leaf(boost::filesystem::path const& p)
    {
#if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
        return p.filename().string();
#else
        return p.filename();
#endif
    }
示例#4
0
static std::string ToString(const boost::filesystem::path& p)
{
#if BOOST_HAS_FILESYSTEM_V3 == 1
    return p.filename().string();
#else
    return p.filename();
#endif
}
inline bool lib_path_equal(const boost::filesystem::path& lhs, const boost::filesystem::path& rhs) {
    // ./b2 may create symlinks. We assume that there are no two files with same names,
    // si if `lhs.filename() == rhs.filename()` then paths are same.
    const bool res = (lhs.filename() == rhs.filename() && lhs.is_absolute() && rhs.is_absolute());
    if (!res) {
        std::cerr << "lhs != rhs: " << lhs << " != " << rhs << '\n';
    }
    return res;
}
示例#6
0
uint64_t AssetStore::removeAsset(const boost::filesystem::path& assetPath) noexcept
{
	BOOST_LOG_SEV(bithorded::storeLog, info) << "removing asset " << assetPath.filename();
	auto tigerId = _index.removeAsset(assetPath.filename().native());
	if (!tigerId.empty()) {
		unlink(_tigerFolder / tigerId);
	}
	return remove_file_recursive(assetPath);
}
//-------------------------------------------------------
const EntityIdAndHandlerId
Filename2EntityIdAndHandlerId(const boost::filesystem::path & filename)
{
    if (!filename.has_filename())
    {
        throw Safir::Dob::Typesystem::IllegalValueException
            (L"Filename2EntityAndHandler: Could not decompose filename : " +
            Safir::Dob::Typesystem::Utilities::ToWstring(filename.string()),__WFILE__,__LINE__);
    }

#if defined (BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION == 3
    const std::string leaf = filename.filename().string();
#else
    const std::string leaf = filename.filename();
#endif

    size_t separatorIndex = leaf.find('@');
    if (separatorIndex == std::string::npos)
    {
        throw Safir::Dob::Typesystem::IllegalValueException
            (L"Filename2EntityAndHandler: Could not decompose filename : " +
            Safir::Dob::Typesystem::Utilities::ToWstring(filename.string()),__WFILE__,__LINE__);
    }

    const std::string typeName = leaf.substr(0,separatorIndex);

    size_t secondSeparatorIndex = leaf.find('@',separatorIndex+1);

    if (secondSeparatorIndex == std::string::npos)
    {
        throw Safir::Dob::Typesystem::IllegalValueException
            (L"Filename2EntityAndHandler: Could not decompose filename : " +
            Safir::Dob::Typesystem::Utilities::ToWstring(filename.string()),__WFILE__,__LINE__);
    }
    const std::string instance = leaf.substr(separatorIndex + 1,secondSeparatorIndex - separatorIndex - 1);

    size_t extIndex = leaf.find('.',secondSeparatorIndex);

    if (extIndex == std::string::npos)
    {
        throw Safir::Dob::Typesystem::IllegalValueException
            (L"Filename2EntityAndHandler: Could not decompose filename : " +
            Safir::Dob::Typesystem::Utilities::ToWstring(filename.string()),__WFILE__,__LINE__);
    }
    const std::string handler = leaf.substr(secondSeparatorIndex + 1,extIndex - secondSeparatorIndex - 1);

    return std::make_pair(Safir::Dob::Typesystem::EntityId
        (Safir::Dob::Typesystem::Operations::GetTypeId(Safir::Dob::Typesystem::Utilities::ToWstring(typeName)),
        Safir::Dob::Typesystem::InstanceId( boost::lexical_cast<Safir::Dob::Typesystem::Int64>(instance))),
        Safir::Dob::Typesystem::HandlerId(boost::lexical_cast<Safir::Dob::Typesystem::Int64>(handler)));
}
示例#8
0
inline Status listInAbsoluteDirectory(const fs::path& path,
                                      std::vector<std::string>& results,
                                      GlobLimits limits) {
  if (path.filename() == "*" && !pathExists(path.parent_path())) {
    return Status(1, "Directory not found: " + path.parent_path().string());
  }

  if (path.filename() == "*" && !isDirectory(path.parent_path())) {
    return Status(1, "Path not a directory: " + path.parent_path().string());
  }

  genGlobs(path.string(), results, limits);
  return Status(0, "OK");
}
示例#9
0
ProcessResults processFile(fs::path file, Params& params)
{
    ProcessResults result;
    Pex::Binary pex;
    try
    {
        Pex::FileReader reader(file.string());
        reader.read(pex);
    }
    catch(std::exception& ex)
    {
        result.push_back(boost::str(boost::format("ERROR: %1% : %2%") % file.string() % ex.what()));
        return result;
    }
    if (params.outputAssembly)
    {
        fs::path asmFile = params.assemblyDir / file.filename().replace_extension(".pas");
        try
        {
            std::ofstream asmStream(asmFile.string());
            Decompiler::AsmCoder asmCoder(new Decompiler::StreamWriter(asmStream));

            asmCoder.code(pex);
            result.push_back(boost::str(boost::format("%1% dissassembled to %2%") % file.string() % asmFile.string()));
        }
        catch(std::exception& ex)
        {
            result.push_back(boost::str(boost::format("ERROR: %1% : %2%") % file.string() % ex.what()));
            fs::remove(asmFile);
        }
    }

    fs::path pscFile = params.papyrusDir / file.filename().replace_extension(".psc");
    try
    {
        std::ofstream pscStream(pscFile.string());
        Decompiler::PscCoder pscCoder(new Decompiler::StreamWriter(pscStream));

        pscCoder.outputAsmComment(params.outputComment).code(pex);
        result.push_back(boost::str(boost::format("%1% decompiled to %2%") % file.string() % pscFile.string()));
    }
    catch(std::exception& ex)
    {
        result.push_back(boost::str(boost::format("ERROR: %1% : %2%") % file.string() % ex.what()));
        fs::remove(pscFile);
    }
    return result;

}
示例#10
0
 // FSWatcher::Watcher::updated
 virtual void updated(const boost::filesystem::path& filePath) {
     string fstr = filePath.filename().string();
     if (!boost::algorithm::ends_with(fstr, ".json") ||
         boost::algorithm::starts_with(fstr, "."))
         return;
     readConfig(filePath.string());
 }
static std::string
loadFile (boost::property_tree::ptree &config,
          const boost::filesystem::path &file)
{
  boost::filesystem::path extension = file.extension();
  boost::filesystem::path extension2 = file.stem().extension();
  std::string fileName = file.filename().string();
  boost::property_tree::ptree readConfig;

  if (extension2.string() == ".conf") {
    if (extension.string() == ".json") {
      boost::property_tree::read_json (file.string(), readConfig);
    } else if (extension.string() == ".info") {
      boost::property_tree::read_info (file.string(), readConfig);
    } else if (extension.string() == ".ini") {
      boost::property_tree::read_ini (file.string(), readConfig);
    } else if (extension.string() == ".xml") {
      boost::property_tree::read_xml (file.string(), readConfig);
    } else {
      throw ParseException ("Unknonw file format");
    }
  } else {
    throw ParseException ("Unknonw file format");
  }

  mergePropertyTrees (config, readConfig);

  config.put ("configPath", file.parent_path().string() );

  fileName = fileName.substr (0, fileName.size() - extension.string().size() );
  fileName = fileName.substr (0, fileName.size() - extension2.string().size() );

  return fileName;
}
示例#12
0
文件: CryDevice.cpp 项目: cryfs/cryfs
optional<unique_ref<fspp::Node>> CryDevice::Load(const bf::path &path) {
  // TODO Split into smaller functions
  ASSERT(path.is_absolute(), "Non absolute path given");

  callFsActionCallbacks();

  if (path.parent_path().empty()) {
    //We are asked to load the base directory '/'.
    return optional<unique_ref<fspp::Node>>(make_unique_ref<CryDir>(this, none, none, _rootKey));
  }

  auto parentWithGrandparent = LoadDirBlobWithParent(path.parent_path());
  auto parent = std::move(parentWithGrandparent.blob);
  auto grandparent = std::move(parentWithGrandparent.parent);

  auto optEntry = parent->GetChild(path.filename().native());
  if (optEntry == boost::none) {
    return boost::none;
  }
  const auto &entry = *optEntry;

  switch(entry.type()) {
    case fspp::Dir::EntryType::DIR:
      return optional<unique_ref<fspp::Node>>(make_unique_ref<CryDir>(this, std::move(parent), std::move(grandparent), entry.key()));
    case fspp::Dir::EntryType::FILE:
      return optional<unique_ref<fspp::Node>>(make_unique_ref<CryFile>(this, std::move(parent), std::move(grandparent), entry.key()));
    case  fspp::Dir::EntryType::SYMLINK:
	  return optional<unique_ref<fspp::Node>>(make_unique_ref<CrySymlink>(this, std::move(parent), std::move(grandparent), entry.key()));
  }
  ASSERT(false, "Switch/case not exhaustive");
}
示例#13
0
void write_pic(const fs::path& path, const char* buff, const int length)
{
    auto curname = path.filename().replace_extension();
    auto rawname = path;
    rawname.append(curname.c_str());
    auto pngname = rawname;
    pngname += ".png";
    auto mskname = rawname;
    mskname += ".msk";
    auto lyrname = rawname;
    lyrname += ".lyr";

    YKGHDR* ghdr = (YKGHDR*)buff;

    if (ghdr->rgb_length)
    {
        write_file(pngname, buff + ghdr->rgb_offset, ghdr->rgb_length);
    }
    if (ghdr->msk_length)
    {
        write_file(mskname, buff + ghdr->msk_offset, ghdr->msk_length);
    }
    if (ghdr->__lyr_len)
    {
        write_file(lyrname, buff + ghdr->__lyr_off, ghdr->__lyr_len);
    }


    (void)length; // not using this variable.

    return;
}
示例#14
0
void move_file(const char *t_path,fs::path p ) {
    try {
        fs::rename(p, fs::path(t_path)/p.filename());
    } catch(fs::filesystem_error &e) {
        std::cerr << e.what() << std::endl;
    }
}
示例#15
0
void writeAttachment( const ::boost::filesystem::path& filePath, const ::fwAtoms::Object::sptr atom )
{
    const ::boost::filesystem::path folderPath = filePath.parent_path();
    const ::boost::filesystem::path filename   = filePath.filename();
    std::string extension                      = ::boost::filesystem::extension(filePath);

    // Write atom
    ::fwZip::IWriteArchive::sptr writeArchive;
    ::fwAtomsBoostIO::FormatType format;
    ::boost::filesystem::path archiveRootName;

    if ( extension == ".json" )
    {
        writeArchive    = ::fwZip::WriteDirArchive::New(folderPath.string());
        archiveRootName = filename;
        format          = ::fwAtomsBoostIO::JSON;
    }
    else if ( extension == ".jsonz" )
    {
        if ( ::boost::filesystem::exists( filePath ) )
        {
            ::boost::filesystem::remove( filePath );
        }
        writeArchive    = ::fwZip::WriteZipArchive::New(filePath.string());
        archiveRootName = "root.json";
        format          = ::fwAtomsBoostIO::JSON;
    }
    else
    {
        FW_RAISE( "This file extension '" << extension << "' is not managed" );
    }

    ::fwAtomsBoostIO::Writer(atom).write( writeArchive, archiveRootName, format );
    writeArchive.reset();
}
示例#16
0
int FilesystemImpl::createAndOpenFile(const bf::path &path, mode_t mode, uid_t uid, gid_t gid) {
  PROFILE(_createAndOpenFileNanosec);
  auto dir = LoadDir(path.parent_path());
  PROFILE(_createAndOpenFileNanosec_withoutLoading);
  auto file = dir->createAndOpenFile(path.filename().native(), mode, uid, gid);
  return _open_files.open(std::move(file));
}
    boost::optional<boost::filesystem::path>
    runMetro( std::string & mod_proj_file, bool is_logging, boost::filesystem::path & debug_log_file_name, std::ofstream & logging_file)
    {
        std::stringstream cmd1, cmd2;
        std::string wine_proj_path = "\"" + wine_temp_dir + "\\\\" + worker_dir.filename().string() + "\\\\" + mod_proj_file + "\"";
        std::string metro_log_path = "\"" + wine_temp_dir + "\\\\" + worker_dir.filename().string() + "\\\\" + cp_metro_log_name + "\"";
        //Call the model
        cmd1 << "timeout --kill-after=20m 19m  " << wine_cmd << " " << geo_cmd << " --Reset --Save " << wine_proj_path ;
        if (is_logging) cmd1 << " >> \"" << debug_log_file_name.c_str() << "\" 2>&1";
        if (is_logging) logging_file << "Running: " << cmd1.str() << std::endl;
        if (is_logging)  logging_file.close();
        int i1 = system(cmd1.str().c_str());
        if (is_logging) logging_file.open(debug_log_file_name.c_str(), std::ios_base::app);
        if (!logging_file.is_open()) is_logging = false;

        cmd2 << "timeout --kill-after=20m 19m  " << wine_cmd << " " << geo_cmd << " --Run --Save --LogSettings " << metro_log_path << " " << wine_proj_path ;
        if (is_logging) cmd2 << " >> \"" << debug_log_file_name.c_str() << "\" 2>&1";
        if (is_logging) logging_file << "Running: " << cmd2.str() << std::endl;
        if (is_logging) logging_file.close();
        int i2 = system(cmd2.str().c_str());
        if (is_logging) logging_file.open(debug_log_file_name.c_str(), std::ios_base::app);
        if (!logging_file.is_open()) is_logging = false;

        boost::filesystem::path output_map = worker_dir / "Log" / "Land_use" / "Land use map_2000-Jan-01 00_00_00.rst";
        if (boost::filesystem::exists(output_map))
        {
            return output_map;
        }
        else
        {
            return boost::none;
        }
    }
示例#18
0
void copy_file(const char *t_path,fs::path p ) {
    try {
        fs::copy_file(p, fs::path(t_path)/p.filename(),fs::copy_option::none);
    } catch(fs::filesystem_error &e) {
        std::cerr << e.what() << std::endl;
    }
}
示例#19
0
std::size_t Cooker::embedFile_(const bf::path& path, DataSectionBlob& name, DataSectionCryptoPack& file, char* ptr )
{
	file.size = (DWORD) bf::file_size(path);
	cout << __FUNCTION__ << " File size: " << file.size << endl;
	if (file.size == 0)
		return 0;
	
	char* p = ptr;
	name.offset = ((DWORD)p - (DWORD)cooked_.get());
	
	std::string filename = path.filename();
	name.size = (DWORD) filename.size() + 1;
	memcpy(ptr, filename.c_str(), name.size);
	p += name.size;
	
	file.offset = ((DWORD)p - (DWORD)cooked_.get());
	bf::ifstream fs;
	fs.open(path, ios::in | ios::binary);
	
	fs.read(p, file.size);
	std::size_t n = fs.gcount();
	cout << __FUNCTION__ << " read: " << n << endl;
	p += file.size;
	
	std::size_t ret = ((DWORD)p - (DWORD)ptr);
	cout << __FUNCTION__ << " size: " << ret << endl;
	
	return ret;
}
示例#20
0
boost::filesystem::path find_executable_in_path(
    const boost::filesystem::path &executable) {
  try {
    if (executable != executable.filename())
      BOOST_THROW_EXCEPTION(
          non_basename_executable_error()
          << non_basename_executable_error::executable(executable));

    const boost::filesystem::path exts[] = {"", ".exe", ".com", ".bat"};
    for (const auto &ext : exts) {
      wchar_t buf[MAX_PATH];
      LPWSTR dummy;
      const DWORD size = ::SearchPathW(nullptr, executable.c_str(), ext.c_str(),
                                       MAX_PATH, buf, &dummy);
      BOOST_ASSERT(size < MAX_PATH);
      if (size > 0) return buf;
    }

    BOOST_THROW_EXCEPTION(
        no_executable_in_path_error()
        << no_executable_in_path_error::executable(executable));
  } catch (find_executable_in_path_error &) {
    throw;
  } catch (std::exception &) {
    BOOST_THROW_EXCEPTION(
        find_executable_in_path_error()
        << find_executable_in_path_error::executable(executable)
        << enable_nested_current());
  }
}
示例#21
0
文件: Engine.cpp 项目: Yadoms/yadoms
   boost::shared_ptr<device::IDevice> CEngine::createDevice(const boost::filesystem::path& devicePath) const
   {
      const std::string filename = devicePath.filename().string();

      // OWFS device name format, see http://owfs.org/uploads/owfs.1.html#sect30
      // OWFS must be configured to use the default format ff.iiiiiiiiiiii, with :
      // - ff : family (1 byte)
      // - iiiiiiiiiiii : id (6 bytes)

      // Retrieve family from the first 2 chars
      EOneWireFamily family = ToFamily(filename.substr(0, 2));

      // Device Id (6 chars after '.')
      std::string id = filename.substr(3, 6 * 2);
      // OWFS give us the device ID inverted, so reinvert it
      for (int i = 0; i < 6 / 2; i++)
      {
         int left_position = i * 2;          // Point on first byte
         int right_position = (6 - i - 1) * 2;   // Point on last byte
         char c = id[left_position]; id[left_position] = id[right_position]; id[right_position] = c;
         c = id[left_position + 1]; id[left_position + 1] = id[right_position + 1]; id[right_position + 1] = c;
      }

      return createDevice(family, id, devicePath);
   }
// removes trailing slashes, uses make_preferred
void standardizePath(bfs::path& inPath)
{
    string pathStr = inPath.string();

    inPath.make_preferred();
    if (inPath.filename() == ".") inPath.remove_filename();
}
示例#23
0
CachedAsset::Ptr CachedAsset::create( GrandCentralDispatch& gcd, const boost::filesystem::path& path, uint64_t size ) {
	auto meta = store::createAssetMeta(path, store::V2CACHE, size, store::DEFAULT_HASH_LEVELS_SKIPPED, size);

	auto ptr = boost::make_shared<CachedAsset>(gcd, path.filename().native(), meta.hashStore, meta.tail);
	ptr->status.change()->set_status(bithorde::SUCCESS);
	return ptr;
}
示例#24
0
::fwAtoms::Object::sptr readAttachment( const ::boost::filesystem::path& filePath )
{
    const ::boost::filesystem::path folderPath = filePath.parent_path();
    const ::boost::filesystem::path filename   = filePath.filename();
    const std::string extension                = ::boost::filesystem::extension(filePath);

    ::fwZip::IReadArchive::sptr readArchive;
    ::boost::filesystem::path archiveRootName;
    ::fwAtomsBoostIO::FormatType format = ::fwAtomsBoostIO::UNSPECIFIED;

    if ( extension == ".json" )
    {
        readArchive     = ::fwZip::ReadDirArchive::New(folderPath.string());
        archiveRootName = filename;
        format          = ::fwAtomsBoostIO::JSON;
    }
    else if ( extension == ".jsonz" )
    {
        readArchive     = ::fwZip::ReadZipArchive::New(filePath.string());
        archiveRootName = "root.json";
        format          = ::fwAtomsBoostIO::JSON;
    }
    else
    {
        FW_RAISE( "This file extension '" << extension << "' is not managed" );
    }

    ::fwAtomsBoostIO::Reader reader;
    ::fwAtoms::Object::sptr atom =
        ::fwAtoms::Object::dynamicCast(reader.read(readArchive, archiveRootName, format));

    return atom;
}
     BOOST_FOREACH(const boost::filesystem::path& fname,filesFound)
     {
         boost::smatch what;
-        std::string leaf = fname.leaf();
+        std::string leaf = fname.filename().string();
 
         if (!boost::regex_match(leaf, what, re)) 
             continue;
示例#26
0
inline Status listInAbsoluteDirectory(const fs::path& path,
                                      std::vector<std::string>& results,
                                      GlobLimits limits) {
  try {
    if (path.filename() == "*" && !fs::exists(path.parent_path())) {
      return Status(1, "Directory not found: " + path.parent_path().string());
    }

    if (path.filename() == "*" && !fs::is_directory(path.parent_path())) {
      return Status(1, "Path not a directory: " + path.parent_path().string());
    }
  } catch (const fs::filesystem_error& e) {
    return Status(1, e.what());
  }
  genGlobs(path.string(), results, limits);
  return Status(0, "OK");
}
示例#27
0
文件: util.cpp 项目: apprb/i2pd
    void CopyDir(const boost::filesystem::path& src, const boost::filesystem::path& dest)
    {
        namespace bfs = boost::filesystem;

        bfs::create_directory(dest);
        
        for(bfs::directory_iterator file(src); file != bfs::directory_iterator(); ++file) {
            const bfs::path current(file->path());
            if(bfs::is_directory(current))
                CopyDir(current, dest / current.filename());
            else
                bfs::copy_file(
                    current, dest / current.filename(),
                    bfs::copy_option::overwrite_if_exists
                );
        }
    }
示例#28
0
/**
 * muti_track_name_helper
 *
 * little helper to construct file names for multiple track files.
 */
boost::filesystem::path muti_track_name_helper(boost::filesystem::path outpath, int n) {
	std::ostringstream prefix;
	prefix << "track ";
	prefix << n+1;
	prefix << " - ";
	boost::filesystem::path trackOutPath = outpath.parent_path() / (prefix.str() + outpath.filename().string());
	return trackOutPath;
}
示例#29
0
bool isConfigPath(const fs::path& file) {
    const string fstr = file.filename().string();
    if (boost::algorithm::ends_with(fstr, ".conf") &&
        !boost::algorithm::starts_with(fstr, ".")) {
        return true;
    }

    return false;
}
示例#30
-1
		void parser_filepath(const vrString& filePath, vrString& strParentPath, vrString& strFileName, vrString& strStem, vrString& strExtension)
		{
			const fs::path p1 = filePath;
			strParentPath = p1.parent_path().string();
			strFileName = p1.filename().string();
			strExtension = p1.extension().string();
			strStem = p1.stem().string();
		}