Ejemplo n.º 1
0
bool
filesystem::mount( const boost::filesystem::path& filepath )
{
    db_.reset( new sqlite() );

    if ( db_->open( filepath.c_str() ) ) {

        filename_ = filepath.string();

        if ( internal::fs::mount( *db_, format_version_ ) ) {

            db_->set_fs_format_version( format_version_ );

            if ( format_version_ >= 3 ) {
                adfs::stmt sql( *db_ );
                sql.exec( "PRAGMA FOREIGN_KEYS = ON" );
            }

            return true;
        }
    }

    db_.reset();
    return false;
}
Ejemplo n.º 2
0
  void Scan(const boost::filesystem::path & path) {
    
    if(args.verbose)
      printf("scanning %s\n", path.c_str());
    
    if(!boost::filesystem::exists(path))
	throw OpenDirException();
      
    if(!boost::filesystem::is_directory(path))
      throw OpenDirException();
    
    // dont parse SVN
    if(path.has_extension() && (strcasecmp(path.extension().c_str(), ".svn")==0))
      return;
    
    boost::filesystem::directory_iterator end;
    for( boost::filesystem::directory_iterator itor = boost::filesystem::directory_iterator( path ); itor != end; itor++)
      if(boost::filesystem::is_regular_file( itor->status() ))
	if( !itor->path().has_extension() || ((strcasecmp(itor->path().extension().c_str(), ".h")==0) || (strcasecmp(itor->path().extension().c_str(), ".hpp")==0)) )
	  Add( itor->path().string() );
    
    if( boost::filesystem::is_symlink(path) )
      return; // FIXME: better way to deal with gphoto's recursive symlinks?
      
    for( boost::filesystem::directory_iterator itor = boost::filesystem::directory_iterator( path ); itor != end; itor++)  
      if(boost::filesystem::is_directory( itor->status() ))
	  Scan( itor->path() );
  }
