summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-12 23:57:27 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-12 23:57:27 +0000
commit19eef14a9c8d939a82fa262633927968a33daf6e (patch)
treeb5f5c188f49911cddf39a3edb8f18daaa76d5c88 /base
parent2f7f4d591192cfdebee227b72e3cf57c7c604450 (diff)
downloadchromium_src-19eef14a9c8d939a82fa262633927968a33daf6e.zip
chromium_src-19eef14a9c8d939a82fa262633927968a33daf6e.tar.gz
chromium_src-19eef14a9c8d939a82fa262633927968a33daf6e.tar.bz2
Convert a CopyRecursiveDirNoCache to use FilePaths instead
of wstrings. Also convert template_user_data_ in UITest to be a FilePath. Review URL: http://codereview.chromium.org/273021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28762 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/test/test_file_util.h4
-rw-r--r--base/test/test_file_util_posix.cc33
-rw-r--r--base/test/test_file_util_win.cc18
3 files changed, 25 insertions, 30 deletions
diff --git a/base/test/test_file_util.h b/base/test/test_file_util.h
index 3d2764e..e9e888e 100644
--- a/base/test/test_file_util.h
+++ b/base/test/test_file_util.h
@@ -28,8 +28,8 @@ bool EvictFileFromSystemCache(const FilePath& file);
//
// Returns true on success. False means there was some error copying, so the
// state of the destination is unknown.
-bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
- const std::wstring& dest_dir);
+bool CopyRecursiveDirNoCache(const FilePath& source_dir,
+ const FilePath& dest_dir);
} // namespace file_util
diff --git a/base/test/test_file_util_posix.cc b/base/test/test_file_util_posix.cc
index 096f3c6..8f7d69d 100644
--- a/base/test/test_file_util_posix.cc
+++ b/base/test/test_file_util_posix.cc
@@ -24,19 +24,16 @@ bool DieFileDie(const FilePath& file, bool recurse) {
}
// Mostly a verbatim copy of CopyDirectory
-bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
- const std::wstring& dest_dir) {
- const FilePath from_path(FilePath::FromWStringHack(source_dir));
- const FilePath to_path(FilePath::FromWStringHack(dest_dir));
-
+bool CopyRecursiveDirNoCache(const FilePath& source_dir,
+ const FilePath& dest_dir) {
char top_dir[PATH_MAX];
- if (base::strlcpy(top_dir, from_path.value().c_str(),
+ 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
- FilePath real_to_path = to_path;
+ FilePath real_to_path = dest_dir;
if (PathExists(real_to_path)) {
if (!AbsolutePath(&real_to_path))
return false;
@@ -45,35 +42,35 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
if (!AbsolutePath(&real_to_path))
return false;
}
- if (real_to_path.value().compare(0, from_path.value().size(),
- from_path.value()) == 0)
+ if (real_to_path.value().compare(0, source_dir.value().size(),
+ source_dir.value()) == 0)
return false;
bool success = true;
FileEnumerator::FILE_TYPE traverse_type =
static_cast<FileEnumerator::FILE_TYPE>(FileEnumerator::FILES |
FileEnumerator::SHOW_SYM_LINKS | FileEnumerator::DIRECTORIES);
- FileEnumerator traversal(from_path, true, traverse_type);
+ FileEnumerator traversal(source_dir, true, traverse_type);
- // to_path may not exist yet, start the loop with to_path
+ // dest_dir may not exist yet, start the loop with dest_dir
FileEnumerator::FindInfo info;
- FilePath current = from_path;
- if (stat(from_path.value().c_str(), &info.stat) < 0) {
+ FilePath current = source_dir;
+ if (stat(source_dir.value().c_str(), &info.stat) < 0) {
LOG(ERROR) << "CopyRecursiveDirNoCache() couldn't stat source directory: "
- << from_path.value() << " errno = " << errno;
+ << source_dir.value() << " errno = " << errno;
success = false;
}
while (success && !current.empty()) {
- // current 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(&current.value().c_str()[from_path.value().size()]);
+ // |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 FilePath target_path = to_path.Append(suffix);
+ const 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 &&
diff --git a/base/test/test_file_util_win.cc b/base/test/test_file_util_win.cc
index 4ebea54..e7bfce8 100644
--- a/base/test/test_file_util_win.cc
+++ b/base/test/test_file_util_win.cc
@@ -122,8 +122,8 @@ bool EvictFileFromSystemCache(const FilePath& file) {
// Like CopyFileNoCache but recursively copies all files and subdirectories
// in the given input directory to the output directory.
-bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
- const std::wstring& dest_dir) {
+bool CopyRecursiveDirNoCache(const FilePath& source_dir,
+ const FilePath& dest_dir) {
// Try to create the directory if it doesn't already exist.
if (!CreateDirectory(dest_dir)) {
if (GetLastError() != ERROR_ALREADY_EXISTS)
@@ -132,7 +132,7 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
std::vector<std::wstring> files_copied;
- std::wstring src(source_dir);
+ std::wstring src(source_dir.value());
file_util::AppendToPath(&src, L"*");
WIN32_FIND_DATA fd;
@@ -145,11 +145,8 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
if (cur_file == L"." || cur_file == L"..")
continue; // Skip these special entries.
- std::wstring cur_source_path(source_dir);
- file_util::AppendToPath(&cur_source_path, cur_file);
-
- std::wstring cur_dest_path(dest_dir);
- file_util::AppendToPath(&cur_dest_path, cur_file);
+ FilePath cur_source_path = source_dir.Append(cur_file);
+ FilePath cur_dest_path = dest_dir.Append(cur_file);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
// Recursively copy a subdirectory. We stripped "." and ".." already.
@@ -159,7 +156,8 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
}
} else {
// Copy the file.
- if (!::CopyFile(cur_source_path.c_str(), cur_dest_path.c_str(), false)) {
+ if (!::CopyFile(cur_source_path.value().c_str(),
+ cur_dest_path.value().c_str(), false)) {
FindClose(fh);
return false;
}
@@ -168,7 +166,7 @@ bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
// 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(FilePath::FromWStringHack(cur_dest_path));
+ EvictFileFromSystemCache(cur_dest_path);
}
} while (FindNextFile(fh, &fd));