예제 #1
0
folly::dynamic ConfigApi::getConfigSourcesInfo() {
  folly::dynamic reply_val = folly::dynamic::object;

  // we have config_str, write its hash
  if (!opts_.config_str.empty()) {
    reply_val[kMcrouterConfigKey] = Md5Hash(opts_.config_str);
  }

  std::lock_guard<std::mutex> lock(fileInfoMutex_);

  for (const auto& fileIt : fileInfos_) {
    const auto& file = fileIt.second;
    switch (file.type) {
      case ConfigType::ConfigFile:
        reply_val[kConfigFile] = file.path;
        reply_val[kMcrouterConfigKey] = file.md5;
        break;
      case ConfigType::Pool:
        if (!reply_val.count("pools")) {
          reply_val["pools"] = folly::dynamic::object;
        }
        reply_val["pools"].insert(file.path, file.md5);
        break;
      case ConfigType::ConfigImport:
        if (!reply_val.count(kConfigImport)) {
          reply_val[kConfigImport] = folly::dynamic::object;
        }
        reply_val[kConfigImport].insert(file.path, file.md5);
        break;
    }
  }

  return reply_val;
}
예제 #2
0
파일: Stats.cpp 프로젝트: AnumQ/protein
string
Stats::Md5ForSeq(Alignment *alnObj, int s)
{
    string seq;
    const clustalw::SeqArray* seqArray = alnObj->getSeqArray();
    char *hash;
    string ret;

    for(int l = 1; l <= alnObj->getSeqLength(s); l++)
    {
        int val = (*seqArray)[s][l];
        // continue if gap
        if((val < 0) || (val > userParameters->getMaxAA()))
            continue;
        seq.append(1, clustalw::userParameters->getAminoAcidCode(val));
    }
    std::transform(seq.begin(), seq.end(), seq.begin(), ::toupper);

    hash = Md5Hash(seq.c_str());
    if (hash==NULL)
    {
        ret = "HASHING_FAILURE";
    } else {
        ret = hash;
    }
    return ret;
}
예제 #3
0
bool ConfigApi::FileInfo::checkMd5Changed() {
  auto previousHash = md5;
  std::string contents;
  if (!folly::readFile(path.data(), contents)) {
    throw std::runtime_error("Error reading from config file " + path);
  }
  md5 = Md5Hash(contents);
  lastMd5Check = nowWallSec();

  return md5 != previousHash;
}
예제 #4
0
파일: Stats.cpp 프로젝트: AnumQ/protein
string
Stats::ConcatInputHash(Alignment *alnObj)
{
    vector<string> rawSeqArray;
    string ret;
    char *hash;

    // collect all sequences and sort
    const clustalw::SeqArray* seqArray = alnObj->getSeqArray();
    for(int s = 1; s <= alnObj->getNumSeqs(); s++)
    {
        string seq;
        for(int r = 1; r <= alnObj->getSeqLength(s); r++)
        {
            int val = (*seqArray)[s][r];
            seq.append(1, clustalw::userParameters->getAminoAcidCode(val));
        }
        rawSeqArray.push_back(seq);
    }
    std::sort(rawSeqArray.begin(), rawSeqArray.end());

    // concatenate sorted seqs
    string concatSeq;
    std::vector<string>::iterator iter;
    for(iter=rawSeqArray.begin(); iter != rawSeqArray.end(); ++iter)
        concatSeq.append(*iter);

    // build hash and return
    hash = Md5Hash(concatSeq.c_str());
    if (hash==NULL)
    {
        ret="HASHING_FAILURE";
    } else {
        for (int i=0; i<strlen(hash); i++)
        ret.append(1, hash[i]);
        free(hash);
    }
    return ret;
}
예제 #5
0
bool ConfigApi::get(ConfigType type, const std::string& path,
                    std::string& contents) {
  std::string fullPath;
  if (type == ConfigType::ConfigImport) {
    if (folly::StringPiece(path).startsWith(kAbsoluteFilePrefix)) {
      fullPath = path.substr(strlen(kAbsoluteFilePrefix));
    } else {
      boost::filesystem::path filePath(opts_.config_file);
      fullPath = (filePath.parent_path() / path).string();
    }
  } else if (type == ConfigType::Pool) {
    if (folly::StringPiece(path).startsWith(kAbsoluteFilePrefix)) {
      fullPath = path.substr(strlen(kAbsoluteFilePrefix));
    } else {
      return false;
    }
  } else {
    fullPath = path;
  }

  if (!folly::readFile(fullPath.data(), contents)) {
    return false;
  }

  if (tracking_) {
    std::lock_guard<std::mutex> lock(fileInfoMutex_);
    auto fileInfoIt = trackedFiles_.emplace(fullPath, FileInfo()).first;

    auto& file = fileInfoIt->second;
    file.path = fullPath;
    file.type = type;
    file.lastMd5Check = nowWallSec();
    file.md5 = Md5Hash(contents);
  }
  return true;
}