Ejemplo n.º 3
0
void RandomAccessFile::open(const boost::filesystem::path& path, RandomAccessFile::Mode mode, uint64_t size)
{
	int m;
	switch (mode) {
		case READ: m = O_RDONLY; break;
		case WRITE: m = O_WRONLY|O_CREAT; break;
		case READWRITE: m = O_RDWR|O_CREAT; break;
		default: throw std::ios_base::failure("Unknown open-mode");
	}
	_size = fs::exists(path) ? fs::file_size(path) : 0;

	if (_size != size) {
		if (size == 0) {
			size = _size;
		} else if (_size != 0) {
			ostringstream buf;
			buf << path << " exists with mismatching size, (" << size << " : " << fs::file_size(path) << ")";
			throw bsys::system_error(bsys::errc::make_error_code(bsys::errc::file_exists), buf.str());
		}
	}

	_fd = ::open(path.c_str(), m, S_IRUSR|S_IWUSR);
	if (_fd < 0) {
		throw bsys::system_error(bsys::errc::make_error_code(static_cast<bsys::errc::errc_t>(errno)), "Failed opening "+path.string());
	} else if ((_size == 0) && (ftruncate(_fd, size) == -1)) {
		::close(_fd);
		ostringstream buf;
		buf << "Failed truncating " << path.string() << " to " << size;
		throw bsys::system_error(bsys::errc::make_error_code(static_cast<bsys::errc::errc_t>(errno)), buf.str());
	}
	_path = path;
	_size = size;
}
Ejemplo n.º 4
0
int DownloadFile(std::string url, boost::filesystem::path target_file_path)
{
    int err = 0;

    printf("bootstrap: Downloading blockchain from %s. \n", url.c_str());

    CURL *curlHandle = curl_easy_init();
    curl_easy_setopt(curlHandle, CURLOPT_URL, url.c_str());
    curl_easy_setopt(curlHandle, CURLOPT_NOPROGRESS, 1L);
    curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curlHandle, CURLOPT_FOLLOWLOCATION, 1L);

    FILE *file = fopen(target_file_path.c_str(), "wb");
    if(file)
    {
        curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, file);
        CURLcode curl_err = curl_easy_perform(curlHandle);
        if (curl_err != CURLE_OK)
            printf("bootstrap: Error downloading from %s. Error: %s.\n", url.c_str(), curl_easy_strerror(curl_err));
        fclose(file);
        err = (int)curl_err;
    }
    else
    {
        printf("bootstrap: Download error: Unable to open output file for writing: %s.\n", target_file_path.c_str());
        err = -1;
    }

    curl_easy_cleanup(curlHandle);

    return err;
}
Ejemplo n.º 5
0
bool
touch(const bfs::path& path)
{
    if (pathExists(path)) {
        return (utimes(path.c_str(), NULL) == 0);
    }

    if (!isDirectory(path.parent_path())) {
        return false;
    }

    int fd = open(path.c_str(), O_EXCL | O_CREAT | O_WRONLY, 0644);
    if (fd < 0) return false;
    close(fd);

    return true;
}
Ejemplo n.º 6
0
int partition_parse(int **declarations,
										boost::filesystem::path input_filename,
										boost::filesystem::path functions_filename,
										boost::filesystem::path config_filename,
										int not_sc_flag)
{
	
	FILE *IN = safe_fopen_read(input_filename);
	
	int retval = partitionParse(declarations, IN,
															const_cast<char *> (functions_filename.c_str()),
															const_cast<char *> (config_filename.c_str()),
															not_sc_flag); // the 0 means not self conjugate.
	fclose(IN);
	
	return retval;
}
KillerImpl::Options readOptions(const boost::filesystem::path &path)
{
    boost::property_tree::ptree ptree;
    boost::property_tree::read_json(path.c_str(), ptree);
    KillerImpl::Options options;
    bunsan::config::input_archive<boost::property_tree::ptree>::load_from_ptree(options, ptree);
    return options;
}
Ejemplo n.º 8
0
std::shared_ptr<rett> createAny(const boost::filesystem::path & libpath, const std::string & methodName)
{
#ifdef VCMI_ANDROID
	// android currently doesn't support loading libs dynamically, so the access to the known libraries
	// is possible only via specializations of this template
	throw std::runtime_error("Could not resolve ai library " + libpath.generic_string());
#else
	typedef void(* TGetAIFun)(std::shared_ptr<rett> &);
	typedef void(* TGetNameFun)(char *);

	char temp[150];

	TGetAIFun getAI = nullptr;
	TGetNameFun getName = nullptr;

#ifdef VCMI_WINDOWS
	HMODULE dll = LoadLibraryW(libpath.c_str());
	if (dll)
	{
		getName = (TGetNameFun)GetProcAddress(dll, "GetAiName");
		getAI = (TGetAIFun)GetProcAddress(dll, methodName.c_str());
	}
#else // !VCMI_WINDOWS
	void *dll = dlopen(libpath.string().c_str(), RTLD_LOCAL | RTLD_LAZY);
	if (dll)
	{
		getName = (TGetNameFun)dlsym(dll, "GetAiName");
		getAI = (TGetAIFun)dlsym(dll, methodName.c_str());
	}
#endif // VCMI_WINDOWS

	if (!dll)
	{
		logGlobal->error("Cannot open dynamic library (%s). Throwing...", libpath.string());
		throw std::runtime_error("Cannot open dynamic library");
	}
	else if(!getName || !getAI)
	{
		logGlobal->error("%s does not export method %s", libpath.string(), methodName);
#ifdef VCMI_WINDOWS
		FreeLibrary(dll);
#else
		dlclose(dll);
#endif
		throw std::runtime_error("Cannot find method " + methodName);
	}

	getName(temp);
	logGlobal->info("Loaded %s", temp);

	std::shared_ptr<rett> ret;
	getAI(ret);
	if(!ret)
		logGlobal->error("Cannot get AI!");

	return ret;
#endif //!VCMI_ANDROID
}
Ejemplo n.º 9
0
void
FsWatcher::deleteFile(const fs::path& filename)
{
  sqlite3_stmt* stmt;
  sqlite3_prepare_v2(m_db, "DELETE FROM Files WHERE filename = ?;", -1, &stmt, 0);
  sqlite3_bind_text(stmt, 1, filename.c_str(), -1, SQLITE_STATIC);
  sqlite3_step(stmt);
  sqlite3_finalize(stmt);
}
Ejemplo n.º 10
0
    template<typename ContainerT, typename PointT> void
    OutofcoreOctreeBase<ContainerT, PointT>::writeVPythonVisual (const boost::filesystem::path filename)
    {
      std::ofstream f (filename.c_str ());

      f << "from visual import *\n\n";

      root_->writeVPythonVisual (f);
    }
