base: TemporaryDir add DoNotRemove() method
Recursively delete all contents in a temporary directory in the
destructor. If the caller wants the contents preserved, then
call DoNotRemove().
Test: compile
Bug: 119313545
Change-Id: I3601c06334920055a60dd3074b249824f4d6f510
diff --git a/file.cpp b/file.cpp
index 7a14711..d5bb7fe 100644
--- a/file.cpp
+++ b/file.cpp
@@ -134,6 +134,8 @@
}
TemporaryDir::~TemporaryDir() {
+ if (!remove_dir_and_contents_) return;
+
auto callback = [](const char* child, const struct stat*, int file_type, struct FTW*) -> int {
switch (file_type) {
case FTW_D: