mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-11 13:30:47 -04:00
refactor(entry): move to internal namespace
This commit is contained in:
parent
61d77b3295
commit
fc21c5d9d5
@ -646,7 +646,7 @@ list(APPEND LIBDWARFS_WRITER_SRC
|
||||
src/dwarfs/category_parser.cpp
|
||||
src/dwarfs/chmod_entry_transformer.cpp
|
||||
src/dwarfs/console_writer.cpp
|
||||
src/dwarfs/entry.cpp
|
||||
src/dwarfs/entry_factory.cpp
|
||||
src/dwarfs/filesystem_block_category_resolver.cpp
|
||||
src/dwarfs/filesystem_writer.cpp
|
||||
src/dwarfs/filter_debug.cpp
|
||||
@ -655,6 +655,7 @@ list(APPEND LIBDWARFS_WRITER_SRC
|
||||
src/dwarfs/inode_fragments.cpp
|
||||
src/dwarfs/internal/block_manager.cpp
|
||||
src/dwarfs/internal/chmod_transformer.cpp
|
||||
src/dwarfs/internal/entry.cpp
|
||||
src/dwarfs/internal/file_scanner.cpp
|
||||
src/dwarfs/internal/fragment_chunkable.cpp
|
||||
src/dwarfs/internal/global_entry_data.cpp
|
||||
|
60
include/dwarfs/entry_factory.h
Normal file
60
include/dwarfs/entry_factory.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/**
|
||||
* \author Marcus Holland-Moritz (github@mhxnet.de)
|
||||
* \copyright Copyright (c) Marcus Holland-Moritz
|
||||
*
|
||||
* This file is part of dwarfs.
|
||||
*
|
||||
* dwarfs is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* dwarfs is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
|
||||
namespace dwarfs {
|
||||
|
||||
class os_access;
|
||||
|
||||
namespace internal {
|
||||
|
||||
class entry;
|
||||
|
||||
} // namespace internal
|
||||
|
||||
class entry_factory {
|
||||
public:
|
||||
entry_factory();
|
||||
|
||||
std::shared_ptr<internal::entry>
|
||||
create(os_access const& os, std::filesystem::path const& path,
|
||||
std::shared_ptr<internal::entry> parent = nullptr) {
|
||||
return impl_->create(os, path, parent);
|
||||
}
|
||||
|
||||
class impl {
|
||||
public:
|
||||
virtual ~impl() = default;
|
||||
|
||||
virtual std::shared_ptr<internal::entry>
|
||||
create(os_access const& os, std::filesystem::path const& path,
|
||||
std::shared_ptr<internal::entry> parent) = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
std::unique_ptr<impl> impl_;
|
||||
};
|
||||
|
||||
} // namespace dwarfs
|
@ -25,7 +25,7 @@
|
||||
|
||||
namespace dwarfs {
|
||||
|
||||
class entry;
|
||||
class entry_interface;
|
||||
|
||||
enum class debug_filter_mode {
|
||||
OFF,
|
||||
@ -37,7 +37,7 @@ enum class debug_filter_mode {
|
||||
ALL
|
||||
};
|
||||
|
||||
void debug_filter_output(std::ostream& os, bool exclude, entry const* pe,
|
||||
debug_filter_mode mode);
|
||||
void debug_filter_output(std::ostream& os, bool exclude,
|
||||
entry_interface const& ei, debug_filter_mode mode);
|
||||
|
||||
} // namespace dwarfs
|
||||
|
@ -26,10 +26,10 @@
|
||||
|
||||
namespace dwarfs {
|
||||
|
||||
class file;
|
||||
|
||||
namespace internal {
|
||||
|
||||
class file;
|
||||
|
||||
class chunkable {
|
||||
public:
|
||||
virtual ~chunkable() = default;
|
||||
|
@ -46,21 +46,19 @@ class metadata;
|
||||
|
||||
} // namespace thrift::metadata
|
||||
|
||||
class file;
|
||||
class link;
|
||||
class dir;
|
||||
class device;
|
||||
class mmif;
|
||||
class os_access;
|
||||
|
||||
namespace internal {
|
||||
|
||||
class file;
|
||||
class link;
|
||||
class dir;
|
||||
class device;
|
||||
class global_entry_data;
|
||||
class inode;
|
||||
class progress;
|
||||
|
||||
} // namespace internal
|
||||
|
||||
class entry_visitor {
|
||||
public:
|
||||
virtual ~entry_visitor() = default;
|
||||
@ -92,10 +90,10 @@ class entry : public entry_interface {
|
||||
virtual void walk(std::function<void(entry*)> const& f);
|
||||
virtual void walk(std::function<void(const entry*)> const& f) const;
|
||||
void pack(thrift::metadata::inode_data& entry_v2,
|
||||
internal::global_entry_data const& data) const;
|
||||
void update(internal::global_entry_data& data) const;
|
||||
global_entry_data const& data) const;
|
||||
void update(global_entry_data& data) const;
|
||||
virtual void accept(entry_visitor& v, bool preorder = false) = 0;
|
||||
virtual void scan(os_access const& os, internal::progress& prog) = 0;
|
||||
virtual void scan(os_access const& os, progress& prog) = 0;
|
||||
file_stat const& status() const { return stat_; }
|
||||
void set_entry_index(uint32_t index) { entry_index_ = index; }
|
||||
std::optional<uint32_t> const& entry_index() const { return entry_index_; }
|
||||
@ -135,14 +133,14 @@ class file : public entry {
|
||||
|
||||
type_t type() const override;
|
||||
std::string_view hash() const;
|
||||
void set_inode(std::shared_ptr<internal::inode> ino);
|
||||
std::shared_ptr<internal::inode> get_inode() const;
|
||||
void set_inode(std::shared_ptr<inode> ino);
|
||||
std::shared_ptr<inode> get_inode() const;
|
||||
void accept(entry_visitor& v, bool preorder) override;
|
||||
void scan(os_access const& os, internal::progress& prog) override;
|
||||
void scan(mmif* mm, internal::progress& prog,
|
||||
std::optional<std::string> const& hash_alg);
|
||||
void scan(os_access const& os, progress& prog) override;
|
||||
void
|
||||
scan(mmif* mm, progress& prog, std::optional<std::string> const& hash_alg);
|
||||
void create_data();
|
||||
void hardlink(file* other, internal::progress& prog);
|
||||
void hardlink(file* other, progress& prog);
|
||||
uint32_t unique_file_id() const;
|
||||
|
||||
void set_inode_num(uint32_t ino) override;
|
||||
@ -163,7 +161,7 @@ class file : public entry {
|
||||
};
|
||||
|
||||
std::shared_ptr<data> data_;
|
||||
std::shared_ptr<internal::inode> inode_;
|
||||
std::shared_ptr<inode> inode_;
|
||||
};
|
||||
|
||||
class dir : public entry {
|
||||
@ -176,13 +174,13 @@ class dir : public entry {
|
||||
void walk(std::function<void(const entry*)> const& f) const override;
|
||||
void accept(entry_visitor& v, bool preorder) override;
|
||||
void sort();
|
||||
void pack(thrift::metadata::metadata& mv2,
|
||||
internal::global_entry_data const& data) const;
|
||||
void
|
||||
pack(thrift::metadata::metadata& mv2, global_entry_data const& data) const;
|
||||
void pack_entry(thrift::metadata::metadata& mv2,
|
||||
internal::global_entry_data const& data) const;
|
||||
void scan(os_access const& os, internal::progress& prog) override;
|
||||
global_entry_data const& data) const;
|
||||
void scan(os_access const& os, progress& prog) override;
|
||||
bool empty() const { return entries_.empty(); }
|
||||
void remove_empty_dirs(internal::progress& prog);
|
||||
void remove_empty_dirs(progress& prog);
|
||||
|
||||
void set_inode_num(uint32_t ino) override { inode_num_ = ino; }
|
||||
std::optional<uint32_t> const& inode_num() const override {
|
||||
@ -209,7 +207,7 @@ class link : public entry {
|
||||
type_t type() const override;
|
||||
const std::string& linkname() const;
|
||||
void accept(entry_visitor& v, bool preorder) override;
|
||||
void scan(os_access const& os, internal::progress& prog) override;
|
||||
void scan(os_access const& os, progress& prog) override;
|
||||
|
||||
void set_inode_num(uint32_t ino) override { inode_num_ = ino; }
|
||||
std::optional<uint32_t> const& inode_num() const override {
|
||||
@ -231,7 +229,7 @@ class device : public entry {
|
||||
|
||||
type_t type() const override;
|
||||
void accept(entry_visitor& v, bool preorder) override;
|
||||
void scan(os_access const& os, internal::progress& prog) override;
|
||||
void scan(os_access const& os, progress& prog) override;
|
||||
uint64_t device_id() const;
|
||||
|
||||
void set_inode_num(uint32_t ino) override { inode_num_ = ino; }
|
||||
@ -243,14 +241,6 @@ class device : public entry {
|
||||
std::optional<uint32_t> inode_num_;
|
||||
};
|
||||
|
||||
class entry_factory {
|
||||
public:
|
||||
static std::unique_ptr<entry_factory> create();
|
||||
} // namespace internal
|
||||
|
||||
virtual ~entry_factory() = default;
|
||||
|
||||
virtual std::shared_ptr<entry>
|
||||
create(os_access const& os, std::filesystem::path const& path,
|
||||
std::shared_ptr<entry> parent = nullptr) = 0;
|
||||
};
|
||||
} // namespace dwarfs
|
@ -28,7 +28,6 @@
|
||||
|
||||
namespace dwarfs {
|
||||
|
||||
class file;
|
||||
class logger;
|
||||
class os_access;
|
||||
class progress;
|
||||
@ -37,6 +36,7 @@ struct inode_options;
|
||||
|
||||
namespace internal {
|
||||
|
||||
class file;
|
||||
class inode_manager;
|
||||
class worker_group;
|
||||
|
||||
|
@ -41,7 +41,6 @@ namespace thrift::metadata {
|
||||
class chunk;
|
||||
}
|
||||
|
||||
class file;
|
||||
class mmif;
|
||||
class os_access;
|
||||
class progress;
|
||||
@ -50,6 +49,8 @@ struct inode_options;
|
||||
|
||||
namespace internal {
|
||||
|
||||
class file;
|
||||
|
||||
class inode : public object {
|
||||
public:
|
||||
using files_vector = small_vector<file*, 1>;
|
||||
|
@ -35,8 +35,6 @@
|
||||
|
||||
namespace dwarfs {
|
||||
|
||||
class file;
|
||||
class inode;
|
||||
class logger;
|
||||
class os_access;
|
||||
class progress;
|
||||
@ -46,6 +44,7 @@ struct inode_options;
|
||||
|
||||
namespace internal {
|
||||
|
||||
class file;
|
||||
class worker_group;
|
||||
|
||||
class inode_manager {
|
||||
|
@ -37,7 +37,7 @@
|
||||
namespace dwarfs {
|
||||
|
||||
class categorizer_manager;
|
||||
class entry;
|
||||
class entry_interface;
|
||||
|
||||
enum class mlock_mode { NONE, TRY, MUST };
|
||||
|
||||
@ -139,7 +139,8 @@ struct scanner_options {
|
||||
bool pack_symlinks_index{false};
|
||||
bool force_pack_string_tables{false};
|
||||
bool no_create_timestamp{false};
|
||||
std::optional<std::function<void(bool, entry const*)>> debug_filter_function;
|
||||
std::optional<std::function<void(bool, entry_interface const&)>>
|
||||
debug_filter_function;
|
||||
size_t num_segmenter_workers{1};
|
||||
bool enable_history{true};
|
||||
std::optional<std::vector<std::string>> command_line_arguments;
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <dwarfs/console_writer.h>
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/entry_interface.h>
|
||||
#include <dwarfs/lazy_value.h>
|
||||
#include <dwarfs/logger.h>
|
||||
@ -34,6 +33,7 @@
|
||||
#include <dwarfs/util.h>
|
||||
#include <dwarfs/writer_progress.h>
|
||||
|
||||
#include <dwarfs/internal/entry.h>
|
||||
#include <dwarfs/internal/progress.h>
|
||||
|
||||
namespace dwarfs {
|
||||
|
72
src/dwarfs/entry_factory.cpp
Normal file
72
src/dwarfs/entry_factory.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/**
|
||||
* \author Marcus Holland-Moritz (github@mhxnet.de)
|
||||
* \copyright Copyright (c) Marcus Holland-Moritz
|
||||
*
|
||||
* This file is part of dwarfs.
|
||||
*
|
||||
* dwarfs is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* dwarfs is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <dwarfs/entry_factory.h>
|
||||
#include <dwarfs/os_access.h>
|
||||
|
||||
#include <dwarfs/internal/entry.h>
|
||||
|
||||
namespace dwarfs {
|
||||
|
||||
namespace internal {
|
||||
|
||||
class entry_factory_ : public entry_factory::impl {
|
||||
public:
|
||||
std::shared_ptr<entry>
|
||||
create(os_access const& os, std::filesystem::path const& path,
|
||||
std::shared_ptr<entry> parent) override {
|
||||
// TODO: just use `path` directly (need to fix test helpers, tho)?
|
||||
std::filesystem::path p =
|
||||
parent ? parent->fs_path() / path.filename() : path;
|
||||
|
||||
auto st = os.symlink_info(p);
|
||||
|
||||
switch (st.type()) {
|
||||
case posix_file_type::regular:
|
||||
return std::make_shared<file>(path, std::move(parent), st);
|
||||
|
||||
case posix_file_type::directory:
|
||||
return std::make_shared<dir>(path, std::move(parent), st);
|
||||
|
||||
case posix_file_type::symlink:
|
||||
return std::make_shared<link>(path, std::move(parent), st);
|
||||
|
||||
case posix_file_type::character:
|
||||
case posix_file_type::block:
|
||||
case posix_file_type::fifo:
|
||||
case posix_file_type::socket:
|
||||
return std::make_shared<device>(path, std::move(parent), st);
|
||||
|
||||
default:
|
||||
// TODO: warn
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
entry_factory::entry_factory()
|
||||
: impl_(std::make_unique<internal::entry_factory_>()) {}
|
||||
|
||||
} // namespace dwarfs
|
@ -21,13 +21,13 @@
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/entry_interface.h>
|
||||
#include <dwarfs/filter_debug.h>
|
||||
|
||||
namespace dwarfs {
|
||||
|
||||
void debug_filter_output(std::ostream& os, bool exclude, entry const* pe,
|
||||
debug_filter_mode mode) {
|
||||
void debug_filter_output(std::ostream& os, bool exclude,
|
||||
entry_interface const& ei, debug_filter_mode mode) {
|
||||
if (exclude ? mode == debug_filter_mode::INCLUDED or
|
||||
mode == debug_filter_mode::INCLUDED_FILES
|
||||
: mode == debug_filter_mode::EXCLUDED or
|
||||
@ -39,7 +39,7 @@ void debug_filter_output(std::ostream& os, bool exclude, entry const* pe,
|
||||
mode == debug_filter_mode::INCLUDED_FILES or
|
||||
mode == debug_filter_mode::EXCLUDED_FILES;
|
||||
|
||||
if (files_only and pe->type() == entry::E_DIR) {
|
||||
if (files_only and ei.is_directory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ void debug_filter_output(std::ostream& os, bool exclude, entry const* pe,
|
||||
prefix = exclude ? "- " : "+ ";
|
||||
}
|
||||
|
||||
os << prefix << pe->unix_dpath() << "\n";
|
||||
os << prefix << ei.unix_dpath() << "\n";
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <dwarfs/checksum.h>
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/error.h>
|
||||
#include <dwarfs/file_type.h>
|
||||
#include <dwarfs/mmif.h>
|
||||
@ -34,6 +33,7 @@
|
||||
#include <dwarfs/os_access.h>
|
||||
#include <dwarfs/util.h>
|
||||
|
||||
#include <dwarfs/internal/entry.h>
|
||||
#include <dwarfs/internal/global_entry_data.h>
|
||||
#include <dwarfs/internal/inode.h>
|
||||
#include <dwarfs/internal/progress.h>
|
||||
@ -41,7 +41,7 @@
|
||||
|
||||
#include <dwarfs/gen-cpp2/metadata_types.h>
|
||||
|
||||
namespace dwarfs {
|
||||
namespace dwarfs::internal {
|
||||
|
||||
namespace {
|
||||
|
||||
@ -146,7 +146,7 @@ void entry::walk(std::function<void(entry*)> const& f) { f(this); }
|
||||
|
||||
void entry::walk(std::function<void(const entry*)> const& f) const { f(this); }
|
||||
|
||||
void entry::update(internal::global_entry_data& data) const {
|
||||
void entry::update(global_entry_data& data) const {
|
||||
data.add_uid(stat_.uid);
|
||||
data.add_gid(stat_.gid);
|
||||
data.add_mode(stat_.mode);
|
||||
@ -156,7 +156,7 @@ void entry::update(internal::global_entry_data& data) const {
|
||||
}
|
||||
|
||||
void entry::pack(thrift::metadata::inode_data& entry_v2,
|
||||
internal::global_entry_data const& data) const {
|
||||
global_entry_data const& data) const {
|
||||
entry_v2.mode_index() = data.get_mode_index(stat_.mode);
|
||||
entry_v2.owner_index() = data.get_uid_index(stat_.uid);
|
||||
entry_v2.group_index() = data.get_gid_index(stat_.gid);
|
||||
@ -196,7 +196,7 @@ std::string_view file::hash() const {
|
||||
return std::string_view(h.data(), h.size());
|
||||
}
|
||||
|
||||
void file::set_inode(std::shared_ptr<internal::inode> ino) {
|
||||
void file::set_inode(std::shared_ptr<inode> ino) {
|
||||
if (inode_) {
|
||||
DWARFS_THROW(runtime_error, "inode already set for file");
|
||||
}
|
||||
@ -204,28 +204,28 @@ void file::set_inode(std::shared_ptr<internal::inode> ino) {
|
||||
inode_ = std::move(ino);
|
||||
}
|
||||
|
||||
std::shared_ptr<internal::inode> file::get_inode() const { return inode_; }
|
||||
std::shared_ptr<inode> file::get_inode() const { return inode_; }
|
||||
|
||||
void file::accept(entry_visitor& v, bool) { v.visit(this); }
|
||||
|
||||
void file::scan(os_access const& /*os*/, internal::progress& /*prog*/) {
|
||||
void file::scan(os_access const& /*os*/, progress& /*prog*/) {
|
||||
DWARFS_THROW(runtime_error, "file::scan() without hash_alg is not used");
|
||||
}
|
||||
|
||||
void file::scan(mmif* mm, internal::progress& prog,
|
||||
void file::scan(mmif* mm, progress& prog,
|
||||
std::optional<std::string> const& hash_alg) {
|
||||
size_t s = size();
|
||||
|
||||
if (hash_alg) {
|
||||
internal::progress::scan_updater supd(prog.hash, s);
|
||||
progress::scan_updater supd(prog.hash, s);
|
||||
checksum cs(*hash_alg);
|
||||
|
||||
if (s > 0) {
|
||||
std::shared_ptr<internal::scanner_progress> pctx;
|
||||
std::shared_ptr<scanner_progress> pctx;
|
||||
auto const chunk_size = prog.hash.chunk_size.load();
|
||||
|
||||
if (s >= 4 * chunk_size) {
|
||||
pctx = prog.create_context<internal::scanner_progress>(
|
||||
pctx = prog.create_context<scanner_progress>(
|
||||
termcolor::MAGENTA, kHashContext, path_as_string(), s);
|
||||
}
|
||||
|
||||
@ -271,7 +271,7 @@ void file::create_data() {
|
||||
data_ = std::make_shared<data>();
|
||||
}
|
||||
|
||||
void file::hardlink(file* other, internal::progress& prog) {
|
||||
void file::hardlink(file* other, progress& prog) {
|
||||
assert(!data_);
|
||||
assert(other->data_);
|
||||
prog.hardlink_size += size();
|
||||
@ -327,10 +327,10 @@ void dir::sort() {
|
||||
});
|
||||
}
|
||||
|
||||
void dir::scan(os_access const&, internal::progress&) {}
|
||||
void dir::scan(os_access const&, progress&) {}
|
||||
|
||||
void dir::pack_entry(thrift::metadata::metadata& mv2,
|
||||
internal::global_entry_data const& data) const {
|
||||
global_entry_data const& data) const {
|
||||
auto& de = mv2.dir_entries()->emplace_back();
|
||||
de.name_index() = has_parent() ? data.get_name_index(name()) : 0;
|
||||
de.inode_num() = DWARFS_NOTHROW(inode_num().value());
|
||||
@ -338,7 +338,7 @@ void dir::pack_entry(thrift::metadata::metadata& mv2,
|
||||
}
|
||||
|
||||
void dir::pack(thrift::metadata::metadata& mv2,
|
||||
internal::global_entry_data const& data) const {
|
||||
global_entry_data const& data) const {
|
||||
thrift::metadata::directory d;
|
||||
if (has_parent()) {
|
||||
auto pd = std::dynamic_pointer_cast<dir>(parent());
|
||||
@ -360,7 +360,7 @@ void dir::pack(thrift::metadata::metadata& mv2,
|
||||
}
|
||||
}
|
||||
|
||||
void dir::remove_empty_dirs(internal::progress& prog) {
|
||||
void dir::remove_empty_dirs(progress& prog) {
|
||||
auto last = std::remove_if(entries_.begin(), entries_.end(),
|
||||
[&](std::shared_ptr<entry> const& e) {
|
||||
if (auto d = dynamic_cast<dir*>(e.get())) {
|
||||
@ -420,7 +420,7 @@ const std::string& link::linkname() const { return link_; }
|
||||
|
||||
void link::accept(entry_visitor& v, bool) { v.visit(this); }
|
||||
|
||||
void link::scan(os_access const& os, internal::progress& prog) {
|
||||
void link::scan(os_access const& os, progress& prog) {
|
||||
link_ = u8string_to_string(os.read_symlink(fs_path()).u8string());
|
||||
prog.original_size += size();
|
||||
prog.symlink_size += size();
|
||||
@ -438,47 +438,8 @@ entry::type_t device::type() const {
|
||||
|
||||
void device::accept(entry_visitor& v, bool) { v.visit(this); }
|
||||
|
||||
void device::scan(os_access const&, internal::progress&) {}
|
||||
void device::scan(os_access const&, progress&) {}
|
||||
|
||||
uint64_t device::device_id() const { return status().rdev; }
|
||||
|
||||
class entry_factory_ : public entry_factory {
|
||||
public:
|
||||
std::shared_ptr<entry>
|
||||
create(os_access const& os, std::filesystem::path const& path,
|
||||
std::shared_ptr<entry> parent) override {
|
||||
// TODO: just use `path` directly (need to fix test helpers, tho)?
|
||||
std::filesystem::path p =
|
||||
parent ? parent->fs_path() / path.filename() : path;
|
||||
|
||||
auto st = os.symlink_info(p);
|
||||
|
||||
switch (st.type()) {
|
||||
case posix_file_type::regular:
|
||||
return std::make_shared<file>(path, std::move(parent), st);
|
||||
|
||||
case posix_file_type::directory:
|
||||
return std::make_shared<dir>(path, std::move(parent), st);
|
||||
|
||||
case posix_file_type::symlink:
|
||||
return std::make_shared<link>(path, std::move(parent), st);
|
||||
|
||||
case posix_file_type::character:
|
||||
case posix_file_type::block:
|
||||
case posix_file_type::fifo:
|
||||
case posix_file_type::socket:
|
||||
return std::make_shared<device>(path, std::move(parent), st);
|
||||
|
||||
default:
|
||||
// TODO: warn
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<entry_factory> entry_factory::create() {
|
||||
return std::make_unique<entry_factory_>();
|
||||
}
|
||||
} // namespace dwarfs
|
||||
} // namespace dwarfs::internal
|
@ -33,7 +33,6 @@
|
||||
#include <range/v3/view/drop.hpp>
|
||||
|
||||
#include <dwarfs/checksum.h>
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/format.h>
|
||||
#include <dwarfs/logger.h>
|
||||
#include <dwarfs/mmif.h>
|
||||
@ -41,6 +40,7 @@
|
||||
#include <dwarfs/os_access.h>
|
||||
#include <dwarfs/util.h>
|
||||
|
||||
#include <dwarfs/internal/entry.h>
|
||||
#include <dwarfs/internal/file_scanner.h>
|
||||
#include <dwarfs/internal/inode.h>
|
||||
#include <dwarfs/internal/inode_manager.h>
|
||||
|
@ -22,10 +22,10 @@
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <dwarfs/categorizer.h>
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/inode_fragments.h>
|
||||
#include <dwarfs/mmif.h>
|
||||
|
||||
#include <dwarfs/internal/entry.h>
|
||||
#include <dwarfs/internal/fragment_chunkable.h>
|
||||
#include <dwarfs/internal/inode.h>
|
||||
|
||||
|
@ -23,8 +23,7 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <dwarfs/entry.h>
|
||||
|
||||
#include <dwarfs/internal/entry.h>
|
||||
#include <dwarfs/internal/inode.h>
|
||||
#include <dwarfs/internal/inode_element_view.h>
|
||||
|
||||
|
@ -42,7 +42,6 @@
|
||||
|
||||
#include <dwarfs/categorizer.h>
|
||||
#include <dwarfs/compiler.h>
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/error.h>
|
||||
#include <dwarfs/logger.h>
|
||||
#include <dwarfs/match.h>
|
||||
@ -52,6 +51,7 @@
|
||||
#include <dwarfs/script.h>
|
||||
#include <dwarfs/util.h>
|
||||
|
||||
#include <dwarfs/internal/entry.h>
|
||||
#include <dwarfs/internal/inode_manager.h>
|
||||
#include <dwarfs/internal/inode_ordering.h>
|
||||
#include <dwarfs/internal/nilsimsa.h>
|
||||
|
@ -21,10 +21,10 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/logger.h>
|
||||
#include <dwarfs/options.h>
|
||||
|
||||
#include <dwarfs/internal/entry.h>
|
||||
#include <dwarfs/internal/inode_element_view.h>
|
||||
#include <dwarfs/internal/inode_ordering.h>
|
||||
#include <dwarfs/internal/promise_receiver.h>
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <dwarfs/categorizer.h>
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/entry_factory.h>
|
||||
#include <dwarfs/error.h>
|
||||
#include <dwarfs/file_access.h>
|
||||
#include <dwarfs/filesystem_writer.h>
|
||||
@ -58,6 +58,7 @@
|
||||
|
||||
#include <dwarfs/internal/block_data.h>
|
||||
#include <dwarfs/internal/block_manager.h>
|
||||
#include <dwarfs/internal/entry.h>
|
||||
#include <dwarfs/internal/features.h>
|
||||
#include <dwarfs/internal/file_scanner.h>
|
||||
#include <dwarfs/internal/fragment_chunkable.h>
|
||||
@ -356,7 +357,7 @@ scanner_<LoggerPolicy>::add_entry(std::filesystem::path const& name,
|
||||
}
|
||||
|
||||
if (debug_filter) {
|
||||
(*options_.debug_filter_function)(exclude, pe.get());
|
||||
(*options_.debug_filter_function)(exclude, *pe);
|
||||
}
|
||||
|
||||
if (exclude) {
|
||||
|
@ -43,7 +43,6 @@
|
||||
|
||||
#include <dwarfs/compiler.h>
|
||||
#include <dwarfs/compression_constraints.h>
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/error.h>
|
||||
#include <dwarfs/logger.h>
|
||||
#include <dwarfs/segmenter.h>
|
||||
@ -54,6 +53,7 @@
|
||||
#include <dwarfs/internal/block_manager.h>
|
||||
#include <dwarfs/internal/chunkable.h>
|
||||
#include <dwarfs/internal/cyclic_hash.h>
|
||||
#include <dwarfs/internal/entry.h>
|
||||
#include <dwarfs/internal/progress.h>
|
||||
|
||||
namespace dwarfs {
|
||||
|
@ -66,7 +66,7 @@
|
||||
#include <dwarfs/chmod_entry_transformer.h>
|
||||
#include <dwarfs/console_writer.h>
|
||||
#include <dwarfs/conv.h>
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/entry_factory.h>
|
||||
#include <dwarfs/error.h>
|
||||
#include <dwarfs/file_access.h>
|
||||
#include <dwarfs/filesystem_block_category_resolver.h>
|
||||
@ -906,8 +906,8 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
|
||||
if (auto it = debug_filter_modes.find(debug_filter);
|
||||
it != debug_filter_modes.end()) {
|
||||
options.debug_filter_function =
|
||||
[&iol, mode = it->second](bool exclude, entry const* pe) {
|
||||
debug_filter_output(iol.out, exclude, pe, mode);
|
||||
[&iol, mode = it->second](bool exclude, entry_interface const& ei) {
|
||||
debug_filter_output(iol.out, exclude, ei, mode);
|
||||
};
|
||||
no_progress = true;
|
||||
} else {
|
||||
@ -1346,10 +1346,12 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
|
||||
auto sf = std::make_shared<segmenter_factory>(
|
||||
lgr, prog, options.inode.categorizer_mgr, sf_config);
|
||||
|
||||
auto ef = std::make_shared<entry_factory>();
|
||||
|
||||
thread_pool scanner_pool(lgr, *iol.os, "scanner", num_scanner_workers);
|
||||
|
||||
scanner s(lgr, scanner_pool, std::move(sf), entry_factory::create(),
|
||||
iol.os, std::move(script), options);
|
||||
scanner s(lgr, scanner_pool, std::move(sf), std::move(ef), iol.os,
|
||||
std::move(script), options);
|
||||
|
||||
s.scan(*fsw, path, prog, input_list, iol.file);
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <thrift/lib/cpp2/frozen/FrozenUtil.h>
|
||||
|
||||
#include <dwarfs/block_compressor.h>
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/entry_factory.h>
|
||||
#include <dwarfs/file_stat.h>
|
||||
#include <dwarfs/filesystem_v2.h>
|
||||
#include <dwarfs/filesystem_writer.h>
|
||||
@ -124,9 +124,10 @@ std::string make_filesystem(::benchmark::State const& state) {
|
||||
writer_progress prog;
|
||||
|
||||
auto sf = std::make_shared<segmenter_factory>(lgr, prog, cfg);
|
||||
auto ef = std::make_shared<entry_factory>();
|
||||
|
||||
scanner s(lgr, pool, sf, entry_factory::create(), os,
|
||||
std::make_shared<test::script_mock>(), options);
|
||||
scanner s(lgr, pool, sf, ef, os, std::make_shared<test::script_mock>(),
|
||||
options);
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#include <dwarfs/block_compressor.h>
|
||||
#include <dwarfs/builtin_script.h>
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/entry_factory.h>
|
||||
#include <dwarfs/file_stat.h>
|
||||
#include <dwarfs/file_type.h>
|
||||
#include <dwarfs/filesystem_v2.h>
|
||||
@ -95,8 +95,9 @@ build_dwarfs(logger& lgr, std::shared_ptr<test::os_access_mock> input,
|
||||
sf_cfg.bloom_filter_size.set_default(cfg.bloom_filter_size);
|
||||
|
||||
auto sf = std::make_shared<segmenter_factory>(lgr, *prog, sf_cfg);
|
||||
auto ef = std::make_shared<entry_factory>();
|
||||
|
||||
scanner s(lgr, pool, sf, entry_factory::create(), input, scr, options);
|
||||
scanner s(lgr, pool, sf, ef, input, scr, options);
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
@ -929,15 +930,17 @@ class filter_test
|
||||
|
||||
scanner_options options;
|
||||
options.remove_empty_dirs = false;
|
||||
options.debug_filter_function = [&](bool exclude, entry const* pe) {
|
||||
debug_filter_output(oss, exclude, pe, mode);
|
||||
options.debug_filter_function = [&](bool exclude,
|
||||
entry_interface const& ei) {
|
||||
debug_filter_output(oss, exclude, ei, mode);
|
||||
};
|
||||
|
||||
writer_progress prog;
|
||||
thread_pool pool(lgr, *input, "worker", 1);
|
||||
auto sf = std::make_shared<segmenter_factory>(lgr, prog,
|
||||
segmenter_factory::config{});
|
||||
scanner s(lgr, pool, sf, entry_factory::create(), input, scr, options);
|
||||
auto ef = std::make_shared<entry_factory>();
|
||||
scanner s(lgr, pool, sf, ef, input, scr, options);
|
||||
|
||||
block_compressor bc("null");
|
||||
std::ostringstream null;
|
||||
|
@ -21,7 +21,9 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <dwarfs/entry.h>
|
||||
#include <dwarfs/entry_factory.h>
|
||||
|
||||
#include <dwarfs/internal/entry.h>
|
||||
|
||||
#include "test_helpers.h"
|
||||
|
||||
@ -37,11 +39,11 @@ struct entry_test : public ::testing::Test {
|
||||
#endif
|
||||
(1, fs::path::preferred_separator)};
|
||||
std::shared_ptr<test::os_access_mock> os;
|
||||
std::unique_ptr<entry_factory> ef;
|
||||
std::optional<entry_factory> ef;
|
||||
|
||||
void SetUp() override {
|
||||
os = test::os_access_mock::create_test_instance();
|
||||
ef = entry_factory::create();
|
||||
ef.emplace();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
@ -51,6 +53,8 @@ struct entry_test : public ::testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(entry_test, path) {
|
||||
using entry = internal::entry;
|
||||
|
||||
auto e1 = ef->create(*os, sep);
|
||||
auto e2 = ef->create(*os, fs::path("somelink"), e1);
|
||||
auto e3 = ef->create(*os, fs::path("somedir"), e1);
|
||||
|
@ -42,7 +42,7 @@ class bench_chunkable : public dwarfs::internal::chunkable {
|
||||
bench_chunkable(std::vector<uint8_t> data)
|
||||
: data_{std::move(data)} {}
|
||||
|
||||
dwarfs::file const* get_file() const override { return nullptr; }
|
||||
dwarfs::internal::file const* get_file() const override { return nullptr; }
|
||||
|
||||
size_t size() const override { return data_.size(); }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user