diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 23:15:45 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 23:15:45 +0000 |
commit | a97f2b462ac8062e59849bfa2323d90f461fd5ff (patch) | |
tree | 5b3d08cc66629b98bd7270440a26b01217b66c0a /base | |
parent | 00d7e6289878922b937039cf542144a8c7906e8e (diff) | |
download | chromium_src-a97f2b462ac8062e59849bfa2323d90f461fd5ff.zip chromium_src-a97f2b462ac8062e59849bfa2323d90f461fd5ff.tar.gz chromium_src-a97f2b462ac8062e59849bfa2323d90f461fd5ff.tar.bz2 |
Reverting 14152.
TBR=tony
Review URL: http://codereview.chromium.org/87066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14154 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/file_util.cc | 5 | ||||
-rw-r--r-- | base/file_util.h | 5 | ||||
-rw-r--r-- | base/file_util_posix.cc | 5 | ||||
-rw-r--r-- | base/file_util_win.cc | 10 | ||||
-rw-r--r-- | base/path_service.cc | 5 |
5 files changed, 21 insertions, 9 deletions
diff --git a/base/file_util.cc b/base/file_util.cc index 1bf4d5e..ab0ae58 100644 --- a/base/file_util.cc +++ b/base/file_util.cc @@ -76,6 +76,11 @@ bool EnsureEndsWithSeparator(FilePath* path) { return true; } +void TrimTrailingSeparator(std::wstring* dir) { + while (dir->length() > 1 && EndsWithSeparator(dir)) + dir->resize(dir->length() - 1); +} + FilePath::StringType GetFileExtensionFromPath(const FilePath& path) { FilePath::StringType file_name = path.BaseName().value(); const FilePath::StringType::size_type last_dot = diff --git a/base/file_util.h b/base/file_util.h index 8f9cfb1..6728a0d 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -55,6 +55,11 @@ bool EndsWithSeparator(const std::wstring& path); // exists. Returns true if |path| is an existing directory, false otherwise. bool EnsureEndsWithSeparator(FilePath* path); +// Modifies a string by trimming all trailing separators from the end. +// Deprecated. FilePath does this automatically, and if it's constructed from a +// path with a trailing separator, StripTrailingSeparators() may be used. +void TrimTrailingSeparator(std::wstring* dir); + // Strips the topmost directory from the end of 'dir'. Assumes 'dir' does not // refer to a file. // If 'dir' is a root directory, return without change. diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index 2e315ab..6a36c62 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -37,8 +37,9 @@ static const char* kTempFileName = "org.chromium.XXXXXX"; std::wstring GetDirectoryFromPath(const std::wstring& path) { if (EndsWithSeparator(path)) { - FilePath fp_path = FilePath::FromWStringHack(path); - return fp_path.StripTrailingSeparators().ToWStringHack(); + std::wstring dir = path; + TrimTrailingSeparator(&dir); + return dir; } else { char full_path[PATH_MAX]; base::strlcpy(full_path, WideToUTF8(path).c_str(), arraysize(full_path)); diff --git a/base/file_util_win.cc b/base/file_util_win.cc index 8020dca..8b3d4f5 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -28,8 +28,8 @@ std::wstring GetDirectoryFromPath(const std::wstring& path) { std::wstring::size_type length = file_ptr ? file_ptr - path_buffer : path.length(); std::wstring directory(path, 0, length); - FilePath fp_directory(directory); - return fp_directory.StripTrailingSeparators().value(); + TrimTrailingSeparator(&directory); + return directory; } bool AbsolutePath(FilePath* path) { @@ -423,7 +423,8 @@ bool GetTempDir(FilePath* path) { // trailing slash. We duplicate this here, but it shouldn't be necessary // when everyone is using the appropriate FilePath APIs. std::wstring path_str(temp_path); - *path = FilePath(path_str).StripTrailingSeparators(); + TrimTrailingSeparator(&path_str); + *path = FilePath(path_str); return true; } @@ -637,7 +638,8 @@ bool GetCurrentDirectory(FilePath* dir) { // trailing slash. We duplicate this here, but it shouldn't be necessary // when everyone is using the appropriate FilePath APIs. std::wstring dir_str(system_buffer); - *dir = FilePath(dir_str).StripTrailingSeparators(); + file_util::TrimTrailingSeparator(&dir_str); + *dir = FilePath(dir_str); return true; } diff --git a/base/path_service.cc b/base/path_service.cc index 40866d1..0c3c3e2 100644 --- a/base/path_service.cc +++ b/base/path_service.cc @@ -219,11 +219,10 @@ bool PathService::Override(int key, const std::wstring& path) { if (!file_util::CreateDirectory(file_path)) return false; - FilePath fp_path = FilePath::FromWStringHack(file_path); - fp_path = fp_path.StripTrailingSeparators(); + file_util::TrimTrailingSeparator(&file_path); AutoLock scoped_lock(path_data->lock); - path_data->cache[key] = fp_path; + path_data->cache[key] = FilePath::FromWStringHack(file_path); path_data->overrides.insert(key); return true; } |