Remove test_utils::RecursiveUnlinkDir().

This test-only function has an equivalent implementation in libcrhome
so we remove it from update_engine and use the library version instead.

Bug: None
Test: FEATURES=test emerge-link update_engine

Change-Id: I3027c879d40461dbdf8b52dd1b65da0240549c9c
diff --git a/delta_performer_unittest.cc b/delta_performer_unittest.cc
index b177790..db19729 100644
--- a/delta_performer_unittest.cc
+++ b/delta_performer_unittest.cc
@@ -673,7 +673,7 @@
   install_plan_.public_key_rsa = "not-valid-base64";
   EXPECT_FALSE(performer_.GetPublicKeyFromResponse(&key_path));
 
-  EXPECT_TRUE(test_utils::RecursiveUnlinkDir(temp_dir));
+  EXPECT_TRUE(base::DeleteFile(base::FilePath(temp_dir), true));
 }
 
 TEST_F(DeltaPerformerTest, ConfVersionsMatch) {
diff --git a/fake_p2p_manager_configuration.h b/fake_p2p_manager_configuration.h
index 6874efb..8563d6e 100644
--- a/fake_p2p_manager_configuration.h
+++ b/fake_p2p_manager_configuration.h
@@ -25,6 +25,7 @@
 #include <vector>
 
 #include <base/logging.h>
+#include <base/files/file_util.h>
 #include <base/strings/string_util.h>
 #include <base/strings/string_number_conversions.h>
 
@@ -39,7 +40,8 @@
   }
 
   ~FakeP2PManagerConfiguration() {
-    if (p2p_dir_.size() > 0 && !test_utils::RecursiveUnlinkDir(p2p_dir_)) {
+    if (p2p_dir_.size() > 0 &&
+        !base::DeleteFile(base::FilePath(p2p_dir_), true)) {
       PLOG(ERROR) << "Unable to unlink files and directory in " << p2p_dir_;
     }
   }
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index a560bd2..268e4c2 100644
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -22,6 +22,7 @@
 #include <vector>
 
 #include <base/bind.h>
+#include <base/files/file_util.h>
 #include <base/strings/string_number_conversions.h>
 #include <base/strings/string_util.h>
 #include <base/strings/stringprintf.h>
@@ -1798,7 +1799,7 @@
       "version=\"0.0.0.0\" from_version=\"1.2.3.4\" "
       "track=\"stable-channel\" from_track=\"canary-channel\" "));
 
-  ASSERT_TRUE(test_utils::RecursiveUnlinkDir(test_dir));
+  ASSERT_TRUE(base::DeleteFile(base::FilePath(test_dir), true));
 }
 
 TEST_F(OmahaRequestActionTest, TestChangingToLessStableChannel) {
diff --git a/omaha_response_handler_action_unittest.cc b/omaha_response_handler_action_unittest.cc
index 52da375..5e62f45 100644
--- a/omaha_response_handler_action_unittest.cc
+++ b/omaha_response_handler_action_unittest.cc
@@ -18,6 +18,7 @@
 
 #include <string>
 
+#include <base/files/file_util.h>
 #include <gtest/gtest.h>
 
 #include "update_engine/constants.h"
@@ -354,7 +355,7 @@
   EXPECT_TRUE(DoTest(in, "", &install_plan));
   EXPECT_TRUE(install_plan.powerwash_required);
 
-  ASSERT_TRUE(test_utils::RecursiveUnlinkDir(test_dir));
+  ASSERT_TRUE(base::DeleteFile(base::FilePath(test_dir), true));
 }
 
 TEST_F(OmahaResponseHandlerActionTest, ChangeToLessStableChannelTest) {
@@ -396,7 +397,7 @@
   EXPECT_TRUE(DoTest(in, "", &install_plan));
   EXPECT_FALSE(install_plan.powerwash_required);
 
-  ASSERT_TRUE(test_utils::RecursiveUnlinkDir(test_dir));
+  ASSERT_TRUE(base::DeleteFile(base::FilePath(test_dir), true));
 }
 
 TEST_F(OmahaResponseHandlerActionTest, P2PUrlIsUsedAndHashChecksMandatory) {
diff --git a/test_utils.cc b/test_utils.cc
index abf91d3..036b729 100644
--- a/test_utils.cc
+++ b/test_utils.cc
@@ -258,63 +258,6 @@
   unmounter_.reset(new ScopedFilesystemUnmounter(*mnt_path));
 }
 
