Пример #1
0
bool XmlParser::InternalParseFile( const char* _filename )
{
    // load file to buffer
    // check if file exists
    ex_assert_return( futil::file::exists(path_t(_filename)), false, "%s not Existss.", _filename );

    IFile::smart_ptr_t spFile = futil::file::open<PhysicalFile>(_filename);
    if ( spFile )
    {
        uint32 filesize = uint32(spFile->size());
        int bufferSize =  sizeof(tchar) * filesize ;
        // get internal buffer
        void* pBuffer = GetBuffer(bufferSize);
        // read file to buffer
        spFile->read( pBuffer, filesize );
        // close file immediately
        spFile->close();

        // record file name help handle error 
        m_ParsingFileName = _filename;
        // parse file
        bool bResult = InternalParseBuffer(bufferSize);
        m_ParsingFileName = NULL;

        // return result
        return bResult;
    }
    return false;
}
Пример #2
0
  STAGE_RC update_operation::deploy() {
    debug() << "patching file " << basis_path_ << " using delta " << delta_path_ << " out to " << patched_path_;
    rs_result rc = encoder_.patch(basis_path_.c_str(), delta_path_.c_str(), patched_path_.c_str());

    if (rc != RS_DONE) {
      error()
        << "Patching file " << basis_path_ << " using patch " << delta_path_ 
        <<" has failed. librsync rc: " << rc;

      return STAGE_INTERNAL_ERROR;
    }

    hasher::digest_rc digest = hasher::instance()->hex_digest(patched_path_);
    if (digest != patched_checksum) {
      error()
        << "Checksum mismatch: "
        << digest.digest << " vs " << patched_checksum
        << " in file " << patched_path_;

      return STAGE_FILE_INTEGRITY_MISMATCH;
    }

    if (rmgr_.stat_filesize(patched_path_) != patched_length) {
      error() 
        << "Length mismatch: "
        << rmgr_.stat_filesize(patched_path_) << " to " << patched_length
        << " in file " << patched_path_;

      return STAGE_FILE_INTEGRITY_MISMATCH;
    }

    // swap the files
    debug() << "Swapping files: " << basis_path_ << " & " << patched_path_;

    fs::rename(patched_path_, path_t(patched_path_.string() + ".tmp"));
    fs::rename(basis_path_, patched_path_);
    fs::rename(path_t(patched_path_.string() + ".tmp"), basis_path_);

    patched_ = true;

    return STAGE_OK;
  }
Пример #3
0
std::wstring normalize_path(const std::wstring &path){
	std::wstring ret;
	size_t skip = 0;
	if (starts_with(path, system_path_prefix)){
		ret = system_path_prefix;
		skip = 4;
	}
	ret += path_t(path.substr(skip)).normalize().wstring();
	std::transform(ret.begin(), ret.end(), ret.begin(), [](wchar_t c){ return c == '/' ? '\\' : c; });
	return ret;
}
Пример #4
0
  // On Windows and Linux, root is KZH_DISTANCE_FROM_ROOT directories up from
  // the binary's
  path_t locate_root_directory(const path_t& bin_path) {
    #if KZH_PLATFORM == KZH_PLATFORM_APPLE
      return path_t(bin_path).remove_leaf().make_preferred();
    #else
      path_t root_path(bin_path);

      for (int i = 0; i < KZH_DISTANCE_FROM_ROOT; ++i) {
        root_path = root_path.remove_leaf();
      }

      return root_path.make_preferred();
    #endif
  }
Пример #5
0
  path_t locate_bin_directory(const logger* log, bool verbose) {
    // locate the binary and build its path
    #if KZH_PLATFORM == KZH_PLATFORM_LINUX
      // use binreloc and fs to build up our paths
      int brres = br_init(0);
      if (brres == 0) {
        if (verbose) {
          log->error() << "binreloc could not be initialised";
        }

        throw std::runtime_error("Unable to resolve paths! binreloc could not be initialized");
      }

      char *tmp_bin_path = br_find_exe_dir(".");
      path_t bin_path = path_t(tmp_bin_path).make_preferred();
      free(tmp_bin_path);
      br_free();

      return bin_path;
    #elif KZH_PLATFORM == KZH_PLATFORM_APPLE
      // use NSBundlePath() to build up our paths
      // return path_t(macBundlePath() + "/Contents/MacOS").make_preferred();
      return path_t(macBundlePath()).make_preferred();
    #else // Windows
      // use GetModuleFileName() and fs to build up our paths on Windows
      TCHAR szPath[MAX_PATH];

      if (!GetModuleFileName(NULL, szPath, MAX_PATH)) {
        if (verbose) {
          log->error() << "Unable to resolve path: " << GetLastError();;
        }

        throw std::runtime_error("Unable to resolve paths! GetModuleFileName() failed. See the log for the error.");
      }

      return path_t(string_t(szPath)).remove_filename().make_preferred();
    #endif
  }
