From cc7948aeb5fe21af08a2d5e868c0087ded0d244a Mon Sep 17 00:00:00 2001 From: "estade@chromium.org" Date: Fri, 13 Mar 2009 20:01:43 +0000 Subject: Implement DownloadFile::Rename() for posix. Downloads work on linux! Review URL: http://codereview.chromium.org/46020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11659 0039d316-1c4b-4281-b951-d872f2087c98 --- base/file_util.h | 4 +++- base/file_util_posix.cc | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'base') 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, -- cgit v1.1