OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <fnmatch.h> | 10 #include <fnmatch.h> |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "base/logging.h" | 37 #include "base/logging.h" |
38 #include "base/scoped_ptr.h" | 38 #include "base/scoped_ptr.h" |
39 #include "base/singleton.h" | 39 #include "base/singleton.h" |
40 #include "base/string_util.h" | 40 #include "base/string_util.h" |
41 #include "base/sys_string_conversions.h" | 41 #include "base/sys_string_conversions.h" |
42 #include "base/time.h" | 42 #include "base/time.h" |
43 #include "base/utf_string_conversions.h" | 43 #include "base/utf_string_conversions.h" |
44 | 44 |
45 namespace file_util { | 45 namespace file_util { |
46 | 46 |
| 47 namespace { |
| 48 |
| 49 // Helper for NormalizeFilePath(), defined below. |
| 50 bool RealPath(const FilePath& path, FilePath* real_path) { |
| 51 FilePath::CharType buf[PATH_MAX]; |
| 52 if (!realpath(path.value().c_str(), buf)) |
| 53 return false; |
| 54 |
| 55 *real_path = FilePath(buf); |
| 56 return true; |
| 57 } |
| 58 |
| 59 } // namespace |
| 60 |
47 #if defined(OS_OPENBSD) || defined(OS_FREEBSD) || \ | 61 #if defined(OS_OPENBSD) || defined(OS_FREEBSD) || \ |
48 (defined(OS_MACOSX) && \ | 62 (defined(OS_MACOSX) && \ |
49 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) | 63 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) |
50 typedef struct stat stat_wrapper_t; | 64 typedef struct stat stat_wrapper_t; |
51 static int CallStat(const char *path, stat_wrapper_t *sb) { | 65 static int CallStat(const char *path, stat_wrapper_t *sb) { |
52 return stat(path, sb); | 66 return stat(path, sb); |
53 } | 67 } |
54 #else | 68 #else |
55 typedef struct stat64 stat_wrapper_t; | 69 typedef struct stat64 stat_wrapper_t; |
56 static int CallStat(const char *path, stat_wrapper_t *sb) { | 70 static int CallStat(const char *path, stat_wrapper_t *sb) { |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 data_ = NULL; | 733 data_ = NULL; |
720 length_ = 0; | 734 length_ = 0; |
721 file_ = base::kInvalidPlatformFileValue; | 735 file_ = base::kInvalidPlatformFileValue; |
722 } | 736 } |
723 | 737 |
724 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, | 738 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, |
725 const base::Time& cutoff_time) { | 739 const base::Time& cutoff_time) { |
726 return find_info.stat.st_mtime >= cutoff_time.ToTimeT(); | 740 return find_info.stat.st_mtime >= cutoff_time.ToTimeT(); |
727 } | 741 } |
728 | 742 |
729 bool RealPath(const FilePath& path, FilePath* real_path) { | 743 bool NormalizeFilePath(const FilePath& path, FilePath* normalized_path) { |
730 FilePath::CharType buf[PATH_MAX]; | 744 FilePath real_path_result; |
731 if (!realpath(path.value().c_str(), buf)) | 745 if (!RealPath(path, &real_path_result)) |
732 return false; | 746 return false; |
733 | 747 |
734 *real_path = FilePath(buf); | 748 // To be consistant with windows, fail if |real_path_result| is a |
| 749 // directory. |
| 750 stat_wrapper_t file_info; |
| 751 if (CallStat(real_path_result.value().c_str(), &file_info) != 0 || |
| 752 S_ISDIR(file_info.st_mode)) |
| 753 return false; |
| 754 |
| 755 *normalized_path = real_path_result; |
735 return true; | 756 return true; |
736 } | 757 } |
737 | 758 |
738 #if !defined(OS_MACOSX) | 759 #if !defined(OS_MACOSX) |
739 bool GetTempDir(FilePath* path) { | 760 bool GetTempDir(FilePath* path) { |
740 const char* tmp = getenv("TMPDIR"); | 761 const char* tmp = getenv("TMPDIR"); |
741 if (tmp) | 762 if (tmp) |
742 *path = FilePath(tmp); | 763 *path = FilePath(tmp); |
743 else | 764 else |
744 *path = FilePath("/tmp"); | 765 *path = FilePath("/tmp"); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 if (HANDLE_EINTR(close(infile)) < 0) | 829 if (HANDLE_EINTR(close(infile)) < 0) |
809 result = false; | 830 result = false; |
810 if (HANDLE_EINTR(close(outfile)) < 0) | 831 if (HANDLE_EINTR(close(outfile)) < 0) |
811 result = false; | 832 result = false; |
812 | 833 |
813 return result; | 834 return result; |
814 } | 835 } |
815 #endif // defined(OS_MACOSX) | 836 #endif // defined(OS_MACOSX) |
816 | 837 |
817 } // namespace file_util | 838 } // namespace file_util |
OLD | NEW |