summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/test/test_file_util.h9
-rw-r--r--base/test/test_file_util_posix.cc76
-rw-r--r--base/test/test_file_util_win.cc53
-rw-r--r--chrome/test/automation/proxy_launcher.cc26
-rw-r--r--chrome/test/perf/startup_test.cc6
5 files changed, 30 insertions, 140 deletions
diff --git a/base/test/test_file_util.h b/base/test/test_file_util.h
index 8d1be1c..c41045e 100644
--- a/base/test/test_file_util.h
+++ b/base/test/test_file_util.h
@@ -27,15 +27,6 @@ bool DieFileDie(const base::FilePath& file, bool recurse);
// to access this file will result in a cold load from the hard drive.
bool EvictFileFromSystemCache(const base::FilePath& file);
-// Like CopyFileNoCache but recursively copies all files and subdirectories
-// in the given input directory to the output directory. Any files in the
-// destination that already exist will be overwritten.
-//
-// Returns true on success. False means there was some error copying, so the
-// state of the destination is unknown.
-bool CopyRecursiveDirNoCache(const base::FilePath& source_dir,
- const base::FilePath& dest_dir);
-
#if defined(OS_WIN)
// Returns true if the volume supports Alternate Data Streams.
bool VolumeSupportsADS(const base::FilePath& path);
diff --git a/base/test/test_file_util_posix.cc b/base/test/test_file_util_posix.cc
index 6be1c82..ae61b24 100644
--- a/base/test/test_file_util_posix.cc
+++ b/base/test/test_file_util_posix.cc
@@ -78,82 +78,6 @@ bool DieFileDie(const base::FilePath& file, bool recurse) {
return file_util::Delete(file, recurse);
}
-// Mostly a verbatim copy of CopyDirectory
-bool CopyRecursiveDirNoCache(const base::FilePath& source_dir,
- const base::FilePath& dest_dir) {
- char top_dir[PATH_MAX];
- if (base::strlcpy(top_dir, source_dir.value().c_str(),
- arraysize(top_dir)) >= arraysize(top_dir)) {
- return false;
- }
-
- // This function does not properly handle destinations within the source
- base::FilePath real_to_path = dest_dir;
- if (PathExists(real_to_path)) {
- if (!AbsolutePath(&real_to_path))
- return false;
- } else {
- real_to_path = real_to_path.DirName();
- if (!AbsolutePath(&real_to_path))
- return false;
- }
- if (real_to_path.value().compare(0, source_dir.value().size(),
- source_dir.value()) == 0)
- return false;
-
- bool success = true;
- int traverse_type = FileEnumerator::FILES |
- FileEnumerator::SHOW_SYM_LINKS | FileEnumerator::DIRECTORIES;
- FileEnumerator traversal(source_dir, true, traverse_type);
-
- // dest_dir may not exist yet, start the loop with dest_dir
- FileEnumerator::FindInfo info;
- base::FilePath current = source_dir;
- if (stat(source_dir.value().c_str(), &info.stat) < 0) {
- DLOG(ERROR) << "CopyRecursiveDirNoCache() couldn't stat source directory: "
- << source_dir.value() << " errno = " << errno;
- success = false;
- }
-
- while (success && !current.empty()) {
- // |current| is the source path, including source_dir, so paste
- // the suffix after source_dir onto dest_dir to create the target_path.
- std::string suffix(&current.value().c_str()[source_dir.value().size()]);
- // Strip the leading '/' (if any).
- if (!suffix.empty()) {
- DCHECK_EQ('/', suffix[0]);
- suffix.erase(0, 1);
- }
- const base::FilePath target_path = dest_dir.Append(suffix);
-
- if (S_ISDIR(info.stat.st_mode)) {
- if (mkdir(target_path.value().c_str(), info.stat.st_mode & 01777) != 0 &&
- errno != EEXIST) {
- DLOG(ERROR) << "CopyRecursiveDirNoCache() couldn't create directory: "
- << target_path.value() << " errno = " << errno;
- success = false;
- }
- } else if (S_ISREG(info.stat.st_mode)) {
- if (CopyFile(current, target_path)) {
- success = EvictFileFromSystemCache(target_path);
- DCHECK(success);
- } else {
- DLOG(ERROR) << "CopyRecursiveDirNoCache() couldn't create file: "
- << target_path.value();
- success = false;
- }
- } else {
- DLOG(WARNING) << "CopyRecursiveDirNoCache() skipping non-regular file: "
- << current.value();
- }
-
- current = traversal.Next();
- traversal.GetFindInfo(&info);
- }
-
- return success;
-}
-
#if !defined(OS_LINUX) && !defined(OS_MACOSX)
bool EvictFileFromSystemCache(const base::FilePath& file) {
// There doesn't seem to be a POSIX way to cool the disk cache.
diff --git a/base/test/test_file_util_win.cc b/base/test/test_file_util_win.cc
index 8d28aef..8e130d8 100644
--- a/base/test/test_file_util_win.cc
+++ b/base/test/test_file_util_win.cc
@@ -216,59 +216,6 @@ bool EvictFileFromSystemCache(const base::FilePath& file) {
return true;
}
-// Like CopyFileNoCache but recursively copies all files and subdirectories
-// in the given input directory to the output directory.
-bool CopyRecursiveDirNoCache(const base::FilePath& source_dir,
- const base::FilePath& dest_dir) {
- // Try to create the directory if it doesn't already exist.
- if (!CreateDirectory(dest_dir)) {
- if (GetLastError() != ERROR_ALREADY_EXISTS)
- return false;
- }
-
- std::vector<std::wstring> files_copied;
-
- base::FilePath src(source_dir.AppendASCII("*"));
-
- WIN32_FIND_DATA fd;
- HANDLE fh = FindFirstFile(src.value().c_str(), &fd);
- if (fh == INVALID_HANDLE_VALUE)
- return false;
-
- do {
- std::wstring cur_file(fd.cFileName);
- if (cur_file == L"." || cur_file == L"..")
- continue; // Skip these special entries.
-
- base::FilePath cur_source_path = source_dir.Append(cur_file);
- base::FilePath cur_dest_path = dest_dir.Append(cur_file);
-
- if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
- // Recursively copy a subdirectory. We stripped "." and ".." already.
- if (!CopyRecursiveDirNoCache(cur_source_path, cur_dest_path)) {
- FindClose(fh);
- return false;
- }
- } else {
- // Copy the file.
- if (!::CopyFile(cur_source_path.value().c_str(),
- cur_dest_path.value().c_str(), false)) {
- FindClose(fh);
- return false;
- }
-
- // We don't check for errors from this function, often, we are copying
- // files that are in the repository, and they will have read-only set.
- // This will prevent us from evicting from the cache, but these don't
- // matter anyway.
- EvictFileFromSystemCache(cur_dest_path);
- }
- } while (FindNextFile(fh, &fd));
-
- FindClose(fh);
- return true;
-}
-
// Checks if the volume supports Alternate Data Streams. This is required for
// the Zone Identifier implementation.
bool VolumeSupportsADS(const base::FilePath& path) {
diff --git a/chrome/test/automation/proxy_launcher.cc b/chrome/test/automation/proxy_launcher.cc
index 98ba947..27abf39 100644
--- a/chrome/test/automation/proxy_launcher.cc
+++ b/chrome/test/automation/proxy_launcher.cc
@@ -39,6 +39,29 @@ namespace {
// Passed as value of kTestType.
const char kUITestType[] = "ui";
+// Copies the contents of the given source directory to the given dest
+// directory. This is somewhat different than CopyDirectory in base which will
+// copies "source/" to "dest/source/". This version will copy "source/*" to
+// "dest/*", overwriting existing files as necessary.
+bool CopyDirectoryContents(const base::FilePath& source,
+ const base::FilePath& dest) {
+ file_util::FileEnumerator en(source, false,
+ file_util::FileEnumerator::FILES |
+ file_util::FileEnumerator::DIRECTORIES);
+ for (base::FilePath cur = en.Next(); !cur.empty(); cur = en.Next()) {
+ file_util::FileEnumerator::FindInfo info;
+ en.GetFindInfo(&info);
+ if (file_util::FileEnumerator::IsDirectory(info)) {
+ if (!file_util::CopyDirectory(cur, dest, true))
+ return false;
+ } else {
+ if (!file_util::CopyFile(cur, dest.Append(cur.BaseName())))
+ return false;
+ }
+ }
+ return true;
+}
+
// We want to have a current history database when we start the browser so
// things like the NTP will have thumbnails. This method updates the dates
// in the history to be more recent.
@@ -186,8 +209,7 @@ bool ProxyLauncher::LaunchBrowser(const LaunchState& state) {
if (!state.template_user_data.empty()) {
// Recursively copy the template directory to the user_data_dir.
- if (!file_util::CopyRecursiveDirNoCache(
- state.template_user_data, user_data_dir())) {
+ if (!CopyDirectoryContents(state.template_user_data, user_data_dir())) {
LOG(ERROR) << "Failed to copy user data directory template.";
return false;
}
diff --git a/chrome/test/perf/startup_test.cc b/chrome/test/perf/startup_test.cc
index 75f3154..1d8243f 100644
--- a/chrome/test/perf/startup_test.cc
+++ b/chrome/test/perf/startup_test.cc
@@ -239,6 +239,12 @@ class StartupTest : public UIPerfTest {
dir_app.Append(FILE_PATH_LITERAL("chrome.dll")));
ASSERT_TRUE(EvictFileFromSystemCacheWrapper(chrome_dll));
#endif
+
+ // Kick out the profile files.
+ file_util::FileEnumerator en(user_data_dir(), true,
+ file_util::FileEnumerator::FILES);
+ for (base::FilePath cur = en.Next(); !cur.empty(); cur = en.Next())
+ EvictFileFromSystemCacheWrapper(cur);
}
UITest::SetUp();
TimeTicks end_time = TimeTicks::Now();