Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
| 13 | 13 |
| 14 // These includes are just for the *Hack functions, and should be removed | 14 // These includes are just for the *Hack functions, and should be removed |
| 15 // when those functions are removed. | 15 // when those functions are removed. |
| 16 #include "base/string_piece.h" | 16 #include "base/string_piece.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
| 19 #include "base/threading/thread_restrictions.h" | |
| 19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 20 | 21 |
| 21 #if defined(OS_MACOSX) | 22 #if defined(OS_MACOSX) |
| 22 #include "base/mac/scoped_cftyperef.h" | 23 #include "base/mac/scoped_cftyperef.h" |
| 23 #include "base/third_party/icu/icu_utf.h" | 24 #include "base/third_party/icu/icu_utf.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 27 #include <windows.h> | 28 #include <windows.h> |
| 28 #elif defined(OS_MACOSX) | 29 #elif defined(OS_MACOSX) |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 return Append(ASCIIToUTF16(component.as_string())); | 515 return Append(ASCIIToUTF16(component.as_string())); |
| 515 #elif defined(OS_POSIX) | 516 #elif defined(OS_POSIX) |
| 516 return Append(component.as_string()); | 517 return Append(component.as_string()); |
| 517 #endif | 518 #endif |
| 518 } | 519 } |
| 519 | 520 |
| 520 bool FilePath::IsAbsolute() const { | 521 bool FilePath::IsAbsolute() const { |
| 521 return IsPathAbsolute(path_); | 522 return IsPathAbsolute(path_); |
| 522 } | 523 } |
| 523 | 524 |
| 525 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
| |
| 526 base::ThreadRestrictions::AssertIOAllowed(); | |
| 527 | |
| 528 #if defined(OS_WIN) | |
| 529 wchar_t file_path[MAX_PATH]; | |
| 530 if (!_wfullpath(file_path, path_.c_str(), MAX_PATH)) | |
| 531 return FilePath(); | |
| 532 return FilePath(file_path); | |
| 533 #elif defined(OS_NACL) | |
| 534 // Nacl doesn't have realpath and there's not a lot you can do inside the | |
| 535 // sandbox with files. | |
| 536 // TODO(brettw) implement something more reasonable if we need it. | |
| 537 return *this; | |
| 538 #elif defined(OS_POSIX) | |
| 539 char full_path[PATH_MAX]; | |
| 540 if (realpath(path_.c_str(), full_path) == NULL) | |
| 541 return FilePath(); | |
| 542 return FilePath(full_path); | |
| 543 #endif | |
| 544 } | |
| 545 | |
| 546 bool FilePath::EndsWithSeparator() const { | |
| 547 if (empty()) | |
| 548 return false; | |
| 549 return IsSeparator(path_[path_.size() - 1]); | |
| 550 } | |
| 551 | |
| 552 FilePath FilePath::AsEndingWithSeparator() const { | |
| 553 if (EndsWithSeparator()) | |
| 554 return *this; | |
| 555 | |
| 556 StringType path_str; | |
| 557 path_str.reserve(path_.length() + 1); // Only allocate string once. | |
| 558 | |
| 559 path_str = path_; | |
| 560 path_str.append(&kSeparators[0], 1); | |
| 561 return FilePath(path_str); | |
| 562 } | |
| 563 | |
| 524 FilePath FilePath::StripTrailingSeparators() const { | 564 FilePath FilePath::StripTrailingSeparators() const { |
| 525 FilePath new_path(path_); | 565 FilePath new_path(path_); |
| 526 new_path.StripTrailingSeparatorsInternal(); | 566 new_path.StripTrailingSeparatorsInternal(); |
| 527 | 567 |
| 528 return new_path; | 568 return new_path; |
| 529 } | 569 } |
| 530 | 570 |
| 531 bool FilePath::ReferencesParent() const { | 571 bool FilePath::ReferencesParent() const { |
| 532 std::vector<StringType> components; | 572 std::vector<StringType> components; |
| 533 GetComponents(&components); | 573 GetComponents(&components); |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1251 #else | 1291 #else |
| 1252 return *this; | 1292 return *this; |
| 1253 #endif | 1293 #endif |
| 1254 } | 1294 } |
| 1255 | 1295 |
| 1256 } // namespace base | 1296 } // namespace base |
| 1257 | 1297 |
| 1258 void PrintTo(const base::FilePath& path, std::ostream* out) { | 1298 void PrintTo(const base::FilePath& path, std::ostream* out) { |
| 1259 *out << path.value(); | 1299 *out << path.value(); |
| 1260 } | 1300 } |
| OLD | NEW |