Merge "base: Add TemporaryFile::DoNotRemove()."
am: 04bf02374c
Change-Id: I414f7b2be3bc945d8ba829f388bc0dee10219c9c
diff --git a/base/include/android-base/test_utils.h b/base/include/android-base/test_utils.h
index 2edafe3..b95fa07 100644
--- a/base/include/android-base/test_utils.h
+++ b/base/include/android-base/test_utils.h
@@ -31,6 +31,8 @@
// Release the ownership of fd, caller is reponsible for closing the
// fd or stream properly.
int release();
+ // Don't remove the temporary file in the destructor.
+ void DoNotRemove() { remove_file_ = false; }
int fd;
char path[1024];
@@ -38,6 +40,8 @@
private:
void init(const std::string& tmp_dir);
+ bool remove_file_ = true;
+
DISALLOW_COPY_AND_ASSIGN(TemporaryFile);
};
diff --git a/base/test_utils.cpp b/base/test_utils.cpp
index 9d8dfb2..1619c21 100644
--- a/base/test_utils.cpp
+++ b/base/test_utils.cpp
@@ -92,7 +92,9 @@
if (fd != -1) {
close(fd);
}
- unlink(path);
+ if (remove_file_) {
+ unlink(path);
+ }
}
int TemporaryFile::release() {