Merge "base: Add TemporaryFile::DoNotRemove()."

am: 04bf02374c

Change-Id: I414f7b2be3bc945d8ba829f388bc0dee10219c9c
This commit is contained in:
Yabin Cui 2018-03-09 19:46:15 +00:00 committed by android-build-merger
commit 8e7844d69e
2 changed files with 7 additions and 1 deletions

View File

@ -31,6 +31,8 @@ class TemporaryFile {
// 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 @@ class TemporaryFile {
private:
void init(const std::string& tmp_dir);
bool remove_file_ = true;
DISALLOW_COPY_AND_ASSIGN(TemporaryFile);
};

View File

@ -92,7 +92,9 @@ TemporaryFile::~TemporaryFile() {
if (fd != -1) {
close(fd);
}
unlink(path);
if (remove_file_) {
unlink(path);
}
}
int TemporaryFile::release() {