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

Unified Diff: base/files/file_path.cc

Issue 13196006: Move path functions from file_util to FilePath object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try fixes, merge Created 7 years, 9 months 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
« no previous file with comments | « base/files/file_path.h ('k') | base/path_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_path.cc
diff --git a/base/files/file_path.cc b/base/files/file_path.cc
index 407ec855b2d7ad06273715e51313fb7275285f3c..a96c710bcbfd873387685b5b3abdc61824221020 100644
--- a/base/files/file_path.cc
+++ b/base/files/file_path.cc
@@ -16,6 +16,7 @@
#include "base/string_piece.h"
#include "base/string_util.h"
#include "base/strings/sys_string_conversions.h"
+#include "base/threading/thread_restrictions.h"
#include "base/utf_string_conversions.h"
#if defined(OS_MACOSX)
@@ -521,6 +522,45 @@ bool FilePath::IsAbsolute() const {
return IsPathAbsolute(path_);
}
+FilePath FilePath::AsAbsolute() const {
rvargas (doing something else) 2013/04/01 19:50:31 I'm not sure moving this code here is a good idea.
brettw 2013/04/01 22:42:24 I thought that was the case but it didn't seem lik
+ base::ThreadRestrictions::AssertIOAllowed();
+
+#if defined(OS_WIN)
+ wchar_t file_path[MAX_PATH];
+ if (!_wfullpath(file_path, path_.c_str(), MAX_PATH))
+ return FilePath();
+ return FilePath(file_path);
+#elif defined(OS_NACL)
+ // Nacl doesn't have realpath and there's not a lot you can do inside the
+ // sandbox with files.
+ // TODO(brettw) implement something more reasonable if we need it.
+ return *this;
+#elif defined(OS_POSIX)
+ char full_path[PATH_MAX];
+ if (realpath(path_.c_str(), full_path) == NULL)
+ return FilePath();
+ return FilePath(full_path);
+#endif
+}
+
+bool FilePath::EndsWithSeparator() const {
+ if (empty())
+ return false;
+ return IsSeparator(path_[path_.size() - 1]);
+}
+
+FilePath FilePath::AsEndingWithSeparator() const {
+ if (EndsWithSeparator())
+ return *this;
+
+ StringType path_str;
+ path_str.reserve(path_.length() + 1); // Only allocate string once.
+
+ path_str = path_;
+ path_str.append(&kSeparators[0], 1);
+ return FilePath(path_str);
+}
+
FilePath FilePath::StripTrailingSeparators() const {
FilePath new_path(path_);
new_path.StripTrailingSeparatorsInternal();
« no previous file with comments | « base/files/file_path.h ('k') | base/path_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698