Skip to content

Commit

Permalink
feat(scanner): use file_access abstraction for dumping inodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Dec 30, 2023
1 parent 61db8ce commit 86f0af2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
14 changes: 8 additions & 6 deletions include/dwarfs/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace dwarfs {
struct scanner_options;

class entry_factory;
class file_access;
class filesystem_writer;
class logger;
class os_access;
Expand All @@ -47,11 +48,11 @@ class scanner {
std::shared_ptr<os_access const> os, std::shared_ptr<script> scr,
const scanner_options& options);

void scan(filesystem_writer& fsw, const std::filesystem::path& path,
progress& prog,
std::optional<std::span<std::filesystem::path const>> list =
std::nullopt) {
impl_->scan(fsw, path, prog, list);
void scan(
filesystem_writer& fsw, const std::filesystem::path& path, progress& prog,
std::optional<std::span<std::filesystem::path const>> list = std::nullopt,
std::shared_ptr<file_access const> fa = nullptr) {
impl_->scan(fsw, path, prog, list, fa);
}

class impl {
Expand All @@ -61,7 +62,8 @@ class scanner {
virtual void
scan(filesystem_writer& fsw, const std::filesystem::path& path,
progress& prog,
std::optional<std::span<std::filesystem::path const>> list) = 0;
std::optional<std::span<std::filesystem::path const>> list,
std::shared_ptr<file_access const> fa) = 0;
};

private:
Expand Down
31 changes: 24 additions & 7 deletions src/dwarfs/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "dwarfs/entry.h"
#include "dwarfs/error.h"
#include "dwarfs/features.h"
#include "dwarfs/file_access.h"
#include "dwarfs/file_scanner.h"
#include "dwarfs/filesystem_writer.h"
#include "dwarfs/fragment_chunkable.h"
Expand Down Expand Up @@ -279,10 +280,10 @@ class scanner_ final : public scanner::impl {
std::shared_ptr<os_access const> os, std::shared_ptr<script> scr,
const scanner_options& options);

void
scan(filesystem_writer& fsw, std::filesystem::path const& path,
progress& prog,
std::optional<std::span<std::filesystem::path const>> list) override;
void scan(filesystem_writer& fsw, std::filesystem::path const& path,
progress& prog,
std::optional<std::span<std::filesystem::path const>> list,
std::shared_ptr<file_access const> fa) override;

private:
std::shared_ptr<entry> scan_tree(std::filesystem::path const& path,
Expand Down Expand Up @@ -564,7 +565,8 @@ scanner_<LoggerPolicy>::scan_list(std::filesystem::path const& path,
template <typename LoggerPolicy>
void scanner_<LoggerPolicy>::scan(
filesystem_writer& fsw, const std::filesystem::path& path, progress& prog,
std::optional<std::span<std::filesystem::path const>> list) {
std::optional<std::span<std::filesystem::path const>> list,
std::shared_ptr<file_access const> fa) {
if (!options_.debug_filter_function) {
LOG_INFO << "scanning " << path;
}
Expand Down Expand Up @@ -659,8 +661,23 @@ void scanner_<LoggerPolicy>::scan(
});
});

if (getenv_is_enabled("DWARFS_DUMP_INODES")) {
im.dump(std::cout);
if (auto dumpfile = os_->getenv("DWARFS_DUMP_INODES")) {
if (fa) {
LOG_VERBOSE << "dumping inodes to " << *dumpfile;
std::error_code ec;
auto ofs = fa->open_output(*dumpfile, ec);
if (ec) {
LOG_ERROR << "cannot open '" << *dumpfile << "': " << ec.message();
} else {
im.dump(ofs->os());
ofs->close(ec);
if (ec) {
LOG_ERROR << "cannot close '" << *dumpfile << "': " << ec.message();
}
}
} else {
LOG_ERROR << "cannot dump inodes: no file access";
}
}

LOG_INFO << "building blocks...";
Expand Down
6 changes: 1 addition & 5 deletions src/mkdwarfs_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,11 +1258,7 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
scanner s(lgr, wg_scanner, std::move(sf), entry_factory::create(), iol.os,
std::move(script), options);

if (input_list) {
s.scan(*fsw, path, prog, *input_list);
} else {
s.scan(*fsw, path, prog);
}
s.scan(*fsw, path, prog, input_list, iol.file);

options.inode.categorizer_mgr.reset();
}
Expand Down

0 comments on commit 86f0af2

Please sign in to comment.