diff options
author | mad@chromium.org <mad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-28 12:41:29 +0000 |
---|---|---|
committer | mad@chromium.org <mad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-28 12:41:29 +0000 |
commit | a14b16bd4b6d7fc3c1e3e83f16d1d59bc05f3dab (patch) | |
tree | b9f147f90989125906bc77282d41f166c57bb959 /base/file_path.cc | |
parent | c3b4463c325d5a7f512130c02a68913cc52d20fe (diff) | |
download | chromium_src-a14b16bd4b6d7fc3c1e3e83f16d1d59bc05f3dab.zip chromium_src-a14b16bd4b6d7fc3c1e3e83f16d1d59bc05f3dab.tar.gz chromium_src-a14b16bd4b6d7fc3c1e3e83f16d1d59bc05f3dab.tar.bz2 |
Get rid of FilePath::AppendAndResolveRelative().
To resolve the problem of '..' parent references as well as symbolic links on POSIX platforms, we can simply use the file_util::AbsolutePath() function.
This has the drawback of having a different behavior on Windows and POSIX platforms, in the way that it can return a canonical path that doesn't exists when ran on Windows, but it will return an empty path (or false) when run on a POSIX platform.
So we need to add an extra PathExists() call to unify the behavior.
BUG=25681,25131
Review URL: http://codereview.chromium.org/343003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30334 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_path.cc')
-rw-r--r-- | base/file_path.cc | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/base/file_path.cc b/base/file_path.cc index 2d9d26e..dde8ae1 100644 --- a/base/file_path.cc +++ b/base/file_path.cc @@ -171,75 +171,6 @@ bool FilePath::operator!=(const FilePath& that) const { #endif // defined(FILE_PATH_USES_DRIVE_LETTERS) } -bool FilePath::AppendAndResolveRelative(const FilePath& relative_path, - FilePath* path) const { - DCHECK(path); - if (!path || relative_path.IsAbsolute()) - return false; - - FilePath full_path = Append(relative_path); - // Is it worth looking for parent references? - if (!full_path.ReferencesParent()) { - *path = full_path; - return true; - } - - // If the parent has a drive letter, then we must not remove the first - // component, which is the drive letter. - bool drive_letter = (FindDriveLetter(full_path.path_) != - FilePath::StringType::npos); - - std::vector<FilePath::StringType> components; - full_path.GetComponents(&components); - std::vector<FilePath::StringType>::iterator it = components.begin(); - // Start by removing any kCurrentDirectory component, since they may - // fool us into not going back to the appropriate parent level. - for (; it != components.end(); ++it) { - if (*it == kCurrentDirectory) { - // erase returns an iterator to the next component. - it = components.erase(it); - // So now, go back to previous iterator, - // so that we can appropriately process the next one as we loop. - --it; - } - } - - // Now parse the component looking for kParentDirectory and remove them as - // well as the previous component. - it = components.begin(); - for (; it != components.end(); ++it) { - if (*it == kParentDirectory) { - // Did we reach the beginning? - if (it == components.begin() || - (drive_letter && (it - 1) == components.begin())) { - return false; - } - // Remove the previous component, as well as the current one. - std::vector<FilePath::StringType>::iterator previous = it - 1; - // Unless the previous is at the beginning. - if (previous == components.begin() || - (drive_letter && (previous - 1) == components.begin())) { - return false; - } - // vector::erase doesn't erase _Last, it erases [_First, _Last[, - // so we must increment current which we want erased. - it = components.erase(previous, it + 1); - // And go back to previous so that we can process the next one as we loop. - --it; - } - } - - // Now reconstruct the path with the components that were left in. - it = components.begin(); - // We start with the first component, in case it is absolute - // and absolute paths can't be appended. - *path = FilePath(*it); - for (++it; it != components.end(); ++it) - *path = path->Append(*it); - - return true; -} - bool FilePath::IsParent(const FilePath& child) const { return AppendRelativePath(child, NULL); } |