Skip to content

Commit

Permalink
Merge branch 'mhx:main' into maxirmx-sync-upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx authored Oct 17, 2023
2 parents 9ccc36d + 6d994de commit 7221a13
Show file tree
Hide file tree
Showing 19 changed files with 336 additions and 195 deletions.
13 changes: 4 additions & 9 deletions include/dwarfs/console_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace dwarfs {

class progress;

class console_writer : public logger {
class console_writer : public stream_logger {
public:
using get_term_width_type = std::function<size_t()>;

Expand All @@ -46,25 +46,20 @@ class console_writer : public logger {
get_term_width_type get_term_width, level_type threshold,
display_mode mode = NORMAL, bool verbose = false);

void write(level_type level, const std::string& output, char const* file,
int line) override;

void update(const progress& p, bool last);

private:
void preamble() override;
void postamble() override;
std::string_view get_newline() const override;
void rewind();

std::ostream& os_;
std::mutex mx_;
std::atomic<level_type> threshold_;
std::string statebuf_;
double frac_;
std::atomic<size_t> counter_{0};
progress_mode const pg_mode_;
get_term_width_type get_term_width_;
display_mode const mode_;
bool const color_;
bool const with_context_;
bool const debug_progress_;
bool writing_{false};
speedometer<uint64_t> read_speed_;
Expand Down
12 changes: 6 additions & 6 deletions include/dwarfs/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ class entry : public entry_interface {
virtual std::optional<uint32_t> const& inode_num() const = 0;

// more methods from entry_interface
uint16_t get_permissions() const override;
void set_permissions(uint16_t perm) override;
uint16_t get_uid() const override;
void set_uid(uint16_t uid) override;
uint16_t get_gid() const override;
void set_gid(uint16_t gid) override;
mode_type get_permissions() const override;
void set_permissions(mode_type perm) override;
uid_type get_uid() const override;
void set_uid(uid_type uid) override;
gid_type get_gid() const override;
void set_gid(gid_type gid) override;
uint64_t get_atime() const override;
void set_atime(uint64_t atime) override;
uint64_t get_mtime() const override;
Expand Down
17 changes: 11 additions & 6 deletions include/dwarfs/entry_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@

#include <string>

#include "dwarfs/file_stat.h"
#include "dwarfs/object.h"

namespace dwarfs {

class entry_interface : public object {
public:
using uid_type = file_stat::uid_type;
using gid_type = file_stat::gid_type;
using mode_type = file_stat::mode_type;

virtual std::string path_as_string() const = 0;
virtual std::string dpath() const = 0;
virtual std::string unix_dpath() const = 0;
Expand All @@ -37,12 +42,12 @@ class entry_interface : public object {
virtual size_t size() const = 0;
virtual bool is_directory() const = 0;

virtual uint16_t get_permissions() const = 0;
virtual void set_permissions(uint16_t perm) = 0;
virtual uint16_t get_uid() const = 0;
virtual void set_uid(uint16_t uid) = 0;
virtual uint16_t get_gid() const = 0;
virtual void set_gid(uint16_t gid) = 0;
virtual mode_type get_permissions() const = 0;
virtual void set_permissions(mode_type perm) = 0;
virtual uid_type get_uid() const = 0;
virtual void set_uid(uid_type uid) = 0;
virtual gid_type get_gid() const = 0;
virtual void set_gid(gid_type gid) = 0;
virtual uint64_t get_atime() const = 0;
virtual void set_atime(uint64_t atime) = 0;
virtual uint64_t get_mtime() const = 0;
Expand Down
40 changes: 23 additions & 17 deletions include/dwarfs/global_entry_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,27 @@

#include <folly/container/F14Map.h>

#include "dwarfs/file_stat.h"

namespace dwarfs {

struct scanner_options;

class global_entry_data {
public:
using uid_type = file_stat::uid_type;
using gid_type = file_stat::gid_type;
using mode_type = file_stat::mode_type;

enum class timestamp_type { ATIME, MTIME, CTIME };

global_entry_data(scanner_options const& options)
: options_(options) {}

void add_uid(uint16_t uid);
void add_gid(uint16_t gid);
void add_uid(uid_type uid);
void add_gid(gid_type gid);

void add_mode(uint16_t mode) { add(mode, modes_, next_mode_index_); }
void add_mode(mode_type mode) { add(mode, modes_, next_mode_index_); }

void add_mtime(uint64_t time);
void add_atime(uint64_t time);
Expand All @@ -56,9 +62,9 @@ class global_entry_data {
index(symlinks_);
}

uint16_t get_uid_index(uint16_t uid) const;
uint16_t get_gid_index(uint16_t gid) const;
uint16_t get_mode_index(uint16_t mode) const;
size_t get_uid_index(uid_type uid) const;
size_t get_gid_index(gid_type gid) const;
size_t get_mode_index(mode_type mode) const;

uint32_t get_name_index(std::string const& name) const;
uint32_t get_symlink_table_entry(std::string const& link) const;
Expand All @@ -67,9 +73,9 @@ class global_entry_data {
uint64_t get_atime_offset(uint64_t time) const;
uint64_t get_ctime_offset(uint64_t time) const;

std::vector<uint16_t> get_uids() const;
std::vector<uint16_t> get_gids() const;
std::vector<uint16_t> get_modes() const;
std::vector<uid_type> get_uids() const;
std::vector<gid_type> get_gids() const;
std::vector<mode_type> get_modes() const;

std::vector<std::string> get_names() const;
std::vector<std::string> get_symlinks() const;
Expand All @@ -85,23 +91,23 @@ class global_entry_data {

static void index(map_type<std::string, uint32_t>& map);

void
add(uint16_t val, map_type<uint16_t, uint16_t>& map, uint16_t& next_index) {
template <typename T>
void add(T val, map_type<T, T>& map, T& next_index) {
if (map.emplace(val, next_index).second) {
++next_index;
}
}

uint64_t get_time_offset(uint64_t time) const;

map_type<uint16_t, uint16_t> uids_;
map_type<uint16_t, uint16_t> gids_;
map_type<uint16_t, uint16_t> modes_;
map_type<uid_type, uid_type> uids_;
map_type<gid_type, gid_type> gids_;
map_type<mode_type, mode_type> modes_;
map_type<std::string, uint32_t> names_;
map_type<std::string, uint32_t> symlinks_;
uint16_t next_uid_index_{0};
uint16_t next_gid_index_{0};
uint16_t next_mode_index_{0};
uid_type next_uid_index_{0};
gid_type next_gid_index_{0};
mode_type next_mode_index_{0};
uint64_t timestamp_base_{std::numeric_limits<uint64_t>::max()};
scanner_options const& options_;
};
Expand Down
16 changes: 14 additions & 2 deletions include/dwarfs/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,22 @@ class stream_logger : public logger {
void set_threshold(level_type threshold);
void set_with_context(bool with_context) { with_context_ = with_context; }

protected:
virtual void preamble();
virtual void postamble();
virtual std::string_view get_newline() const;

std::ostream& log_stream() const { return os_; }
std::mutex& log_mutex() const { return mx_; }
bool log_is_colored() const { return color_; }
level_type log_threshold() const { return threshold_.load(); }

private:
std::ostream& os_;
std::mutex mx_;
std::mutex mutable mx_;
std::atomic<level_type> threshold_;
bool const color_;
bool const enable_stack_trace_;
bool with_context_;
};

Expand Down Expand Up @@ -306,7 +317,8 @@ class log_proxy {
};

#define LOG_DETAIL_LEVEL(level, lgr, method) \
if (lgr.is_enabled_for(::dwarfs::logger::level)) \
if constexpr (std::decay_t<decltype(lgr)>::is_enabled_for( \
::dwarfs::logger::level)) \
lgr.method(__FILE__, __LINE__)

#define LOG_PROXY(policy, lgr) ::dwarfs::log_proxy<policy> log_(lgr)
Expand Down
11 changes: 8 additions & 3 deletions include/dwarfs/metadata_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <thrift/lib/cpp2/frozen/FrozenUtil.h>

#include "dwarfs/file_stat.h"
#include "dwarfs/file_type.h"
#include "dwarfs/string_table.h"

Expand Down Expand Up @@ -90,15 +91,19 @@ class inode_view
friend class dir_entry_view;

public:
uint16_t mode() const;
using uid_type = file_stat::uid_type;
using gid_type = file_stat::gid_type;
using mode_type = file_stat::mode_type;

mode_type mode() const;
posix_file_type::value type() const {
return posix_file_type::from_mode(mode());
}
bool is_regular_file() const { return type() == posix_file_type::regular; }
bool is_directory() const { return type() == posix_file_type::directory; }
bool is_symlink() const { return type() == posix_file_type::symlink; }
uint16_t getuid() const;
uint16_t getgid() const;
uid_type getuid() const;
gid_type getgid() const;
uint32_t inode_num() const { return inode_num_; }

private:
Expand Down
5 changes: 3 additions & 2 deletions include/dwarfs/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <iosfwd>
#include <optional>

#include "dwarfs/file_stat.h"
#include "dwarfs/types.h"

namespace dwarfs {
Expand Down Expand Up @@ -97,8 +98,8 @@ struct file_order_options {
struct scanner_options {
file_order_options file_order;
std::optional<std::string> file_hash_algorithm{"xxh3-128"};
std::optional<uint16_t> uid;
std::optional<uint16_t> gid;
std::optional<file_stat::uid_type> uid;
std::optional<file_stat::gid_type> gid;
std::optional<uint64_t> timestamp;
bool keep_all_times{false};
bool remove_empty_dirs{false};
Expand Down
2 changes: 2 additions & 0 deletions include/dwarfs/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ void shorten_path_string(std::string& path, char separator, size_t max_len);

std::filesystem::path canonical_path(std::filesystem::path p);

bool getenv_is_enabled(char const* var);

} // namespace dwarfs
Loading

0 comments on commit 7221a13

Please sign in to comment.