Bug 1139173 - ipc/chromium: Remove unused functions from file_util. r=froydnj
authorFelix Janda <felix.janda@posteo.de>
Wed, 15 Apr 2015 23:59:44 +0200
changeset 240369 9b6b694dd82e1a3f7652c35d3e8b264d701ec253
parent 240368 1e75c69141cadfd8ea35f5f60e32cb7320d297ab
child 240370 f996215427273ee9a9a7c7c36230a4c6b2777e87
push id12522
push userryanvm@gmail.com
push dateWed, 22 Apr 2015 19:35:40 +0000
treeherderfx-team@9b6b694dd82e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1139173
milestone40.0a1
Bug 1139173 - ipc/chromium: Remove unused functions from file_util. r=froydnj CLOSED TREE
ipc/chromium/src/base/file_util.cc
ipc/chromium/src/base/file_util.h
ipc/chromium/src/base/file_util_posix.cc
ipc/chromium/src/base/file_util_win.cc
ipc/chromium/src/base/shared_memory_posix.cc
--- a/ipc/chromium/src/base/file_util.cc
+++ b/ipc/chromium/src/base/file_util.cc
@@ -134,22 +134,16 @@ void AppendToPath(std::wstring* path, co
     NOTREACHED();
     return;  // Don't crash in this function in release builds.
   }
 
   if (!EndsWithSeparator(path))
     path->push_back(FilePath::kSeparators[0]);
   path->append(new_ending);
 }
