From baca1a8a1aa180c42de6278d3b8286c4496c6a10 Mon Sep 17 00:00:00 2001
From: Feng Xiao <xiaofeng@xiaofeng-macbookpro2.roam.corp.google.com>
Date: Fri, 7 Nov 2014 14:09:18 -0500
Subject: [PATCH] Adds more checks before deleting temporary files.

---
 .../protobuf/compiler/command_line_interface_unittest.cc      | 4 +++-
 src/google/protobuf/compiler/importer_unittest.cc             | 4 +++-
 src/google/protobuf/testing/file.cc                           | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc
index 6bf7357ba..5bc1fea95 100644
--- a/src/google/protobuf/compiler/command_line_interface_unittest.cc
+++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc
@@ -252,7 +252,9 @@ void CommandLineInterfaceTest::SetUp() {
 
 void CommandLineInterfaceTest::TearDown() {
   // Delete the temp directory.
-  File::DeleteRecursively(temp_directory_, NULL, NULL);
+  if (File::Exists(temp_directory_)) {
+    File::DeleteRecursively(temp_directory_, NULL, NULL);
+  }
 
   // Delete all the MockCodeGenerators.
   for (int i = 0; i < mock_generators_to_delete_.size(); i++) {
diff --git a/src/google/protobuf/compiler/importer_unittest.cc b/src/google/protobuf/compiler/importer_unittest.cc
index 387f135de..8cc5d882d 100644
--- a/src/google/protobuf/compiler/importer_unittest.cc
+++ b/src/google/protobuf/compiler/importer_unittest.cc
@@ -348,7 +348,9 @@ class DiskSourceTreeTest : public testing::Test {
 
   virtual void TearDown() {
     for (int i = 0; i < dirnames_.size(); i++) {
-      File::DeleteRecursively(dirnames_[i], NULL, NULL);
+      if (File::Exists(dirnames_[i])) {
+        File::DeleteRecursively(dirnames_[i], NULL, NULL);
+      }
     }
   }
 
diff --git a/src/google/protobuf/testing/file.cc b/src/google/protobuf/testing/file.cc
index 20e01a15e..5344ec15a 100644
--- a/src/google/protobuf/testing/file.cc
+++ b/src/google/protobuf/testing/file.cc
@@ -133,6 +133,8 @@ bool File::RecursivelyCreateDir(const string& path, int mode) {
 
 void File::DeleteRecursively(const string& name,
                              void* dummy1, void* dummy2) {
+  if (name.empty()) return;
+
   // We don't care too much about error checking here since this is only used
   // in tests to delete temporary directories that are under /tmp anyway.
 
-- 
2.18.0