Ejemplo n.º 11
0
void LogSink::setLogFile (boost::filesystem::path const& path)
{
    bool const wasOpened = m_logFile.open (path.c_str ());

    if (! wasOpened)
    {
        Log (lsFATAL) << "Unable to open logfile " << path;
    }
}
Ejemplo n.º 12
0
void
FsWatcher::addFile(const fs::path& filename)
{
  sqlite3_stmt* stmt;
  sqlite3_prepare_v2(m_db, "INSERT OR IGNORE INTO Files(filename) VALUES(?);", -1, &stmt, 0);
  sqlite3_bind_text(stmt, 1, filename.c_str(), -1, SQLITE_STATIC);
  sqlite3_step(stmt);
  sqlite3_finalize(stmt);
}
Ejemplo n.º 13
0
    void PugiXMLParseResultPrettifier ( const pugi::xml_parse_result& aLoadResult , const boost::filesystem::path& aPath , const std::vector<uint8_t>& aFile )
    {
      log ( Error() , "Failed to parse file " , aPath.c_str() , ". PugiXML returned the following description " , Quote ( aLoadResult.description() ) , "." );
      std::size_t lLineCounter ( 1 );
      std::vector<uint8_t>::const_iterator lIt0 ( aFile.begin() );
      std::vector<uint8_t>::const_iterator lIt1 ( aFile.begin() + aLoadResult.offset );
      std::vector<uint8_t>::const_iterator lIt2 ( lIt1 );

      for ( ; lIt0!=lIt1 ; ++lIt0 )
      {
        if ( *lIt0 == '\n' )
        {
          lLineCounter++;
        }
      }

      for ( ; lIt1 != aFile.begin() ; --lIt1 )
      {
        if ( *lIt1 == '\n' )
        {
          ++lIt1;
          break;
        }
      }

      for ( ; lIt2 != aFile.end() ; ++lIt2 )
      {
        if ( *lIt2 == '\n' )
        {
          --lIt2;
          break;
        }
      }

      std::size_t lDist0 ( lIt0 - lIt1 );
      std::size_t lDist1 ( lIt2 - lIt0 );
      std::string lLine;
      lLine.reserve ( lIt2 - lIt1 );

      for ( ; lIt1 != lIt2 ; ++lIt1 )
      {
        if ( isprint ( *lIt1 ) || *lIt1==10 )
        {
          lLine += *lIt1;
        }
        else
        {
          lLine += '#';
        }
      }

      log ( Error() , "Error occured at line number " , Integer ( lLineCounter ) ,
            ", character " , Integer ( lDist0+1 ) , "\n"
            "LINE           : " , lLine , "\n"
            "ERROR LOCATION : " , std::string ( lDist0 , '_' ) , "^" , std::string ( lDist1 , '_' ) );
    }
Ejemplo n.º 14
0
BitsetSaver::BitsetSaver(const boost::filesystem::path filePath) :
    filePath_(filePath),
    os_(filePath.c_str())
{
    if (!os_)
    {
        const boost::format message = boost::format("Failed to open file %s for writing: %s") % filePath_ % strerror(errno);
        BOOST_THROW_EXCEPTION(common::IoException(errno, message.str()));
    }
}
Ejemplo n.º 15
0
  static void EXPECT_STORED_FILE_DATA_CORRECT(const Data &data, const bf::path &filepath) {
    EXPECT_EQ(data.size(), bf::file_size(filepath));

    ifstream file(filepath.c_str(), std::ios::binary);
    char *read_data = new char[data.size()];
    file.read(read_data, data.size());

    EXPECT_EQ(0, std::memcmp(data.data(), read_data, data.size()));
    delete[] read_data;
  }
