Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Unified Diff: base/file_util.cc

Issue 12620: Append a trailing slash on file directory URLs. Thus a link to /directory wil... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/file_util.cc
===================================================================
--- base/file_util.cc (revision 5946)
+++ base/file_util.cc (working copy)
@@ -26,7 +26,7 @@
std::wstring::size_type end = path.find(kPathSeparator, start);
// Special case the "/" or "\" directory. On Windows with a drive letter,
- // this code path won't hit, but the right thing should still happen.
+ // this code path won't hit, but the right thing should still happen.
// "E:\foo" will turn into "E:","foo".
if (end == start) {
components->push_back(std::wstring(path, 0, 1));
@@ -42,17 +42,28 @@
std::wstring component = std::wstring(path, start);
components->push_back(component);
}
-
-bool EndsWithSeparator(std::wstring* path) {
- return EndsWithSeparator(*path);
-}
-
-bool EndsWithSeparator(const std::wstring& path) {
- bool is_sep = (path.length() > 0 &&
- (path)[path.length() - 1] == kPathSeparator);
+
+bool EndsWithSeparator(const FilePath& file_path) {
+ std::wstring path = file_path.ToWStringHack();
+ bool is_sep = (path.length() > 0 &&
+ path[path.length() - 1] == kPathSeparator);
return is_sep;
}
+bool EnsureEndsWithSeparator(FilePath* path) {
+ if (!DirectoryExists(*path))
+ return false;
+
+ if (EndsWithSeparator(*path))
+ return true;
+
+ FilePath::StringType& path_str =
+ const_cast<FilePath::StringType&>(path->value());
+ path_str.append(&FilePath::kSeparators[0], 1);
+
+ return true;
+}
+
void TrimTrailingSeparator(std::wstring* dir) {
while (dir->length() > 1 && EndsWithSeparator(dir))
dir->resize(dir->length() - 1);
@@ -315,6 +326,12 @@
bool Delete(const std::wstring& path, bool recursive) {
return Delete(FilePath::FromWStringHack(path), recursive);
}
+bool EndsWithSeparator(std::wstring* path) {
+ return EndsWithSeparator(FilePath::FromWStringHack(*path));
+}
+bool EndsWithSeparator(const std::wstring& path) {
+ return EndsWithSeparator(FilePath::FromWStringHack(path));
+}
bool Move(const std::wstring& from_path, const std::wstring& to_path) {
return Move(FilePath::FromWStringHack(from_path),
FilePath::FromWStringHack(to_path));

Powered by Google App Engine
This is Rietveld 408576698