summaryrefslogtreecommitdiffstats
path: root/base/file_util_posix.cc
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-15 01:11:44 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-15 01:11:44 +0000
commitbc6a901f7d54c1307fcffc82181aedcf694470f7 (patch)
treeb24e0d6fb40364b695d95291cd4bf0f134f47afa /base/file_util_posix.cc
parent3c5edd42af2fab481784f122d00d75a2c28661b7 (diff)
downloadchromium_src-bc6a901f7d54c1307fcffc82181aedcf694470f7.zip
chromium_src-bc6a901f7d54c1307fcffc82181aedcf694470f7.tar.gz
chromium_src-bc6a901f7d54c1307fcffc82181aedcf694470f7.tar.bz2
More CopyDirectory tests and fixes
BUG=themes stopped working on Linux and Mac TEST=unittests Review URL: http://codereview.chromium.org/269083 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29076 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r--base/file_util_posix.cc35
1 files changed, 26 insertions, 9 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 3ba351e..f011580 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -170,6 +170,19 @@ bool Delete(const FilePath& path, bool recursive) {
}
bool Move(const FilePath& from_path, const FilePath& to_path) {
+ // Windows compatibility: if to_path exists, from_path and to_path
+ // must be the same type, either both files, or both directories.
+ stat_wrapper_t to_file_info;
+ if (CallStat(to_path.value().c_str(), &to_file_info) == 0) {
+ stat_wrapper_t from_file_info;
+ if (CallStat(from_path.value().c_str(), &from_file_info) == 0) {
+ if (S_ISDIR(to_file_info.st_mode) != S_ISDIR(from_file_info.st_mode))
+ return false;
+ } else {
+ return false;
+ }
+ }
+
if (rename(from_path.value().c_str(), to_path.value().c_str()) == 0)
return true;
@@ -228,22 +241,26 @@ bool CopyDirectory(const FilePath& from_path,
FileEnumerator traversal(from_path, recursive, traverse_type);
// We have to mimic windows behavior here. |to_path| may not exist yet,
- // start the loop with |to_path|. If this is a recursive copy and
- // the destination already exists, we have to copy the source directory
- // as well.
+ // start the loop with |to_path|.
FileEnumerator::FindInfo info;
FilePath current = from_path;
- FilePath from_path_base = from_path;
- if (recursive && stat(to_path.value().c_str(), &info.stat) == 0) {
- // If the destination already exists, then the top level of source
- // needs to be copied.
- from_path_base = from_path.DirName();
- }
if (stat(from_path.value().c_str(), &info.stat) < 0) {
LOG(ERROR) << "CopyDirectory() couldn't stat source directory: " <<
from_path.value() << " errno = " << errno;
success = false;
}
+ struct stat to_path_stat;
+ FilePath from_path_base = from_path;
+ if (recursive && stat(to_path.value().c_str(), &to_path_stat) == 0 &&
+ S_ISDIR(to_path_stat.st_mode)) {
+ // If the destination already exists and is a directory, then the
+ // top level of source needs to be copied.
+ from_path_base = from_path.DirName();
+ }
+
+ // The Windows version of this function assumes that non-recursive calls
+ // will always have a directory for from_path.
+ DCHECK(recursive || S_ISDIR(info.stat.st_mode));
while (success && !current.empty()) {
// current is the source path, including from_path, so paste