From 623682af2f7cd0052a157f459d74b5ebc9cfb2fe Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Sun, 6 Oct 2024 13:06:16 -0700 Subject: [PATCH] fiemap_writer_test: add block truncation and sync for safety There is a delay to get inode evicted whic requires to deallocate blocks used by the previous test. Let's secure the pinned space as much as possible. Bug: 371822983 Change-Id: I4cc69fc61e348511bb027ca0a9dd277fffb20f7f Signed-off-by: Jaegeuk Kim --- fs_mgr/libfiemap/fiemap_writer_test.cpp | 6 +++++- fs_mgr/libfiemap/split_fiemap_writer.cpp | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fs_mgr/libfiemap/fiemap_writer_test.cpp b/fs_mgr/libfiemap/fiemap_writer_test.cpp index c37329c36..115f53e8e 100644 --- a/fs_mgr/libfiemap/fiemap_writer_test.cpp +++ b/fs_mgr/libfiemap/fiemap_writer_test.cpp @@ -66,7 +66,11 @@ class FiemapWriterTest : public ::testing::Test { testfile = gTestDir + "/"s + tinfo->name(); } - void TearDown() override { unlink(testfile.c_str()); } + void TearDown() override { + truncate(testfile.c_str(), 0); + unlink(testfile.c_str()); + sync(); + } // name of the file we use for testing std::string testfile; diff --git a/fs_mgr/libfiemap/split_fiemap_writer.cpp b/fs_mgr/libfiemap/split_fiemap_writer.cpp index 0df61253c..1f32d2f99 100644 --- a/fs_mgr/libfiemap/split_fiemap_writer.cpp +++ b/fs_mgr/libfiemap/split_fiemap_writer.cpp @@ -196,10 +196,13 @@ bool SplitFiemap::RemoveSplitFiles(const std::string& file_path, std::string* me if (access(file.c_str(), F_OK) != 0 && (errno == ENOENT || errno == ENAMETOOLONG)) { continue; } + truncate(file.c_str(), 0); ok &= android::base::RemoveFileIfExists(file, message); } } + truncate(file_path.c_str(), 0); ok &= android::base::RemoveFileIfExists(file_path, message); + sync(); return ok; }