diff --git a/src/dwarfs/builtin_script.cpp b/src/dwarfs/builtin_script.cpp index f0e00fd8..08017be1 100644 --- a/src/dwarfs/builtin_script.cpp +++ b/src/dwarfs/builtin_script.cpp @@ -190,6 +190,10 @@ void builtin_script_::set_root_path( std::filesystem::path const& path) { // TODO: this whole thing needs to be windowsized root_path_ = u8string_to_string(path.u8string()); + + if (root_path_ == "/") { + root_path_.clear(); + } } template @@ -252,7 +256,8 @@ bool builtin_script_::filter(entry_interface const& ei) { for (const auto& r : filter_) { if (std::regex_match(r.floating ? path : relpath, r.re)) { - LOG_TRACE << path << " matched rule '" << r.rule << "'"; + LOG_TRACE << "[" << path << "] / [" << relpath << "] matched rule '" + << r.rule << "'"; switch (r.type) { case filter_rule::rule_type::include: return true; @@ -263,7 +268,7 @@ bool builtin_script_::filter(entry_interface const& ei) { } } - LOG_TRACE << path << " matched no rule"; + LOG_TRACE << "[" << path << "] / [" << relpath << "] matched no rule"; return true; } diff --git a/test/tool_main_test.cpp b/test/tool_main_test.cpp index c264723a..4e5d8dd4 100644 --- a/test/tool_main_test.cpp +++ b/test/tool_main_test.cpp @@ -1591,6 +1591,19 @@ TEST(mkdwarfs_test, filter_recursion) { "recursion detected while opening file: filt1.txt")); } +TEST(mkdwarfs_test, filter_root_dir) { + auto t = mkdwarfs_tester::create_empty(); + t.add_test_file_tree(); + EXPECT_EQ(0, t.run({"-i", "/", "-o", "-", "-F", "- /var/", "-F", "- /usr/"})) + << t.err(); + auto fs = t.fs_from_stdout(); + EXPECT_TRUE(fs.find("/")); + EXPECT_FALSE(fs.find("/var")); + EXPECT_FALSE(fs.find("/usr")); + EXPECT_TRUE(fs.find("/dev")); + EXPECT_TRUE(fs.find("/etc")); +} + namespace { constexpr std::array const pack_mode_names = {