-bool CopyDirectory(const std::wstring& from_path, const std::wstring& to_path,
-                   bool recursive) {
-  return CopyDirectory(FilePath::FromWStringHack(from_path),
-                       FilePath::FromWStringHack(to_path),
-                       recursive);
-}
 bool CopyFile(const std::wstring& from_path, const std::wstring& to_path) {
   return CopyFile(FilePath::FromWStringHack(from_path),
                   FilePath::FromWStringHack(to_path));
 }
 bool CreateDirectory(const std::wstring& full_path) {
   return CreateDirectory(FilePath::FromWStringHack(full_path));
 }
 bool CreateNewTempDirectory(const std::wstring& prefix,
@@ -167,18 +161,18 @@ bool CreateNewTempDirectory(const std::w
 }
 bool CreateTemporaryFileName(std::wstring* temp_file) {
   FilePath temp_file_path;
   if (!CreateTemporaryFileName(&temp_file_path))
     return false;
   *temp_file = temp_file_path.ToWStringHack();
   return true;
 }
-bool Delete(const std::wstring& path, bool recursive) {
-  return Delete(FilePath::FromWStringHack(path), recursive);
+bool Delete(const std::wstring& path) {
+  return Delete(FilePath::FromWStringHack(path));
 }
 bool DirectoryExists(const std::wstring& path) {
   return DirectoryExists(FilePath::FromWStringHack(path));
 }
 bool EndsWithSeparator(std::wstring* path) {
   return EndsWithSeparator(FilePath::FromWStringHack(*path));
 }
 bool EndsWithSeparator(const std::wstring& path) {
--- a/ipc/chromium/src/base/file_util.h
+++ b/ipc/chromium/src/base/file_util.h
@@ -11,17 +11,16 @@
 #include "build/build_config.h"
 
 #if defined(OS_WIN)
 #include <windows.h>
 #elif defined(ANDROID)
 #include <sys/stat.h>
 #elif defined(OS_POSIX) 
 #include <sys/types.h>
-#include <fts.h>
 #include <sys/stat.h>
 #endif
 
 #include <stdio.h>
 
 #include <stack>
 #include <string>
 #include <vector>
@@ -82,44 +81,27 @@ void InsertBeforeExtension(std::wstring*
 void ReplaceExtension(std::wstring* file_name, const std::wstring& extension);
 #endif
 
 //-----------------------------------------------------------------------------
 // Functions that involve filesystem access or modification:
 
 // Deletes the given path, whether it's a file or a directory.
 // If it's a directory, it's perfectly happy to delete all of the
-// directory's contents.  Passing true to recursive deletes
-// subdirectories and their contents as well.
+// directory's contents.
 // Returns true if successful, false otherwise.
-//
-// WARNING: USING THIS WITH recursive==true IS EQUIVALENT
-//          TO "rm -rf", SO USE WITH CAUTION.
-bool Delete(const FilePath& path, bool recursive);
+bool Delete(const FilePath& path);
 // Deprecated temporary compatibility function.
-bool Delete(const std::wstring& path, bool recursive);
+bool Delete(const std::wstring& path);
 
 // Copies a single file. Use CopyDirectory to copy directories.
 bool CopyFile(const FilePath& from_path, const FilePath& to_path);
 // Deprecated temporary compatibility function.
 bool CopyFile(const std::wstring& from_path, const std::wstring& to_path);
 
-// Copies the given path, and optionally all subdirectories and their contents
-// as well.
-// If there are files existing under to_path, always overwrite.
-// Returns true if successful, false otherwise.
-// Dont't use wildcards on the names, it may stop working without notice.
-//
-// If you only need to copy a file use CopyFile, it's faster.
-bool CopyDirectory(const FilePath& from_path, const FilePath& to_path,
-                   bool recursive);
-// Deprecated temporary compatibility function.
-bool CopyDirectory(const std::wstring& from_path, const std::wstring& to_path,
-                   bool recursive);
-
 // Returns true if the given path exists on the local filesystem,
 // false otherwise.
 bool PathExists(const FilePath& path);
 // Deprecated temporary compatibility function.
 bool PathExists(const std::wstring& path);
 
 // Returns true if the given path is writable by the user, false otherwise.
 bool PathIsWritable(const FilePath& path);
--- a/ipc/chromium/src/base/file_util_posix.cc
+++ b/ipc/chromium/src/base/file_util_posix.cc
@@ -3,19 +3,16 @@
 // found in the LICENSE file.
 
 #include "base/file_util.h"
 
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <fnmatch.h>
-#ifndef ANDROID
-#include <fts.h>
-#endif
 #include <libgen.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <sys/mman.h>
 #define _DARWIN_USE_64_BIT_INODE // Use 64-bit inode data structures
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -48,195 +45,29 @@ bool AbsolutePath(FilePath* path) {
   *path = FilePath(full_path);
   return true;
 }
 
 // TODO(erikkay): The Windows version of this accepts paths like "foo/bar/*"
 // which works both with and without the recursive flag.  I'm not sure we need
 // that functionality. If not, remove from file_util_win.cc, otherwise add it
 // here.
-bool Delete(const FilePath& path, bool recursive) {
+bool Delete(const FilePath& path) {
   const char* path_str = path.value().c_str();
   struct stat file_info;
   int test = stat(path_str, &file_info);
   if (test != 0) {
     // The Windows version defines this condition as success.
     bool ret = (errno == ENOENT || errno == ENOTDIR);
     return ret;
   }
   if (!S_ISDIR(file_info.st_mode))
     return (unlink(path_str) == 0);
-  if (!recursive)
-    return (rmdir(path_str) == 0);
 
-#ifdef ANDROID
-  // XXX Need ftsless impl for bionic
-  return false;
-#else
-  bool success = true;
-  int ftsflags = FTS_PHYSICAL | FTS_NOSTAT;
-  char top_dir[PATH_MAX];
-  if (base::strlcpy(top_dir, path_str,
-                    arraysize(top_dir)) >= arraysize(top_dir)) {
-    return false;
-  }
-  char* dir_list[2] = { top_dir, NULL };
-  FTS* fts = fts_open(dir_list, ftsflags, NULL);
-  if (fts) {
-    FTSENT* fts_ent = fts_read(fts);
-    while (success && fts_ent != NULL) {
-      switch (fts_ent->fts_info) {
-        case FTS_DNR:
-        case FTS_ERR:
-          // log error
-          success = false;
-          continue;
-          break;
-        case FTS_DP:
-          success = (rmdir(fts_ent->fts_accpath) == 0);
-          break;
-        case FTS_D:
-          break;
-        case FTS_NSOK:
-        case FTS_F:
-        case FTS_SL:
-        case FTS_SLNONE:
-          success = (unlink(fts_ent->fts_accpath) == 0);
-          break;
-        default:
-          DCHECK(false);
-          break;
-      }
-      fts_ent = fts_read(fts);
-    }
-    fts_close(fts);
-  }
-  return success;
-#endif
-}
-
-bool Move(const FilePath& from_path, const FilePath& to_path) {
-  if (rename(from_path.value().c_str(), to_path.value().c_str()) == 0)
-    return true;
-
-  if (!CopyDirectory(from_path, to_path, true))
-    return false;
-
-  Delete(from_path, true);
-  return true;
-}
-
-bool CopyDirectory(const FilePath& from_path,
-                   const FilePath& to_path,
-                   bool recursive) {
-  // Some old callers of CopyDirectory want it to support wildcards.
-  // After some discussion, we decided to fix those callers.
-  // Break loudly here if anyone tries to do this.
-  // TODO(evanm): remove this once we're sure it's ok.
-  DCHECK(to_path.value().find('*') == std::string::npos);
-  DCHECK(from_path.value().find('*') == std::string::npos);
-
-  char top_dir[PATH_MAX];
-  if (base::strlcpy(top_dir, from_path.value().c_str(),
-                    arraysize(top_dir)) >= arraysize(top_dir)) {
-    return false;
-  }
-
-#ifdef ANDROID
-  // XXX Need ftsless impl for bionic
-  return false;
-#else
-  char* dir_list[] = { top_dir, NULL };
-  FTS* fts = fts_open(dir_list, FTS_PHYSICAL | FTS_NOSTAT, NULL);
-  if (!fts) {
-    CHROMIUM_LOG(ERROR) << "fts_open failed: " << strerror(errno);
-    return false;
-  }
-
-  int error = 0;
-  FTSENT* ent;
-  while (!error && (ent = fts_read(fts)) != NULL) {
-    // ent->fts_path is the source path, including from_path, so paste
-    // the suffix after from_path onto to_path to create the target_path.
-    std::string suffix(&ent->fts_path[from_path.value().size()]);
-    // Strip the leading '/' (if any).
-    if (!suffix.empty()) {
-      DCHECK_EQ('/', suffix[0]);
-      suffix.erase(0, 1);
-    }
-    const FilePath target_path = to_path.Append(suffix);
-    switch (ent->fts_info) {
-      case FTS_D:  // Preorder directory.
-        // If we encounter a subdirectory in a non-recursive copy, prune it
-        // from the traversal.
-        if (!recursive && ent->fts_level > 0) {
-          if (fts_set(fts, ent, FTS_SKIP) != 0)
-            error = errno;
-          continue;
-        }
-
-        // Try creating the target dir, continuing on it if it exists already.
-        // Rely on the user's umask to produce correct permissions.
-        if (mkdir(target_path.value().c_str(), 0777) != 0) {
-          if (errno != EEXIST)
-            error = errno;
-        }
-        break;
-      case FTS_F:     // Regular file.
-      case FTS_NSOK:  // File, no stat info requested.
-        errno = 0;
-        if (!CopyFile(FilePath(ent->fts_path), target_path))
-          error = errno ? errno : EINVAL;
-        break;
-      case FTS_DP:   // Postorder directory.
-      case FTS_DOT:  // "." or ".."
-        // Skip it.
-        continue;
-      case FTS_DC:   // Directory causing a cycle.
-        // Skip this branch.
-        if (fts_set(fts, ent, FTS_SKIP) != 0)
-          error = errno;
-        break;
-      case FTS_DNR:  // Directory cannot be read.
-      case FTS_ERR:  // Error.
-      case FTS_NS:   // Stat failed.
-        // Abort with the error.
-        error = ent->fts_errno;
-        break;
-      case FTS_SL:      // Symlink.
-      case FTS_SLNONE:  // Symlink with broken target.
-        CHROMIUM_LOG(WARNING) << "CopyDirectory() skipping symbolic link: " <<
-            ent->fts_path;
-        continue;
-      case FTS_DEFAULT:  // Some other sort of file.
-        CHROMIUM_LOG(WARNING) << "CopyDirectory() skipping file of unknown type: " <<
-            ent->fts_path;
-        continue;
-      default:
-        NOTREACHED();
-        continue;  // Hope for the best!
-    }
-  }
-  // fts_read may have returned NULL and set errno to indicate an error.
-  if (!error && errno != 0)
-    error = errno;
-
-  if (!fts_close(fts)) {
-    // If we already have an error, let's use that error instead of the error
-    // fts_close set.
-    if (!error)
-      error = errno;
-  }
-
-  if (error) {
-    CHROMIUM_LOG(ERROR) << "CopyDirectory(): " << strerror(error);
-    return false;
-  }
-  return true;
-#endif
+  return (rmdir(path_str) == 0);
 }
 
 bool PathExists(const FilePath& path) {
   struct stat file_info;
   return (stat(path.value().c_str(), &file_info) == 0);
 }
 
 bool PathIsWritable(const FilePath& path) {
--- a/ipc/chromium/src/base/file_util_win.cc
+++ b/ipc/chromium/src/base/file_util_win.cc
@@ -22,39 +22,38 @@ namespace file_util {
 bool AbsolutePath(FilePath* path) {
   wchar_t file_path_buf[MAX_PATH];
   if (!_wfullpath(file_path_buf, path->value().c_str(), MAX_PATH))
     return false;
   *path = FilePath(file_path_buf);
   return true;
 }
 
-bool Delete(const FilePath& path, bool recursive) {
+bool Delete(const FilePath& path) {
   if (path.value().length() >= MAX_PATH)
     return false;
 
-  // If we're not recursing use DeleteFile; it should be faster. DeleteFile
+  // Use DeleteFile; it should be faster. DeleteFile
   // fails if passed a directory though, which is why we fall through on
   // failure to the SHFileOperation.
-  if (!recursive && DeleteFile(path.value().c_str()) != 0)
+  if (DeleteFile(path.value().c_str()) != 0)
     return true;
 
   // SHFILEOPSTRUCT wants the path to be terminated with two NULLs,
   // so we have to use wcscpy because wcscpy_s writes non-NULLs
   // into the rest of the buffer.
   wchar_t double_terminated_path[MAX_PATH + 1] = {0};
 #pragma warning(suppress:4996)  // don't complain about wcscpy deprecation
   wcscpy(double_terminated_path, path.value().c_str());
 
   SHFILEOPSTRUCT file_operation = {0};
   file_operation.wFunc = FO_DELETE;
   file_operation.pFrom = double_terminated_path;
   file_operation.fFlags = FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION;
-  if (!recursive)
-    file_operation.fFlags |= FOF_NORECURSION | FOF_FILESONLY;
+  file_operation.fFlags |= FOF_NORECURSION | FOF_FILESONLY;
   int err = SHFileOperation(&file_operation);
   // Some versions of Windows return ERROR_FILE_NOT_FOUND when
   // deleting an empty directory.
   return (err == 0 || err == ERROR_FILE_NOT_FOUND);
 }
 
 bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
   // NOTE: I suspect we could support longer paths, but that would involve
@@ -93,36 +92,16 @@ bool ShellCopy(const FilePath& from_path
   file_operation.fFlags = FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION |
                           FOF_NOCONFIRMMKDIR;
   if (!recursive)
     file_operation.fFlags |= FOF_NORECURSION | FOF_FILESONLY;
 
   return (SHFileOperation(&file_operation) == 0);
 }
 
-bool CopyDirectory(const FilePath& from_path, const FilePath& to_path,
-                   bool recursive) {
-  if (recursive)
-    return ShellCopy(from_path, to_path, true);
-
-  // Instead of creating a new directory, we copy the old one to include the
-  // security information of the folder as part of the copy.
-  if (!PathExists(to_path)) {
-    // Except that Vista fails to do that, and instead do a recursive copy if
-    // the target directory doesn't exist.
-    if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA)
-      CreateDirectory(to_path);
-    else
-      ShellCopy(from_path, to_path, false);
-  }
-
-  FilePath directory = from_path.Append(L"*.*");
-  return ShellCopy(directory, to_path, false);
-}
-
 bool PathExists(const FilePath& path) {
   return (GetFileAttributes(path.value().c_str()) != INVALID_FILE_ATTRIBUTES);
 }
 
 bool PathIsWritable(const FilePath& path) {
   HANDLE dir =
       CreateFile(path.value().c_str(), FILE_ADD_FILE,
                  FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
--- a/ipc/chromium/src/base/shared_memory_posix.cc
+++ b/ipc/chromium/src/base/shared_memory_posix.cc
@@ -88,17 +88,17 @@ bool SharedMemory::Create(const std::str
 // In practice this call is only needed for unit tests.
 bool SharedMemory::Delete(const std::wstring& name) {
   std::wstring mem_filename;
   if (FilenameForMemoryName(name, &mem_filename) == false)
     return false;
 
   FilePath path(WideToUTF8(mem_filename));
   if (file_util::PathExists(path)) {
-    return file_util::Delete(path, false);
+    return file_util::Delete(path);
   }
 
   // Doesn't exist, so success.
   return true;
 }
 
 bool SharedMemory::Open(const std::wstring &name, bool read_only) {
   read_only_ = read_only;
@@ -165,17 +165,17 @@ bool SharedMemory::CreateOrOpen(const st
     DCHECK(posix_flags & (O_RDWR | O_WRONLY));
 
     FilePath path;
     fp = file_util::CreateAndOpenTemporaryShmemFile(&path);
 
     // Deleting the file prevents anyone else from mapping it in
     // (making it private), and prevents the need for cleanup (once
     // the last fd is closed, it is truly freed).
-    file_util::Delete(path, false);
+    file_util::Delete(path);
   } else {
     std::wstring mem_filename;
     if (FilenameForMemoryName(name, &mem_filename) == false)
       return false;
 
     std::string mode;
     switch (posix_flags) {
       case (O_RDWR | O_CREAT):