diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-12 05:17:15 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-12 05:17:15 +0000 |
commit | 154769362a046967efd14bb0a0da5d6f3a301e32 (patch) | |
tree | 33e4550cd4f8895b639fabc55b45f5bb6e8d67bc /base/file_util_posix.cc | |
parent | e7a810943e48e9649db8063058fb77ddefaf9f96 (diff) | |
download | chromium_src-154769362a046967efd14bb0a0da5d6f3a301e32.zip chromium_src-154769362a046967efd14bb0a0da5d6f3a301e32.tar.gz chromium_src-154769362a046967efd14bb0a0da5d6f3a301e32.tar.bz2 |
Move path functions from file_util to FilePath object.
EnsureEndsWithSeparator used to check whether the file existed. This seems bad and unnecessary so I removed it.
I removed file_util::ContainsPath and used the existing file_util::IsParent instead. The functions descriptions are the same but the implementations do slightly different things, which is worrying. The only non-test use of this function to worry about is content/browser/storage_partition_impl_map.cc. As far as I see, the requirements for this seem OK, but I'm not very familiar with this.
After some discussion with akalin, I changed sync/internal_api/sync_manager_impl.cc to be a DCHECK that the path is absolute rather than make it absolute. The old code relied on the behavior of the old function that the argument would be unchanged if the file didn't exist, and this (possibly relative) path would be used later. This behavior doesn't make a lot of sense, and it looks like now that the path is always absolute, so I replaced this call with a DCHECK.
BUG=
Review URL: https://codereview.chromium.org/13196006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r-- | base/file_util_posix.cc | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index 8bf164a..8b36812 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -59,6 +59,19 @@ #endif using base::FilePath; +using base::MakeAbsoluteFilePath; + +namespace base { + +FilePath MakeAbsoluteFilePath(const FilePath& input) { + base::ThreadRestrictions::AssertIOAllowed(); + char full_path[PATH_MAX]; + if (realpath(input.value().c_str(), full_path) == NULL) + return FilePath(); + return FilePath(full_path); +} + +} // namespace base namespace file_util { @@ -150,15 +163,6 @@ static std::string TempFileName() { #endif } -bool AbsolutePath(FilePath* path) { - base::ThreadRestrictions::AssertIOAllowed(); // For realpath(). - char full_path[PATH_MAX]; - if (realpath(path->value().c_str(), full_path) == NULL) - return false; - *path = FilePath(full_path); - return true; -} - // TODO(erikkay): The Windows version of this accepts paths like "foo/bar/*" // which works both with and without the recursive flag. I'm not sure we need // that functionality. If not, remove from file_util_win.cc, otherwise add it @@ -253,15 +257,16 @@ bool CopyDirectory(const FilePath& from_path, // This function does not properly handle destinations within the source FilePath real_to_path = to_path; if (PathExists(real_to_path)) { - if (!AbsolutePath(&real_to_path)) + real_to_path = MakeAbsoluteFilePath(real_to_path); + if (real_to_path.empty()) return false; } else { - real_to_path = real_to_path.DirName(); - if (!AbsolutePath(&real_to_path)) + real_to_path = MakeAbsoluteFilePath(real_to_path.DirName()); + if (real_to_path.empty()) return false; } - FilePath real_from_path = from_path; - if (!AbsolutePath(&real_from_path)) + FilePath real_from_path = MakeAbsoluteFilePath(from_path); + if (real_from_path.empty()) return false; if (real_to_path.value().size() >= real_from_path.value().size() && real_to_path.value().compare(0, real_from_path.value().size(), |