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/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 <libgen.h> | 10 #include <libgen.h> |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 #if defined(OS_BSD) || defined(OS_MACOSX) | 64 #if defined(OS_BSD) || defined(OS_MACOSX) |
65 typedef struct stat stat_wrapper_t; | 65 typedef struct stat stat_wrapper_t; |
66 static int CallStat(const char *path, stat_wrapper_t *sb) { | 66 static int CallStat(const char *path, stat_wrapper_t *sb) { |
67 ThreadRestrictions::AssertIOAllowed(); | 67 ThreadRestrictions::AssertIOAllowed(); |
68 return stat(path, sb); | 68 return stat(path, sb); |
69 } | 69 } |
70 static int CallLstat(const char *path, stat_wrapper_t *sb) { | 70 static int CallLstat(const char *path, stat_wrapper_t *sb) { |
71 ThreadRestrictions::AssertIOAllowed(); | 71 ThreadRestrictions::AssertIOAllowed(); |
72 return lstat(path, sb); | 72 return lstat(path, sb); |
73 } | 73 } |
74 #else | 74 #else // defined(OS_BSD) || defined(OS_MACOSX) |
75 typedef struct stat64 stat_wrapper_t; | 75 typedef struct stat64 stat_wrapper_t; |
76 static int CallStat(const char *path, stat_wrapper_t *sb) { | 76 static int CallStat(const char *path, stat_wrapper_t *sb) { |
77 ThreadRestrictions::AssertIOAllowed(); | 77 ThreadRestrictions::AssertIOAllowed(); |
78 return stat64(path, sb); | 78 return stat64(path, sb); |
79 } | 79 } |
80 static int CallLstat(const char *path, stat_wrapper_t *sb) { | 80 static int CallLstat(const char *path, stat_wrapper_t *sb) { |
81 ThreadRestrictions::AssertIOAllowed(); | 81 ThreadRestrictions::AssertIOAllowed(); |
82 return lstat64(path, sb); | 82 return lstat64(path, sb); |
83 } | 83 } |
84 #if defined(OS_ANDROID) | 84 #endif // !(defined(OS_BSD) || defined(OS_MACOSX)) |
85 static int CallFstat(int fd, stat_wrapper_t *sb) { | |
86 ThreadRestrictions::AssertIOAllowed(); | |
87 return fstat64(fd, sb); | |
88 } | |
89 #endif | |
90 #endif | |
91 | 85 |
92 // Helper for NormalizeFilePath(), defined below. | 86 // Helper for NormalizeFilePath(), defined below. |
93 bool RealPath(const FilePath& path, FilePath* real_path) { | 87 bool RealPath(const FilePath& path, FilePath* real_path) { |
94 ThreadRestrictions::AssertIOAllowed(); // For realpath(). | 88 ThreadRestrictions::AssertIOAllowed(); // For realpath(). |
95 FilePath::CharType buf[PATH_MAX]; | 89 FilePath::CharType buf[PATH_MAX]; |
96 if (!realpath(path.value().c_str(), buf)) | 90 if (!realpath(path.value().c_str(), buf)) |
97 return false; | 91 return false; |
98 | 92 |
99 *real_path = FilePath(buf); | 93 *real_path = FilePath(buf); |
100 return true; | 94 return true; |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 if (S_ISLNK(st.st_mode)) | 648 if (S_ISLNK(st.st_mode)) |
655 return true; | 649 return true; |
656 else | 650 else |
657 return false; | 651 return false; |
658 } | 652 } |
659 | 653 |
660 bool GetFileInfo(const FilePath& file_path, File::Info* results) { | 654 bool GetFileInfo(const FilePath& file_path, File::Info* results) { |
661 stat_wrapper_t file_info; | 655 stat_wrapper_t file_info; |
662 #if defined(OS_ANDROID) | 656 #if defined(OS_ANDROID) |
663 if (file_path.IsContentUri()) { | 657 if (file_path.IsContentUri()) { |
664 ScopedFD fd(OpenContentUriForRead(file_path)); | 658 File file = OpenContentUriForRead(file_path); |
665 if (!fd.is_valid()) | 659 if (!file.IsValid()) |
666 return false; | 660 return false; |
667 if (CallFstat(fd.get(), &file_info) != 0) | 661 return file.GetInfo(results); |
668 return false; | |
669 } else { | 662 } else { |
670 #endif // defined(OS_ANDROID) | 663 #endif // defined(OS_ANDROID) |
671 if (CallStat(file_path.value().c_str(), &file_info) != 0) | 664 if (CallStat(file_path.value().c_str(), &file_info) != 0) |
672 return false; | 665 return false; |
673 #if defined(OS_ANDROID) | 666 #if defined(OS_ANDROID) |
674 } | 667 } |
675 #endif // defined(OS_ANDROID) | 668 #endif // defined(OS_ANDROID) |
676 results->is_directory = S_ISDIR(file_info.st_mode); | 669 results->is_directory = S_ISDIR(file_info.st_mode); |
677 results->size = file_info.st_size; | 670 results->size = file_info.st_size; |
678 #if defined(OS_MACOSX) || (defined(OS_FREEBSD) && __FreeBSD_version < 900000) | 671 #if defined(OS_MACOSX) || (defined(OS_FREEBSD) && __FreeBSD_version < 900000) |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 result = false; | 914 result = false; |
922 if (IGNORE_EINTR(close(outfile)) < 0) | 915 if (IGNORE_EINTR(close(outfile)) < 0) |
923 result = false; | 916 result = false; |
924 | 917 |
925 return result; | 918 return result; |
926 } | 919 } |
927 #endif // !defined(OS_MACOSX) | 920 #endif // !defined(OS_MACOSX) |
928 | 921 |
929 } // namespace internal | 922 } // namespace internal |
930 } // namespace base | 923 } // namespace base |
OLD | NEW |