From 5726ee708fed1563be09e4aa446c56209cb4e1ba Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Tue, 16 Mar 2021 22:36:04 +0100 Subject: [PATCH] Cleanup --- src/dwarfs/filesystem_extractor.cpp | 6 +----- src/dwarfs/metadata_types.cpp | 6 ++++-- src/dwarfs/metadata_v2.cpp | 4 ---- test/dwarfs.cpp | 6 +++++- test/dwarfs_compat.cpp | 24 ++++++++++++------------ 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/dwarfs/filesystem_extractor.cpp b/src/dwarfs/filesystem_extractor.cpp index 7f288c36..82fa8874 100644 --- a/src/dwarfs/filesystem_extractor.cpp +++ b/src/dwarfs/filesystem_extractor.cpp @@ -197,11 +197,7 @@ void filesystem_extractor_::extract(filesystem_v2& fs, DWARFS_THROW(runtime_error, "getattr() failed"); } - auto path = entry.path(); - - DWARFS_CHECK(path[0] == '/', "path expected to start with /"); - - ::archive_entry_set_pathname(ae, path.c_str() + 1); // drop leading / + ::archive_entry_set_pathname(ae, entry.path().c_str()); ::archive_entry_copy_stat(ae, &stbuf); if (S_ISLNK(inode.mode())) { diff --git a/src/dwarfs/metadata_types.cpp b/src/dwarfs/metadata_types.cpp index 87233828..b0617f62 100644 --- a/src/dwarfs/metadata_types.cpp +++ b/src/dwarfs/metadata_types.cpp @@ -160,8 +160,10 @@ std::string dir_entry_view::path() const { void dir_entry_view::append_path_to(std::string& s) const { if (auto p = parent()) { - p->append_path_to(s); - s += '/'; + if (!p->is_root()) { + p->append_path_to(s); + s += '/'; + } } if (!is_root()) { s += name(); diff --git a/src/dwarfs/metadata_v2.cpp b/src/dwarfs/metadata_v2.cpp index 5327b11c..c21e0536 100644 --- a/src/dwarfs/metadata_v2.cpp +++ b/src/dwarfs/metadata_v2.cpp @@ -238,10 +238,6 @@ class metadata_ final : public metadata_v2::impl { return inode_view(meta_.entries()[index], inode, &meta_); } - dir_entry_view make_dir_entry_view(uint32_t self_index) const { - return dir_entry_view::from_dir_entry_index(self_index, &meta_); - } - dir_entry_view make_dir_entry_view(uint32_t self_index, uint32_t parent_index) const { return dir_entry_view::from_dir_entry_index(self_index, parent_index, diff --git a/test/dwarfs.cpp b/test/dwarfs.cpp index da02e0a8..4af9b2ac 100644 --- a/test/dwarfs.cpp +++ b/test/dwarfs.cpp @@ -458,7 +458,11 @@ void basic_end_to_end_test(std::string const& compressor, struct ::stat stbuf; ASSERT_EQ(0, fs.getattr(e.inode(), &stbuf)); inodes.push_back(stbuf.st_ino); - EXPECT_TRUE(entries.emplace(e.path(), stbuf).second); + auto path = e.path(); + if (!path.empty()) { + path = "/" + path; + } + EXPECT_TRUE(entries.emplace(path, stbuf).second); }); EXPECT_EQ(entries.size(), dwarfs::test::statmap.size() + 2 * with_devices + diff --git a/test/dwarfs_compat.cpp b/test/dwarfs_compat.cpp index 181dddc2..13f694dc 100644 --- a/test/dwarfs_compat.cpp +++ b/test/dwarfs_compat.cpp @@ -286,18 +286,18 @@ TEST_P(compat_filesystem, backwards_compat) { std::map ref_entries{ {"", make_stat(S_IFDIR | 0755, 8)}, - {"/bench.sh", make_stat(S_IFREG | 0644, 1517)}, - {"/dev", make_stat(S_IFDIR | 0755, 0)}, - {"/empty", make_stat(S_IFDIR | 0755, 1)}, - {"/empty/alsoempty", make_stat(S_IFDIR | 0755, 0)}, - {"/foo", make_stat(S_IFDIR | 0755, 3)}, - {"/foo/bad", make_stat(S_IFLNK | 0777, 6)}, - {"/foo/bar", make_stat(S_IFREG | 0644, 0)}, - {"/foo/bla.sh", make_stat(S_IFREG | 0644, 1517)}, - {"/foobar", make_stat(S_IFLNK | 0777, 7)}, - {"/format.sh", make_stat(S_IFREG | 0755, 94)}, - {"/perl-exec.sh", make_stat(S_IFREG | 0644, 87)}, - {"/test.py", make_stat(S_IFREG | 0644, 1012)}, + {"bench.sh", make_stat(S_IFREG | 0644, 1517)}, + {"dev", make_stat(S_IFDIR | 0755, 0)}, + {"empty", make_stat(S_IFDIR | 0755, 1)}, + {"empty/alsoempty", make_stat(S_IFDIR | 0755, 0)}, + {"foo", make_stat(S_IFDIR | 0755, 3)}, + {"foo/bad", make_stat(S_IFLNK | 0777, 6)}, + {"foo/bar", make_stat(S_IFREG | 0644, 0)}, + {"foo/bla.sh", make_stat(S_IFREG | 0644, 1517)}, + {"foobar", make_stat(S_IFLNK | 0777, 7)}, + {"format.sh", make_stat(S_IFREG | 0755, 94)}, + {"perl-exec.sh", make_stat(S_IFREG | 0644, 87)}, + {"test.py", make_stat(S_IFREG | 0644, 1012)}, }; for (auto mp : {&filesystem_v2::walk, &filesystem_v2::walk_inode_order}) {