Пример #6
0
  STAGE_RC update_operation::deploy() {
    auto file_manager = config_.file_manager;

    debug() << "patching file " << basis_path_ << " using delta " << delta_path_ << " out to " << patched_path_;

    if (
      !file_manager->is_readable(basis_path_) ||
      !file_manager->is_readable(delta_path_)
    ) {
      return STAGE_INVALID_STATE;
    }

    rs_result rc = encoder_.patch(basis_path_.c_str(), delta_path_.c_str(), patched_path_.c_str());

    if (rc != RS_DONE) {
      error()
        << "Patching file " << basis_path_ << " using patch " << delta_path_
        <<" has failed. librsync rc: " << rc;

      return STAGE_ENCODING_ERROR;
    }

    hasher::digest_rc digest = config_.hasher->hex_digest(patched_path_);

    if (digest != patched_checksum) {
      error()
        << "Checksum mismatch: "
        << digest.digest << " vs " << patched_checksum
        << " in file " << patched_path_;

      return STAGE_FILE_INTEGRITY_MISMATCH;
    }

    const path_t temp_path(path_t(patched_path_.string() + ".tmp").make_preferred());

    // move the patched file to a temporary location until we can move it over
    // to the destination:
    file_manager->move(patched_path_, temp_path);

    // free the destination; move the old file to where the patched file was so
    // that we can roll back if necessary:
    file_manager->move(basis_path_, patched_path_); // !! repository side effect !!

    // finally, move over the patched file to where the old file was:
    file_manager->move(temp_path, basis_path_); // !! repository side effect !!

    patched_ = true;

    return STAGE_OK;
  }
Пример #7
0
  void path_resolver::resolve(path_t root, bool verbose) {
    if (root.empty()) {
      root_path_ = locate_root_directory(locate_bin_directory(this, verbose));
    }
    else {
      root_path_ = root;
    }

    // locate the binary and build its path
    #if KZH_PLATFORM == KZH_PLATFORM_LINUX
      // Linux:
      if (verbose) {
        debug() << "Platform: Linux";
      }

      cache_path_ = path_t(root_path_ / ".kzh/cache").make_preferred();
    #elif KZH_PLATFORM == KZH_PLATFORM_APPLE
      // OS X:
      if (verbose) {
        debug() << "Platform: OS X";
      }

      cache_path_ = path_t(root_path_ / ".kzh/cache").make_preferred();
    #else
      // Windows:
      if (verbose) {
        debug() << "Platform: Windows";
      }

      cache_path_ = path_t(root_path_ / ".kzh/cache").make_preferred();
    #endif

    if (verbose) {
      debug() << "Root path: " <<  root_path_;
      debug() << "Cache path: " <<  cache_path_;
    }
  }
Пример #8
0
BackupMode BackupSystem::get_backup_mode_for_object(const FileSystemObject &fso, bool &follow_link_targets){
	follow_link_targets = false;
	bool dir = fso.is_directoryish();
	auto it = this->ignored_names.find(fso.get_name());
	if (it != this->ignored_names.end()){
		auto ignore_type = it->second;
		if (((unsigned)ignore_type & (unsigned)NameIgnoreType::File) && !dir)
			return BackupMode::NoBackup;
		if (((unsigned)ignore_type & (unsigned)NameIgnoreType::Directory) && dir)
			return BackupMode::NoBackup;
	}
	if (this->ignored_extensions.find(path_t(fso.get_name()).extension().wstring()) != this->ignored_extensions.end() && !dir)
		return BackupMode::NoBackup;
	if (this->ignored_paths.find(*fso.get_unmapped_base_path()) != this->ignored_paths.end())
		return BackupMode::NoBackup;
	return dir ? BackupMode::Directory : BackupMode::Full;
}
Пример #9
0
config_set::path_t  config_set::_pathFromString (string const &strPath) const
{
    return path_t (strPath);
}
Пример #10
0
 path_t get_value() {
     return path_t (field);
 }
Пример #11
0
  STAGE_RC update_operation::stage() {
    basis_path_     = rmgr_.root_path() / basis;
    cache_dir_      = path_t(rmgr_.cache_path() / rm_.checksum / basis).parent_path();
    signature_path_ = cache_dir_ / (path_t(basis).filename().string() + ".signature");
    delta_path_     = cache_dir_ / (path_t(basis).filename().string() + ".delta");
    patched_path_   = cache_dir_ / (path_t(basis).filename().string() + ".patched");

    // basis must exist
    if (!rmgr_.is_readable(basis_path_)) {
      error()
        << "basis file does not exist at: " << basis_path_;
        
      return STAGE_FILE_MISSING;
    }

    // basis checksum check
    hasher::digest_rc digest = hasher::instance()->hex_digest(basis_path_);
    if (digest != basis_checksum) {
      error()
        << "Basis file checksum mismatch: "
        << digest.digest << " vs " << basis_checksum
        << " in file " << basis_path_;

      return STAGE_FILE_INTEGRITY_MISMATCH;
    }

    if (rmgr_.stat_filesize(basis_path_) != basis_length) {
      error() 
        << "Length mismatch: "
        << rmgr_.stat_filesize(basis_path_) << " to " << basis_length
        << " in file " << basis_path_;

      return STAGE_FILE_INTEGRITY_MISMATCH;
    }


    // prepare our cache directory, if necessary
    if (!fs::is_directory(cache_dir_)) {
      if (!rmgr_.create_directory(cache_dir_)) {
        error() << "Unable to create cache directory: " << cache_dir_;
        return STAGE_UNAUTHORIZED;
      }
    }

    // TODO: free space checks, need at least 2x basis file size + delta size

    // get the delta patch
    if (!rmgr_.get_remote(delta, delta_path_, delta_checksum, delta_length)) {
      throw invalid_resource(delta);
    }

    // create the signature
    debug() << "generating signature for " << basis_path_ << " out to " << signature_path_;

    rs_result rc = encoder_.signature(basis_path_.c_str(), signature_path_.c_str());
    if (rc != RS_DONE) {
      error() << "Generating of signature for file " << basis_path_ << " has failed. librsync rc: " << rc;
      return STAGE_INTERNAL_ERROR;
    }

    return STAGE_OK;
  }