OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "base/utf_string_conversions.h" | 47 #include "base/utf_string_conversions.h" |
48 | 48 |
49 #if defined(OS_ANDROID) | 49 #if defined(OS_ANDROID) |
50 #include "base/os_compat_android.h" | 50 #include "base/os_compat_android.h" |
51 #endif | 51 #endif |
52 | 52 |
53 namespace file_util { | 53 namespace file_util { |
54 | 54 |
55 namespace { | 55 namespace { |
56 | 56 |
57 #if defined(OS_OPENBSD) || defined(OS_FREEBSD) || \ | 57 #if defined(OS_BSD) || (defined(OS_MACOSX) && \ |
58 (defined(OS_MACOSX) && \ | 58 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) |
59 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) | |
60 typedef struct stat stat_wrapper_t; | 59 typedef struct stat stat_wrapper_t; |
61 static int CallStat(const char *path, stat_wrapper_t *sb) { | 60 static int CallStat(const char *path, stat_wrapper_t *sb) { |
62 base::ThreadRestrictions::AssertIOAllowed(); | 61 base::ThreadRestrictions::AssertIOAllowed(); |
63 return stat(path, sb); | 62 return stat(path, sb); |
64 } | 63 } |
65 static int CallLstat(const char *path, stat_wrapper_t *sb) { | 64 static int CallLstat(const char *path, stat_wrapper_t *sb) { |
66 base::ThreadRestrictions::AssertIOAllowed(); | 65 base::ThreadRestrictions::AssertIOAllowed(); |
67 return lstat(path, sb); | 66 return lstat(path, sb); |
68 } | 67 } |
69 #else | 68 #else |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 return true; | 150 return true; |
152 } | 151 } |
153 | 152 |
154 int CountFilesCreatedAfter(const FilePath& path, | 153 int CountFilesCreatedAfter(const FilePath& path, |
155 const base::Time& comparison_time) { | 154 const base::Time& comparison_time) { |
156 base::ThreadRestrictions::AssertIOAllowed(); | 155 base::ThreadRestrictions::AssertIOAllowed(); |
157 int file_count = 0; | 156 int file_count = 0; |
158 | 157 |
159 DIR* dir = opendir(path.value().c_str()); | 158 DIR* dir = opendir(path.value().c_str()); |
160 if (dir) { | 159 if (dir) { |
161 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_FREEBSD) && \ | 160 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_BSD) && \ |
162 !defined(OS_OPENBSD) && !defined(OS_SOLARIS) && !defined(OS_ANDROID) | 161 !defined(OS_SOLARIS) && !defined(OS_ANDROID) |
163 #error Port warning: depending on the definition of struct dirent, \ | 162 #error Port warning: depending on the definition of struct dirent, \ |
164 additional space for pathname may be needed | 163 additional space for pathname may be needed |
165 #endif | 164 #endif |
166 struct dirent ent_buf; | 165 struct dirent ent_buf; |
167 struct dirent* ent; | 166 struct dirent* ent; |
168 while (readdir_r(dir, &ent_buf, &ent) == 0 && ent) { | 167 while (readdir_r(dir, &ent_buf, &ent) == 0 && ent) { |
169 if ((strcmp(ent->d_name, ".") == 0) || | 168 if ((strcmp(ent->d_name, ".") == 0) || |
170 (strcmp(ent->d_name, "..") == 0)) | 169 (strcmp(ent->d_name, "..") == 0)) |
171 continue; | 170 continue; |
172 | 171 |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 return base::Time::FromTimeT(find_info.stat.st_mtime); | 793 return base::Time::FromTimeT(find_info.stat.st_mtime); |
795 } | 794 } |
796 | 795 |
797 bool FileEnumerator::ReadDirectory(std::vector<DirectoryEntryInfo>* entries, | 796 bool FileEnumerator::ReadDirectory(std::vector<DirectoryEntryInfo>* entries, |
798 const FilePath& source, bool show_links) { | 797 const FilePath& source, bool show_links) { |
799 base::ThreadRestrictions::AssertIOAllowed(); | 798 base::ThreadRestrictions::AssertIOAllowed(); |
800 DIR* dir = opendir(source.value().c_str()); | 799 DIR* dir = opendir(source.value().c_str()); |
801 if (!dir) | 800 if (!dir) |
802 return false; | 801 return false; |
803 | 802 |
804 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_FREEBSD) && \ | 803 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_BSD) && \ |
805 !defined(OS_OPENBSD) && !defined(OS_SOLARIS) && !defined(OS_ANDROID) | 804 !defined(OS_SOLARIS) && !defined(OS_ANDROID) |
806 #error Port warning: depending on the definition of struct dirent, \ | 805 #error Port warning: depending on the definition of struct dirent, \ |
807 additional space for pathname may be needed | 806 additional space for pathname may be needed |
808 #endif | 807 #endif |
809 | 808 |
810 struct dirent dent_buf; | 809 struct dirent dent_buf; |
811 struct dirent* dent; | 810 struct dirent* dent; |
812 while (readdir_r(dir, &dent_buf, &dent) == 0 && dent) { | 811 while (readdir_r(dir, &dent_buf, &dent) == 0 && dent) { |
813 DirectoryEntryInfo info; | 812 DirectoryEntryInfo info; |
814 info.filename = FilePath(dent->d_name); | 813 info.filename = FilePath(dent->d_name); |
815 | 814 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 | 1056 |
1058 allowed_group_ids.insert(group_record->gr_gid); | 1057 allowed_group_ids.insert(group_record->gr_gid); |
1059 } | 1058 } |
1060 | 1059 |
1061 return VerifyPathControlledByUser( | 1060 return VerifyPathControlledByUser( |
1062 kFileSystemRoot, path, kRootUid, allowed_group_ids); | 1061 kFileSystemRoot, path, kRootUid, allowed_group_ids); |
1063 } | 1062 } |
1064 #endif // defined(OS_MACOSX) | 1063 #endif // defined(OS_MACOSX) |
1065 | 1064 |
1066 } // namespace file_util | 1065 } // namespace file_util |
OLD | NEW |