Ejemplo n.º 16
0
CZipStream::CZipStream(std::shared_ptr<CIOApi> api, const boost::filesystem::path & archive, unz64_file_pos filepos)
{
	zlib_filefunc64_def zlibApi;

	zlibApi = api->getApiStructure();

	file = unzOpen2_64(archive.c_str(), &zlibApi);
	unzGoToFilePos64(file, &filepos);
	unzOpenCurrentFile(file);
}
Ejemplo n.º 17
0
bool process::create(const std::wstring& command_line, const boost::filesystem::path& current_directory)
{
    if (statue_ == PROCESS_STATUE_READY)
    {
        if (command_line.empty())
        {
            if (!detail::create_process(
                        nullptr,
                        nullptr,
                        inherit_handle_,
                        NORMAL_PRIORITY_CLASS,
                        boost::filesystem::exists(current_directory) ? current_directory.c_str(): nullptr,
                        &si_, &pi_, inject_dll_
                    ))
            {
                return false;
            }
        }
        else
        {
            std::dynarray<wchar_t> command_line_buffer(command_line.size()+1);
            wcscpy_s(command_line_buffer.data(), command_line_buffer.size(), command_line.c_str());

            if (!detail::create_process(
                        nullptr,
                        command_line_buffer.data(),
                        inherit_handle_,
                        NORMAL_PRIORITY_CLASS,
                        boost::filesystem::exists(current_directory) ? current_directory.c_str(): nullptr,
                        &si_, &pi_, inject_dll_
                    ))
            {
                return false;
            }
        }

        statue_ = PROCESS_STATUE_RUNNING;
        return true;
    }

    return false;
}
Ejemplo n.º 18
0
std::vector<uint8_t> readFile(const boost::filesystem::path& filename)
{
    boost::uintmax_t size = boost::filesystem::file_size(filename);

    std::vector<uint8_t> data(size);

    std::ifstream file(filename.c_str(), std::ios::in | std::ios::binary);
    file.read(reinterpret_cast<char*>(&data[0]), size);

    return data;
}
Ejemplo n.º 19
0
Status isReadable(const boost::filesystem::path& path) {
  auto path_exists = pathExists(path);
  if (!path_exists.ok()) {
    return path_exists;
  }

  if (access(path.c_str(), R_OK) == 0) {
    return Status(0, "OK");
  }
  return Status(1, "Path is not readable.");
}
Ejemplo n.º 20
0
	bool getROSPackagePath(const std::string pkgName, boost::filesystem::path & pkgPath)	{
	    pkgPath = ros::package::getPath(pkgName);
	    if (pkgPath.empty())	    {
	        printf("Could not find package '%s' ", pkgName.c_str());
	        return false;
	    }
	    else	    {
	        printf("%s package found here: %s", pkgName.c_str(), pkgPath.c_str());
	        return true;
	    }
	}
Ejemplo n.º 21
0
Status isReadable(const fs::path& path) {
  auto path_exists = pathExists(path);
  if (!path_exists.ok()) {
    return path_exists;
  }

  if (access(path.c_str(), R_OK) == 0) {
    return Status(0, "OK");
  }
  return Status(1, "Path is not readable: " + path.string());
}
Ejemplo n.º 22
0
void EnOpenNLPChunker::Process(std::istream &in, std::ostream &out, const vector<string> &filterList)
{
    const boost::filesystem::path
    inPath = boost::filesystem::unique_path(),
    outPath = boost::filesystem::unique_path();
    // read all input to a temp file
    ofstream inFile(inPath.c_str());

    string line;
    while (getline(in, line)) {
        Unescape(line);
        inFile << line << endl;
    }
    inFile.close();

    // execute chunker
    string cmd = "cat " + inPath.native() + " | "
                 + m_openNLPPath + "/bin/opennlp POSTagger "
                 + m_openNLPPath + "/models/en-pos-maxent.bin | "
                 + m_openNLPPath + "/bin/opennlp ChunkerME "
                 + m_openNLPPath + "/models/en-chunker.bin > "
                 + outPath.native();
    //g << "Executing:" << cmd << endl;
    int ret = system(cmd.c_str());

    // read result of chunker and output as Moses xml trees
    ifstream outFile(outPath.c_str());

    size_t lineNum = 0;
    while (getline(outFile, line)) {
        //cerr << line << endl;
        MosesReformat(line, out, filterList);
        out << endl;
        ++lineNum;
    }
    outFile.close();

    // clean up temporary files
    remove(inPath.c_str());
    remove(outPath.c_str());
}
Ejemplo n.º 23
0
SortedReferenceMetadata loadSortedReferenceXml(
    const boost::filesystem::path &xmlPath)
{
    SortedReferenceMetadata ret;
    std::ifstream is(xmlPath.c_str());
    if (!is)
    {
        BOOST_THROW_EXCEPTION(common::IoException(errno, "Failed to open sorted reference file " + xmlPath.string()));
    }

    return loadSortedReferenceXml(is);
}
Ejemplo n.º 24
0
 boost::optional< boost::filesystem::path > loader::findLibInDirectory( const std::string &name, const boost::filesystem::path &path ) const {
   llvm::sys::Path llvm_path;
   llvm_path.set( path.c_str() );
   llvm_path.appendComponent( "lib" + name );
   llvm_path.appendSuffix( llvm::sys::Path::GetDLLSuffix() );
   if ( llvm_path.isDynamicLibrary() || llvm_path.isBitcodeFile() )
     return boost::filesystem::path( llvm_path.c_str() );
   llvm_path.eraseSuffix();
   if ( llvm_path.isDynamicLibrary() || llvm_path.isBitcodeFile() )
     return boost::filesystem::path( llvm_path.c_str() );
   return boost::optional< boost::filesystem::path >();
 }
