summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/file_util.h4
-rw-r--r--base/file_util_posix.cc10
-rw-r--r--chrome/browser/download/download_file.cc18
3 files changed, 19 insertions, 13 deletions
diff --git a/base/file_util.h b/base/file_util.h
index 70e24e1..43c31f5 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -154,7 +154,9 @@ bool Delete(const FilePath& path, bool recursive);
bool Delete(const std::wstring& path, bool recursive);
// Moves the given path, whether it's a file or a directory.
-// Returns true if successful, false otherwise.
+// If a simple rename is not possible, such as in the case where the paths are
+// on different volumes, this will attempt to copy and delete. Returns
+// true for success.
bool Move(const FilePath& from_path, const FilePath& to_path);
// Deprecated temporary compatibility function.
bool Move(const std::wstring& from_path, const std::wstring& to_path);
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 85cdc10..235e6c0 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -107,8 +107,14 @@ bool Delete(const FilePath& path, bool recursive) {
}
bool Move(const FilePath& from_path, const FilePath& to_path) {
- return (rename(from_path.value().c_str(),
- to_path.value().c_str()) == 0);
+ 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,
diff --git a/chrome/browser/download/download_file.cc b/chrome/browser/download/download_file.cc
index 8a3444a..e70615a 100644
--- a/chrome/browser/download/download_file.cc
+++ b/chrome/browser/download/download_file.cc
@@ -89,17 +89,20 @@ void DownloadFile::Cancel() {
// The UI has provided us with our finalized name.
bool DownloadFile::Rename(const FilePath& new_path) {
-#if defined(OS_WIN)
Close();
+#if defined(OS_WIN)
// We cannot rename because rename will keep the same security descriptor
// on the destination file. We want to recreate the security descriptor
// with the security that makes sense in the new path.
- if (!file_util::RenameFileAndResetSecurityDescriptor(full_path_, new_path)) {
+ if (!file_util::RenameFileAndResetSecurityDescriptor(full_path_, new_path))
return false;
- }
-
- file_util::Delete(full_path_, false);
+#elif defined(OS_POSIX)
+ // TODO(estade): Move() falls back to copying and deleting when a simple
+ // rename fails. Copying sucks for large downloads. crbug.com/8737
+ if (!file_util::Move(full_path_, new_path))
+ return false;
+#endif
full_path_ = new_path;
path_renamed_ = true;
@@ -111,11 +114,6 @@ bool DownloadFile::Rename(const FilePath& new_path) {
if (!Open("a+b"))
return false;
return true;
-#elif defined(OS_POSIX)
- // TODO(port): Port this function to posix (we need file_util::Rename()).
- NOTIMPLEMENTED();
- return false;
-#endif
}
void DownloadFile::Close() {