void TailFile::parseStateFileLine()

in extensions/standard-processors/processors/TailFile.cpp [344:411]


void TailFile::parseStateFileLine(char *buf, std::map<std::filesystem::path, TailState> &state) const {
  char *line = buf;

  logger_->log_trace("Received line %s", buf);

  while ((line[0] == ' ') || (line[0] == '\t'))
    ++line;

  char first = line[0];
  if ((first == '\0') || (first == '#') || (first == '\r') || (first == '\n') || (first == '=')) {
    return;
  }

  char *equal = strchr(line, '=');
  if (equal == nullptr) {
    return;
  }

  equal[0] = '\0';
  std::string key = line;

  equal++;
  while ((equal[0] == ' ') || (equal[0] == '\t'))
    ++equal;

  first = equal[0];
  if ((first == '\0') || (first == '\r') || (first == '\n')) {
    return;
  }

  std::string value = equal;
  key = utils::StringUtils::trimRight(key);
  value = utils::StringUtils::trimRight(value);

  if (key == "FILENAME") {
    std::filesystem::path file_path = value;
    if (file_path.has_filename() && file_path.has_parent_path()) {
      logger_->log_debug("State migration received path %s, file %s", file_path.parent_path().string(), file_path.filename().string());
      state.emplace(file_path.filename(), TailState{file_path.parent_path(), file_path.filename()});
    } else {
      state.emplace(value, TailState{file_path.parent_path(), value});
    }
  }
  if (key == "POSITION") {
    // for backwards compatibility
    if (tail_states_.size() != std::size_t{1}) {
      throw minifi::Exception(ExceptionType::PROCESSOR_EXCEPTION, "Incompatible state file types");
    }
    const auto position = std::stoull(value);
    logger_->log_debug("Received position %llu", position);
    state.begin()->second.position_ = gsl::narrow<uint64_t>(position);
  }
  if (key.find(CURRENT_STR) == 0) {
    const auto file = key.substr(strlen(CURRENT_STR));
    std::filesystem::path file_path = value;
    if (file_path.has_filename() && file_path.has_parent_path()) {
      state[file].path_ = file_path.parent_path();
      state[file].file_name_ = file_path.filename();
    } else {
      throw minifi::Exception(ExceptionType::PROCESSOR_EXCEPTION, "State file contains an invalid file name");
    }
  }

  if (key.find(POSITION_STR) == 0) {
    const auto file = key.substr(strlen(POSITION_STR));
    state[file].position_ = std::stoull(value);
  }
}