Merge "fiemap_writer_test: add block truncation and sync for safety" into main
diff --git a/fs_mgr/libfiemap/fiemap_writer_test.cpp b/fs_mgr/libfiemap/fiemap_writer_test.cpp
index c37329c..115f53e 100644
--- a/fs_mgr/libfiemap/fiemap_writer_test.cpp
+++ b/fs_mgr/libfiemap/fiemap_writer_test.cpp
@@ -66,7 +66,11 @@
         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 0df6125..1f32d2f 100644
--- a/fs_mgr/libfiemap/split_fiemap_writer.cpp
+++ b/fs_mgr/libfiemap/split_fiemap_writer.cpp
@@ -196,10 +196,13 @@
             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;
 }