| 36 | } |
| 37 | |
| 38 | CoTryTask<Dispatcher::OutputTable> handleReadFile(IEnv &ienv, |
| 39 | const argparse::ArgumentParser &parser, |
| 40 | const Dispatcher::Args &args) { |
| 41 | [[maybe_unused]] auto &env = dynamic_cast<AdminEnv &>(ienv); |
| 42 | ENSURE_USAGE(args.empty()); |
| 43 | Dispatcher::OutputTable table; |
| 44 | |
| 45 | // 1. parse arguments. |
| 46 | Path src = parser.get<std::string>("path"); |
| 47 | auto stat = parser.get<bool>("--stat"); |
| 48 | auto enableChecksum = !parser.get<bool>("--disableChecksum"); |
| 49 | auto fillZero = parser.get<bool>("--fillZero"); |
| 50 | auto verbose = parser.get<bool>("--verbose"); |
| 51 | auto output = parser.present<std::string>("--output"); |
| 52 | auto hex = parser.get<bool>("--hex"); |
| 53 | |
| 54 | size_t offset = 0; |
| 55 | if (auto o = parser.present("--offset")) { |
| 56 | auto offsetResult = Size::from(*o); |
| 57 | CO_RETURN_AND_LOG_ON_ERROR(offsetResult); |
| 58 | offset = *offsetResult; |
| 59 | } |
| 60 | std::optional<size_t> lengthIn; |
| 61 | if (auto l = parser.present<std::string>("--length")) { |
| 62 | auto lengthResult = Size::from(*l); |
| 63 | CO_RETURN_AND_LOG_ON_ERROR(lengthResult); |
| 64 | lengthIn = *lengthResult; |
| 65 | } |
| 66 | storage::client::TargetSelectionMode mode = storage::client::TargetSelectionMode::Default; |
| 67 | uint32_t targetIndex = 0; |
| 68 | if (auto m = parser.present("--mode")) { |
| 69 | auto result = magic_enum::enum_cast<storage::client::TargetSelectionMode>(*m); |
| 70 | if (result) { |
| 71 | mode = *result; |
| 72 | } else if (auto idx = scn::scan_value<uint32_t>(*m)) { |
| 73 | mode = storage::client::TargetSelectionMode::ManualMode; |
| 74 | targetIndex = idx.value(); |
| 75 | } else { |
| 76 | co_return makeError(StatusCode::kInvalidArg, fmt::format("invalid mode", *m)); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // 2. refresh routing info. |
| 81 | CO_RETURN_AND_LOG_ON_ERROR(co_await env.mgmtdClientGetter()->refreshRoutingInfo(true)); |
| 82 | auto routingInfo = env.mgmtdClientGetter()->getRoutingInfo()->raw(); |
| 83 | if (routingInfo == nullptr) { |
| 84 | co_return makeError(StorageClientCode::kRoutingError, "routing info is null"); |
| 85 | } |
| 86 | |
| 87 | // 3. open file. |
| 88 | auto openResult = co_await FileWrapper::openOrCreateFile(env, src); |
| 89 | CO_RETURN_AND_LOG_ON_ERROR(openResult); |
| 90 | auto &file = *openResult; |
| 91 | |
| 92 | // 4. calc chain and chunk id. |
| 93 | if (file.length() <= offset) { |
| 94 | co_return makeError(StatusCode::kInvalidArg, fmt::format("offset {} exceed file length {}", offset, file.length())); |
| 95 | } |
nothing calls this directly
no test coverage detected