forked from deepseek-ai/3FS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseTargetMeta.cc
More file actions
66 lines (53 loc) · 2.09 KB
/
Copy pathParseTargetMeta.cc
File metadata and controls
66 lines (53 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "ParseTargetMeta.h"
#include <folly/experimental/coro/BlockingWait.h>
#include <fstream>
#include "AdminEnv.h"
#include "client/cli/admin/FileWrapper.h"
#include "client/cli/common/Dispatcher.h"
#include "client/cli/common/Utils.h"
#include "client/storage/StorageClient.h"
#include "common/serde/Serde.h"
#include "common/utils/FileUtils.h"
#include "common/utils/Result.h"
#include "fbs/meta/Common.h"
#include "fbs/storage/Common.h"
namespace hf3fs::client::cli {
namespace {
auto getParser() {
argparse::ArgumentParser parser("parse-target-meta");
parser.add_argument("path");
parser.add_argument("-o", "--output");
parser.add_argument("--format").default_value(false).implicit_value(true);
return parser;
}
CoTryTask<Dispatcher::OutputTable> handleParseTargetMeta(IEnv &ienv,
const argparse::ArgumentParser &parser,
const Dispatcher::Args &args) {
[[maybe_unused]] auto &env = dynamic_cast<AdminEnv &>(ienv);
ENSURE_USAGE(args.empty());
Dispatcher::OutputTable table;
// 1. parse arguments.
Path src = parser.get<std::string>("path");
auto output = parser.present<std::string>("--output");
auto format = parser.get<bool>("--format");
auto readResult = loadFile(src);
CO_RETURN_AND_LOG_ON_ERROR(readResult);
std::map<storage::ChunkId, storage::ChunkMetadata> metas;
CO_RETURN_AND_LOG_ON_ERROR(serde::deserialize(metas, *readResult));
// 5. write to file.
std::ofstream outputFile;
if (output.has_value()) {
outputFile = std::ofstream{output.value()};
if (!outputFile) {
co_return makeError(StatusCode::kInvalidArg, fmt::format("create output file {} failed", output.value()));
}
}
std::ostream &out = output.has_value() ? outputFile : std::cout;
out << serde::toJsonString(metas, false, format) << std::endl;
co_return table;
}
} // namespace
CoTryTask<void> registerParseTargetMetaHandler(Dispatcher &dispatcher) {
co_return co_await dispatcher.registerHandler(getParser, handleParseTargetMeta);
}
} // namespace hf3fs::client::cli