Ejemplo n.º 25
0
Status FTDCFileReader::open(const boost::filesystem::path& file) {
    _stream.open(file.c_str(), std::ios_base::in | std::ios_base::binary);
    if (!_stream.is_open()) {
        return Status(ErrorCodes::FileStreamFailed, "Failed to open file " + file.generic_string());
    }

    _fileSize = boost::filesystem::file_size(file);

    _file = file;

    return Status::OK();
}
Ejemplo n.º 26
0
	void DiskFromCFD::PrepareOutputFile(const boost::filesystem::path file_name, std::ofstream& fOutput)
	{
		fOutput.open(file_name.c_str(), std::ios::out);
		fOutput.setf(std::ios::scientific);

		unsigned int count = 1;
		OpenSMOKE::PrintTagOnASCIILabel(22, fOutput, "x[mm]", count);
		OpenSMOKE::PrintTagOnASCIILabel(22, fOutput, "T[K]", count);
		for (unsigned int j = 0; j < thermodynamicsMap_.NumberOfSpecies(); j++)
			OpenSMOKE::PrintTagOnASCIILabel(22, fOutput, thermodynamicsMap_.NamesOfSpecies()[j] + "_w", count);
		fOutput << std::endl;
	}
Ejemplo n.º 27
0
bool JumpListAddRecentTask(JumpList& jumpList, fs::path const& ydweDirectory, fs::path const& filePath)
{
	HRESULT hr = jumpList.AddTask(filePath.filename().c_str(), [&](CComPtr<IShellLinkW>& shellLinkPtr)
	{
		shellLinkPtr->SetPath((ydweDirectory / L"YDWE.exe").c_str());
		shellLinkPtr->SetArguments((L" -loadfile \"" + filePath.wstring() + L"\"").c_str());
		shellLinkPtr->SetDescription(filePath.c_str());
		shellLinkPtr->SetIconLocation((ydweDirectory / L"bin" / L"logo.ico").c_str(), 0);
	});

	return SUCCEEDED(hr);
}
Ejemplo n.º 28
0
Status platformIsTmpDir(const fs::path& dir) {
  struct stat dir_stat;
  if (::stat(dir.c_str(), &dir_stat) < 0) {
    return Status(-1, "");
  }

  if (dir_stat.st_mode & (1 << 9)) {
    return Status(0, "OK");
  }

  return Status(1, "");
}
Ejemplo n.º 29
0
bool OptionHandler::generateWaveformData(
    const boost::filesystem::path& input_filename,
    const boost::filesystem::path& output_filename,
    const Options& options)
{
    const std::unique_ptr<ScaleFactor> scale_factor = createScaleFactor(options);

    const boost::filesystem::path output_file_ext = output_filename.extension();

    const std::unique_ptr<AudioFileReader> audio_file_reader =
        createAudioFileReader(input_filename);

    if (audio_file_reader == nullptr) {
        error_stream << "Unknown file type: " << input_filename << '\n';
        return false;
    }

    if (!audio_file_reader->open(input_filename.c_str())) {
        return false;
    }

    WaveformBuffer buffer;
    WaveformGenerator processor(buffer, *scale_factor);

    if (!audio_file_reader->run(processor)) {
        return false;
    }

    assert(output_file_ext == ".dat" || output_file_ext == ".json");

    const int bits = options.getBits();

    if (output_file_ext == ".dat") {
        return buffer.save(output_filename.c_str(), bits);
    }
    else {
        return buffer.saveAsJson(output_filename.c_str(), bits);
    }
}
Ejemplo n.º 30
0
		bool CreateDirectoriesTransacted(KTMTransaction& trans, const boost::filesystem::path& dir)
		{
			if (dir.empty() || FileExistsTransacted(trans, dir.c_str()))
			{
				if (!dir.empty() && !boost::filesystem::is_directory(dir))
				{
					// this is an error 
					// TODO log disp, whatever
				}
				return false;
			}

			// First create branch, by calling ourself recursively
			CreateDirectoriesTransacted(trans, dir.parent_path());
			// Now that parent's path exists, create the directory
			if (trans.CreateDirectoryExW(nullptr, dir.c_str(), nullptr) == 0)
			{
				std::wstring msg = lhWinAPI::GetLastErrorS();
				OutputDebugString(msg.c_str());
			}
			return true;
		}