mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-08 20:12:56 -04:00
fix: --set-owner and --set-group did not work with non-zero ids
This commit is contained in:
parent
710b321ac5
commit
0a0be0ce6f
@ -36,11 +36,13 @@ std::vector<T> global_entry_data::get_vector(map_type<T, U> const& map) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto global_entry_data::get_uids() const -> std::vector<uid_type> {
|
auto global_entry_data::get_uids() const -> std::vector<uid_type> {
|
||||||
return get_vector(uids_);
|
return options_.uid ? std::vector<uid_type>{*options_.uid}
|
||||||
|
: get_vector(uids_);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto global_entry_data::get_gids() const -> std::vector<gid_type> {
|
auto global_entry_data::get_gids() const -> std::vector<gid_type> {
|
||||||
return get_vector(gids_);
|
return options_.gid ? std::vector<gid_type>{*options_.gid}
|
||||||
|
: get_vector(gids_);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto global_entry_data::get_modes() const -> std::vector<mode_type> {
|
auto global_entry_data::get_modes() const -> std::vector<mode_type> {
|
||||||
@ -85,11 +87,11 @@ uint64_t global_entry_data::get_timestamp_base() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t global_entry_data::get_uid_index(uid_type uid) const {
|
size_t global_entry_data::get_uid_index(uid_type uid) const {
|
||||||
return options_.uid ? *options_.uid : DWARFS_NOTHROW(uids_.at(uid));
|
return options_.uid ? 0 : DWARFS_NOTHROW(uids_.at(uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t global_entry_data::get_gid_index(gid_type gid) const {
|
size_t global_entry_data::get_gid_index(gid_type gid) const {
|
||||||
return options_.gid ? *options_.gid : DWARFS_NOTHROW(gids_.at(gid));
|
return options_.gid ? 0 : DWARFS_NOTHROW(gids_.at(gid));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t global_entry_data::get_mode_index(mode_type mode) const {
|
size_t global_entry_data::get_mode_index(mode_type mode) const {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
@ -540,6 +541,7 @@ uint32_t global_metadata::parent_dir_entry(uint32_t ino) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto inode_view::mode() const -> mode_type {
|
auto inode_view::mode() const -> mode_type {
|
||||||
|
assert(mode_index() < meta_->modes().size());
|
||||||
return meta_->modes()[mode_index()];
|
return meta_->modes()[mode_index()];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,10 +554,18 @@ auto inode_view::perm_string() const -> std::string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto inode_view::getuid() const -> uid_type {
|
auto inode_view::getuid() const -> uid_type {
|
||||||
|
if (meta_->uids().empty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
assert(owner_index() < meta_->uids().size());
|
||||||
return meta_->uids()[owner_index()];
|
return meta_->uids()[owner_index()];
|
||||||
}
|
}
|
||||||
|
|
||||||
auto inode_view::getgid() const -> gid_type {
|
auto inode_view::getgid() const -> gid_type {
|
||||||
|
if (meta_->gids().empty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
assert(group_index() < meta_->gids().size());
|
||||||
return meta_->gids()[group_index()];
|
return meta_->gids()[group_index()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,16 +191,16 @@ class mkdwarfs_tester {
|
|||||||
std::unique_ptr<logger> lgr;
|
std::unique_ptr<logger> lgr;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::optional<filesystem_v2>
|
std::tuple<std::optional<filesystem_v2>, mkdwarfs_tester>
|
||||||
build_with_args(std::vector<std::string> opt_args = {}) {
|
build_with_args(std::vector<std::string> opt_args = {}) {
|
||||||
std::string const image_file = "test.dwarfs";
|
std::string const image_file = "test.dwarfs";
|
||||||
mkdwarfs_tester t;
|
mkdwarfs_tester t;
|
||||||
std::vector<std::string> args = {"-i", "/", "-o", image_file};
|
std::vector<std::string> args = {"-i", "/", "-o", image_file};
|
||||||
args.insert(args.end(), opt_args.begin(), opt_args.end());
|
args.insert(args.end(), opt_args.begin(), opt_args.end());
|
||||||
if (t.run(args) != 0) {
|
if (t.run(args) != 0) {
|
||||||
return std::nullopt;
|
return {std::nullopt, std::move(t)};
|
||||||
}
|
}
|
||||||
return t.fs_from_file(image_file);
|
return {t.fs_from_file(image_file), std::move(t)};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<uint64_t> get_all_fs_times(filesystem_v2 const& fs) {
|
std::set<uint64_t> get_all_fs_times(filesystem_v2 const& fs) {
|
||||||
@ -215,6 +215,26 @@ std::set<uint64_t> get_all_fs_times(filesystem_v2 const& fs) {
|
|||||||
return times;
|
return times;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<uint64_t> get_all_fs_uids(filesystem_v2 const& fs) {
|
||||||
|
std::set<uint64_t> uids;
|
||||||
|
fs.walk([&](auto const& e) {
|
||||||
|
file_stat st;
|
||||||
|
fs.getattr(e.inode(), &st);
|
||||||
|
uids.insert(st.uid);
|
||||||
|
});
|
||||||
|
return uids;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<uint64_t> get_all_fs_gids(filesystem_v2 const& fs) {
|
||||||
|
std::set<uint64_t> gids;
|
||||||
|
fs.walk([&](auto const& e) {
|
||||||
|
file_stat st;
|
||||||
|
fs.getattr(e.inode(), &st);
|
||||||
|
gids.insert(st.gid);
|
||||||
|
});
|
||||||
|
return gids;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class mkdwarfs_main_test : public tool_main_test {
|
class mkdwarfs_main_test : public tool_main_test {
|
||||||
@ -527,12 +547,12 @@ TEST(mkdwarfs_test, set_time_now) {
|
|||||||
auto t0 =
|
auto t0 =
|
||||||
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||||
|
|
||||||
auto regfs = build_with_args();
|
auto [regfs, regt] = build_with_args();
|
||||||
ASSERT_TRUE(regfs);
|
ASSERT_TRUE(regfs) << regt.err();
|
||||||
auto reg = get_all_fs_times(*regfs);
|
auto reg = get_all_fs_times(*regfs);
|
||||||
|
|
||||||
auto optfs = build_with_args({"--set-time=now"});
|
auto [optfs, optt] = build_with_args({"--set-time=now"});
|
||||||
ASSERT_TRUE(optfs);
|
ASSERT_TRUE(optfs) << optt.err();
|
||||||
auto opt = get_all_fs_times(*optfs);
|
auto opt = get_all_fs_times(*optfs);
|
||||||
|
|
||||||
auto t1 =
|
auto t1 =
|
||||||
@ -546,12 +566,12 @@ TEST(mkdwarfs_test, set_time_now) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(mkdwarfs_test, set_time_epoch) {
|
TEST(mkdwarfs_test, set_time_epoch) {
|
||||||
auto regfs = build_with_args();
|
auto [regfs, regt] = build_with_args();
|
||||||
ASSERT_TRUE(regfs);
|
ASSERT_TRUE(regfs) << regt.err();
|
||||||
auto reg = get_all_fs_times(*regfs);
|
auto reg = get_all_fs_times(*regfs);
|
||||||
|
|
||||||
auto optfs = build_with_args({"--set-time=100000001"});
|
auto [optfs, optt] = build_with_args({"--set-time=100000001"});
|
||||||
ASSERT_TRUE(optfs);
|
ASSERT_TRUE(optfs) << optt.err();
|
||||||
auto opt = get_all_fs_times(*optfs);
|
auto opt = get_all_fs_times(*optfs);
|
||||||
|
|
||||||
EXPECT_EQ(reg.size(), 11);
|
EXPECT_EQ(reg.size(), 11);
|
||||||
@ -564,8 +584,8 @@ TEST(mkdwarfs_test, set_time_epoch_string) {
|
|||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
using std::chrono::sys_days;
|
using std::chrono::sys_days;
|
||||||
|
|
||||||
auto optfs = build_with_args({"--set-time", "2020-01-01 01:02"});
|
auto [optfs, optt] = build_with_args({"--set-time", "2020-01-01 01:02"});
|
||||||
ASSERT_TRUE(optfs);
|
ASSERT_TRUE(optfs) << optt.err();
|
||||||
auto opt = get_all_fs_times(*optfs);
|
auto opt = get_all_fs_times(*optfs);
|
||||||
|
|
||||||
ASSERT_EQ(opt.size(), 1);
|
ASSERT_EQ(opt.size(), 1);
|
||||||
@ -582,6 +602,36 @@ TEST(mkdwarfs_test, set_time_error) {
|
|||||||
EXPECT_THAT(t.err(), ::testing::HasSubstr("cannot parse time point"));
|
EXPECT_THAT(t.err(), ::testing::HasSubstr("cannot parse time point"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(mkdwarfs_test, set_owner) {
|
||||||
|
auto [regfs, regt] = build_with_args();
|
||||||
|
ASSERT_TRUE(regfs) << regt.err();
|
||||||
|
auto reg = get_all_fs_uids(*regfs);
|
||||||
|
|
||||||
|
auto [optfs, optt] = build_with_args({"--set-owner=333"});
|
||||||
|
ASSERT_TRUE(optfs) << optt.err();
|
||||||
|
auto opt = get_all_fs_uids(*optfs);
|
||||||
|
|
||||||
|
ASSERT_EQ(reg.size(), 2);
|
||||||
|
ASSERT_EQ(opt.size(), 1);
|
||||||
|
|
||||||
|
EXPECT_EQ(*opt.begin(), 333);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(mkdwarfs_test, set_group) {
|
||||||
|
auto [regfs, regt] = build_with_args();
|
||||||
|
ASSERT_TRUE(regfs) << regt.err();
|
||||||
|
auto reg = get_all_fs_gids(*regfs);
|
||||||
|
|
||||||
|
auto [optfs, optt] = build_with_args({"--set-group=444"});
|
||||||
|
ASSERT_TRUE(optfs) << optt.err();
|
||||||
|
auto opt = get_all_fs_gids(*optfs);
|
||||||
|
|
||||||
|
ASSERT_EQ(reg.size(), 2);
|
||||||
|
ASSERT_EQ(opt.size(), 1);
|
||||||
|
|
||||||
|
EXPECT_EQ(*opt.begin(), 444);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(mkdwarfs_test, unrecognized_arguments) {
|
TEST(mkdwarfs_test, unrecognized_arguments) {
|
||||||
auto t = mkdwarfs_tester::create_empty();
|
auto t = mkdwarfs_tester::create_empty();
|
||||||
EXPECT_NE(0, t.run({"grmpf"}));
|
EXPECT_NE(0, t.run({"grmpf"}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user