MCPcopy Create free account
hub / github.com/MemNixFS/MemNixFS / export_tree

Function export_tree

src/cli/main.cpp:157–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157void export_tree(const lmpfs::vfs::NodePtr& n, const std::filesystem::path& out) {
158 namespace fs = std::filesystem;
159 if (n->is_dir()) {
160 fs::create_directories(out);
161 for (auto& e : n->list()) export_tree(e.node, out / e.name);
162 } else {
163 std::ofstream f(out, std::ios::binary);
164 if (!f)
165 lmpfs::throw_error("export: cannot create '{}'", out.string());
166 const std::size_t kBuf = 64 * 1024;
167 std::vector<char> buf(kBuf);
168 std::uint64_t off = 0;
169 while (true) {
170 std::size_t got = n->read(off, buf.data(), buf.size());
171 if (got == 0) break;
172 f.write(buf.data(), got);
173 if (!f)
174 lmpfs::throw_error("export: write failed for '{}'", out.string());
175 off += got;
176 if (got < buf.size()) break;
177 }
178 }
179}
180
181void print_tree(const lmpfs::vfs::NodePtr& n, std::string indent = "") {
182 fmt::print("{}{}{}\n", indent, n->is_dir() ? "[DIR] " : " ", n->name());

Callers 1

mainFunction · 0.85

Calls 5

throw_errorFunction · 0.85
is_dirMethod · 0.80
listMethod · 0.80
readMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected