diff options
author | Yabin Cui | 2018-03-08 19:03:04 -0600 |
---|---|---|
committer | Yabin Cui | 2018-03-08 19:59:36 -0600 |
commit | ef58cef98250305e6d629f3a307a74e45875b8dd (patch) | |
tree | 226c4221c6d349eca2e4ec158e8ce3d60d2f137a /base | |
parent | 929112bcd19e92c9b9f647d8a227ba55c743239d (diff) | |
download | platform-system-core-ef58cef98250305e6d629f3a307a74e45875b8dd.tar.gz platform-system-core-ef58cef98250305e6d629f3a307a74e45875b8dd.tar.xz platform-system-core-ef58cef98250305e6d629f3a307a74e45875b8dd.zip |
base: Add TemporaryFile::DoNotRemove().
Bug: http://b/73127105
Test: none.
Change-Id: I563c12bfb629ddd630568dda4817fb10cc9940a8
Diffstat (limited to 'base')
-rw-r--r-- | base/include/android-base/test_utils.h | 4 | ||||
-rw-r--r-- | base/test_utils.cpp | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/base/include/android-base/test_utils.h b/base/include/android-base/test_utils.h index 2edafe344..b95fa07ce 100644 --- a/base/include/android-base/test_utils.h +++ b/base/include/android-base/test_utils.h | |||
@@ -31,6 +31,8 @@ class TemporaryFile { | |||
31 | // Release the ownership of fd, caller is reponsible for closing the | 31 | // Release the ownership of fd, caller is reponsible for closing the |
32 | // fd or stream properly. | 32 | // fd or stream properly. |
33 | int release(); | 33 | int release(); |
34 | // Don't remove the temporary file in the destructor. | ||
35 | void DoNotRemove() { remove_file_ = false; } | ||
34 | 36 | ||
35 | int fd; | 37 | int fd; |
36 | char path[1024]; | 38 | char path[1024]; |
@@ -38,6 +40,8 @@ class TemporaryFile { | |||
38 | private: | 40 | private: |
39 | void init(const std::string& tmp_dir); | 41 | void init(const std::string& tmp_dir); |
40 | 42 | ||
43 | bool remove_file_ = true; | ||
44 | |||
41 | DISALLOW_COPY_AND_ASSIGN(TemporaryFile); | 45 | DISALLOW_COPY_AND_ASSIGN(TemporaryFile); |
42 | }; | 46 | }; |
43 | 47 | ||
diff --git a/base/test_utils.cpp b/base/test_utils.cpp index 9d8dfb2fd..1619c2134 100644 --- a/base/test_utils.cpp +++ b/base/test_utils.cpp | |||
@@ -92,7 +92,9 @@ TemporaryFile::~TemporaryFile() { | |||
92 | if (fd != -1) { | 92 | if (fd != -1) { |
93 | close(fd); | 93 | close(fd); |
94 | } | 94 | } |
95 | unlink(path); | 95 | if (remove_file_) { |
96 | unlink(path); | ||
97 | } | ||
96 | } | 98 | } |
97 | 99 | ||
98 | int TemporaryFile::release() { | 100 | int TemporaryFile::release() { |