-namespace {
-class ScopedDirCloser {
- public:
-  explicit ScopedDirCloser(DIR** dir) : dir_(dir) {}
-  ~ScopedDirCloser() {
-    if (dir_ && *dir_) {
-      int r = closedir(*dir_);
-      TEST_AND_RETURN_ERRNO(r == 0);
-      *dir_ = nullptr;
-      dir_ = nullptr;
-    }
-  }
- private:
-  DIR** dir_;
-};
-}  // namespace
-
-bool RecursiveUnlinkDir(const string& path) {
-  struct stat stbuf;
-  int r = lstat(path.c_str(), &stbuf);
-  TEST_AND_RETURN_FALSE_ERRNO((r == 0) || (errno == ENOENT));
-  if ((r < 0) && (errno == ENOENT))
-    // path request is missing. that's fine.
-    return true;
-  if (!S_ISDIR(stbuf.st_mode)) {
-    TEST_AND_RETURN_FALSE_ERRNO((unlink(path.c_str()) == 0) ||
-                                (errno == ENOENT));
-    // success or path disappeared before we could unlink.
-    return true;
-  }
-  {
-    // We have a dir, unlink all children, then delete dir
-    DIR *dir = opendir(path.c_str());
-    TEST_AND_RETURN_FALSE_ERRNO(dir);
-    ScopedDirCloser dir_closer(&dir);
-    struct dirent dir_entry;
-    struct dirent *dir_entry_p;
-    int err = 0;
-    while ((err = readdir_r(dir, &dir_entry, &dir_entry_p)) == 0) {
-      if (dir_entry_p == nullptr) {
-        // end of stream reached
-        break;
-      }
-      // Skip . and ..
-      if (!strcmp(dir_entry_p->d_name, ".") ||
-          !strcmp(dir_entry_p->d_name, ".."))
-        continue;
-      TEST_AND_RETURN_FALSE(RecursiveUnlinkDir(path + "/" +
-                                               dir_entry_p->d_name));
-    }
-    TEST_AND_RETURN_FALSE(err == 0);
-  }
-  // unlink dir
-  TEST_AND_RETURN_FALSE_ERRNO((rmdir(path.c_str()) == 0) || (errno == ENOENT));
-  return true;
-}
-
 base::FilePath GetBuildArtifactsPath() {
   base::FilePath exe_path;
   base::ReadSymbolicLink(base::FilePath("/proc/self/exe"), &exe_path);
diff --git a/test_utils.h b/test_utils.h
index 9e2d4f7..91ebcd4 100644
--- a/test_utils.h
+++ b/test_utils.h
@@ -189,11 +189,6 @@
   std::unique_ptr<ScopedFilesystemUnmounter> unmounter_;
 };
 
-// Deletes a directory and all its contents synchronously. Returns true
-// on success. This may be called with a regular file--it will just unlink it.
-// This WILL cross filesystem boundaries.
-bool RecursiveUnlinkDir(const std::string& path);
-
 // Returns the path where the build artifacts are stored. This is the directory
 // where the unittest executable is being run from.
 base::FilePath GetBuildArtifactsPath();
diff --git a/test_utils_unittest.cc b/test_utils_unittest.cc
deleted file mode 100644
index 1bdf19e..0000000
--- a/test_utils_unittest.cc
+++ /dev/null
@@ -1,53 +0,0 @@
-//
-// Copyright (C) 2014 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-#include "update_engine/test_utils.h"
-
-#include <string>
-
-#include <gtest/gtest.h>
-
-using std::string;
-
-namespace chromeos_update_engine {
-namespace test_utils {
-
-class TestUtilsTest : public ::testing::Test { };
-
-TEST(UtilsTest, RecursiveUnlinkDirTest) {
-  string first_dir_name;
-  ASSERT_TRUE(utils::MakeTempDirectory("RecursiveUnlinkDirTest-a-XXXXXX",
-                                       &first_dir_name));
-  ASSERT_EQ(0, Chmod(first_dir_name, 0755));
-  string second_dir_name;
-  ASSERT_TRUE(utils::MakeTempDirectory("RecursiveUnlinkDirTest-b-XXXXXX",
-                                       &second_dir_name));
-  ASSERT_EQ(0, Chmod(second_dir_name, 0755));
-
-  EXPECT_EQ(0, Symlink(string("../") + first_dir_name,
-                       second_dir_name + "/link"));
-  EXPECT_EQ(0, System(string("echo hi > ") + second_dir_name + "/file"));
-  EXPECT_EQ(0, Mkdir(second_dir_name + "/dir", 0755));
-  EXPECT_EQ(0, System(string("echo ok > ") + second_dir_name + "/dir/subfile"));
-  EXPECT_TRUE(test_utils::RecursiveUnlinkDir(second_dir_name));
-  EXPECT_TRUE(utils::FileExists(first_dir_name.c_str()));
-  EXPECT_EQ(0, System(string("rm -rf ") + first_dir_name));
-  EXPECT_FALSE(utils::FileExists(second_dir_name.c_str()));
-  EXPECT_TRUE(test_utils::RecursiveUnlinkDir("/something/that/doesnt/exist"));
-}
-
-}  // namespace test_utils
-}  // namespace chromeos_update_engine
diff --git a/update_attempter_unittest.cc b/update_attempter_unittest.cc
index 31f75b6..c2318f0 100644
--- a/update_attempter_unittest.cc
+++ b/update_attempter_unittest.cc
@@ -163,7 +163,7 @@
   }
 
   void TearDown() override {
-    test_utils::RecursiveUnlinkDir(test_dir_);
+    base::DeleteFile(base::FilePath(test_dir_), true);
   }
 
  public:
diff --git a/update_engine.gyp b/update_engine.gyp
index 5a87790..5d229ec 100644
--- a/update_engine.gyp
+++ b/update_engine.gyp
@@ -435,7 +435,6 @@
             'subprocess_unittest.cc',
             'terminator_unittest.cc',
             'test_utils.cc',
-            'test_utils_unittest.cc',
             'update_attempter_unittest.cc',
             'update_manager/boxed_value_unittest.cc',
             'update_manager/chromeos_policy_unittest.cc',
diff --git a/utils_unittest.cc b/utils_unittest.cc
index a315e53..2bdb76b 100644
--- a/utils_unittest.cc
+++ b/utils_unittest.cc
@@ -103,7 +103,7 @@
   EXPECT_FALSE(utils::IsSymlink(temp_file.c_str()));
   EXPECT_TRUE(utils::IsSymlink(temp_symlink.c_str()));
   EXPECT_FALSE(utils::IsSymlink("/non/existent/path"));
-  EXPECT_TRUE(test_utils::RecursiveUnlinkDir(temp_dir));
+  EXPECT_TRUE(base::DeleteFile(base::FilePath(temp_dir), true));
 }
 
 TEST(UtilsTest, SplitPartitionNameTest) {