mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-17 00:10:03 -04:00
feat(scanner): use file_access abstraction for dumping inodes
This commit is contained in:
parent
61db8cec2b
commit
86f0af2058
@ -32,6 +32,7 @@ namespace dwarfs {
|
|||||||
struct scanner_options;
|
struct scanner_options;
|
||||||
|
|
||||||
class entry_factory;
|
class entry_factory;
|
||||||
|
class file_access;
|
||||||
class filesystem_writer;
|
class filesystem_writer;
|
||||||
class logger;
|
class logger;
|
||||||
class os_access;
|
class os_access;
|
||||||
@ -47,11 +48,11 @@ class scanner {
|
|||||||
std::shared_ptr<os_access const> os, std::shared_ptr<script> scr,
|
std::shared_ptr<os_access const> os, std::shared_ptr<script> scr,
|
||||||
const scanner_options& options);
|
const scanner_options& options);
|
||||||
|
|
||||||
void scan(filesystem_writer& fsw, const std::filesystem::path& path,
|
void scan(
|
||||||
progress& prog,
|
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::nullopt,
|
||||||
std::nullopt) {
|
std::shared_ptr<file_access const> fa = nullptr) {
|
||||||
impl_->scan(fsw, path, prog, list);
|
impl_->scan(fsw, path, prog, list, fa);
|
||||||
}
|
}
|
||||||
|
|
||||||
class impl {
|
class impl {
|
||||||
@ -61,7 +62,8 @@ class scanner {
|
|||||||
virtual void
|
virtual void
|
||||||
scan(filesystem_writer& fsw, const std::filesystem::path& path,
|
scan(filesystem_writer& fsw, const std::filesystem::path& path,
|
||||||
progress& prog,
|
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:
|
private:
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "dwarfs/entry.h"
|
#include "dwarfs/entry.h"
|
||||||
#include "dwarfs/error.h"
|
#include "dwarfs/error.h"
|
||||||
#include "dwarfs/features.h"
|
#include "dwarfs/features.h"
|
||||||
|
#include "dwarfs/file_access.h"
|
||||||
#include "dwarfs/file_scanner.h"
|
#include "dwarfs/file_scanner.h"
|
||||||
#include "dwarfs/filesystem_writer.h"
|
#include "dwarfs/filesystem_writer.h"
|
||||||
#include "dwarfs/fragment_chunkable.h"
|
#include "dwarfs/fragment_chunkable.h"
|
||||||
@ -279,10 +280,10 @@ class scanner_ final : public scanner::impl {
|
|||||||
std::shared_ptr<os_access const> os, std::shared_ptr<script> scr,
|
std::shared_ptr<os_access const> os, std::shared_ptr<script> scr,
|
||||||
const scanner_options& options);
|
const scanner_options& options);
|
||||||
|
|
||||||
void
|
void scan(filesystem_writer& fsw, std::filesystem::path const& path,
|
||||||
scan(filesystem_writer& fsw, std::filesystem::path const& path,
|
progress& prog,
|
||||||
progress& prog,
|
std::optional<std::span<std::filesystem::path const>> list,
|
||||||
std::optional<std::span<std::filesystem::path const>> list) override;
|
std::shared_ptr<file_access const> fa) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<entry> scan_tree(std::filesystem::path const& path,
|
std::shared_ptr<entry> scan_tree(std::filesystem::path const& path,
|
||||||
@ -564,7 +565,8 @@ scanner_<LoggerPolicy>::scan_list(std::filesystem::path const& path,
|
|||||||
template <typename LoggerPolicy>
|
template <typename LoggerPolicy>
|
||||||
void scanner_<LoggerPolicy>::scan(
|
void scanner_<LoggerPolicy>::scan(
|
||||||
filesystem_writer& fsw, const std::filesystem::path& path, progress& prog,
|
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) {
|
if (!options_.debug_filter_function) {
|
||||||
LOG_INFO << "scanning " << path;
|
LOG_INFO << "scanning " << path;
|
||||||
}
|
}
|
||||||
@ -659,8 +661,23 @@ void scanner_<LoggerPolicy>::scan(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (getenv_is_enabled("DWARFS_DUMP_INODES")) {
|
if (auto dumpfile = os_->getenv("DWARFS_DUMP_INODES")) {
|
||||||
im.dump(std::cout);
|
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...";
|
LOG_INFO << "building blocks...";
|
||||||
|
@ -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,
|
scanner s(lgr, wg_scanner, std::move(sf), entry_factory::create(), iol.os,
|
||||||
std::move(script), options);
|
std::move(script), options);
|
||||||
|
|
||||||
if (input_list) {
|
s.scan(*fsw, path, prog, input_list, iol.file);
|
||||||
s.scan(*fsw, path, prog, *input_list);
|
|
||||||
} else {
|
|
||||||
s.scan(*fsw, path, prog);
|
|
||||||
}
|
|
||||||
|
|
||||||
options.inode.categorizer_mgr.reset();
|
options.inode.categorizer_mgr.reset();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user