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 30 matching lines...) Expand all Loading... | |
41 #include "base/stl_util.h" | 41 #include "base/stl_util.h" |
42 #include "base/strings/string_util.h" | 42 #include "base/strings/string_util.h" |
43 #include "base/strings/stringprintf.h" | 43 #include "base/strings/stringprintf.h" |
44 #include "base/strings/sys_string_conversions.h" | 44 #include "base/strings/sys_string_conversions.h" |
45 #include "base/strings/utf_string_conversions.h" | 45 #include "base/strings/utf_string_conversions.h" |
46 #include "base/sys_info.h" | 46 #include "base/sys_info.h" |
47 #include "base/threading/thread_restrictions.h" | 47 #include "base/threading/thread_restrictions.h" |
48 #include "base/time/time.h" | 48 #include "base/time/time.h" |
49 | 49 |
50 #if defined(OS_ANDROID) | 50 #if defined(OS_ANDROID) |
51 #include "base/android/content_uri_utils.h" | |
51 #include "base/os_compat_android.h" | 52 #include "base/os_compat_android.h" |
52 #endif | 53 #endif |
53 | 54 |
54 #if !defined(OS_IOS) | 55 #if !defined(OS_IOS) |
55 #include <grp.h> | 56 #include <grp.h> |
56 #endif | 57 #endif |
57 | 58 |
58 namespace base { | 59 namespace base { |
59 | 60 |
60 namespace { | 61 namespace { |
(...skipping 11 matching lines...) Expand all Loading... | |
72 #else | 73 #else |
73 typedef struct stat64 stat_wrapper_t; | 74 typedef struct stat64 stat_wrapper_t; |
74 static int CallStat(const char *path, stat_wrapper_t *sb) { | 75 static int CallStat(const char *path, stat_wrapper_t *sb) { |
75 ThreadRestrictions::AssertIOAllowed(); | 76 ThreadRestrictions::AssertIOAllowed(); |
76 return stat64(path, sb); | 77 return stat64(path, sb); |
77 } | 78 } |
78 static int CallLstat(const char *path, stat_wrapper_t *sb) { | 79 static int CallLstat(const char *path, stat_wrapper_t *sb) { |
79 ThreadRestrictions::AssertIOAllowed(); | 80 ThreadRestrictions::AssertIOAllowed(); |
80 return lstat64(path, sb); | 81 return lstat64(path, sb); |
81 } | 82 } |
83 #if defined(OS_ANDROID) | |
84 static int CallFstat(int fd, stat_wrapper_t *sb) { | |
85 ThreadRestrictions::AssertIOAllowed(); | |
86 return fstat64(fd, sb); | |
87 } | |
88 #endif | |
82 #endif | 89 #endif |
83 | 90 |
84 // Helper for NormalizeFilePath(), defined below. | 91 // Helper for NormalizeFilePath(), defined below. |
85 bool RealPath(const FilePath& path, FilePath* real_path) { | 92 bool RealPath(const FilePath& path, FilePath* real_path) { |
86 ThreadRestrictions::AssertIOAllowed(); // For realpath(). | 93 ThreadRestrictions::AssertIOAllowed(); // For realpath(). |
87 FilePath::CharType buf[PATH_MAX]; | 94 FilePath::CharType buf[PATH_MAX]; |
88 if (!realpath(path.value().c_str(), buf)) | 95 if (!realpath(path.value().c_str(), buf)) |
89 return false; | 96 return false; |
90 | 97 |
91 *real_path = FilePath(buf); | 98 *real_path = FilePath(buf); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 current = traversal.Next(); | 308 current = traversal.Next(); |
302 if (!current.empty()) | 309 if (!current.empty()) |
303 from_stat = traversal.GetInfo().stat(); | 310 from_stat = traversal.GetInfo().stat(); |
304 } | 311 } |
305 | 312 |
306 return success; | 313 return success; |
307 } | 314 } |
308 | 315 |
309 bool PathExists(const FilePath& path) { | 316 bool PathExists(const FilePath& path) { |
310 ThreadRestrictions::AssertIOAllowed(); | 317 ThreadRestrictions::AssertIOAllowed(); |
318 #if defined(OS_ANDROID) | |
319 if (path.IsContentUrl()) { | |
320 return ContentUrlExists(path); | |
321 } | |
kinuko
2013/11/06 01:42:05
nit: usually we use no { } for single-line block i
qinmin
2013/11/07 01:13:35
Done.
| |
322 #endif | |
311 return access(path.value().c_str(), F_OK) == 0; | 323 return access(path.value().c_str(), F_OK) == 0; |
312 } | 324 } |
313 | 325 |
314 bool PathIsWritable(const FilePath& path) { | 326 bool PathIsWritable(const FilePath& path) { |
315 ThreadRestrictions::AssertIOAllowed(); | 327 ThreadRestrictions::AssertIOAllowed(); |
316 return access(path.value().c_str(), W_OK) == 0; | 328 return access(path.value().c_str(), W_OK) == 0; |
317 } | 329 } |
318 | 330 |
319 bool DirectoryExists(const FilePath& path) { | 331 bool DirectoryExists(const FilePath& path) { |
320 ThreadRestrictions::AssertIOAllowed(); | 332 ThreadRestrictions::AssertIOAllowed(); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 return false; | 574 return false; |
563 | 575 |
564 if (S_ISLNK(st.st_mode)) | 576 if (S_ISLNK(st.st_mode)) |
565 return true; | 577 return true; |
566 else | 578 else |
567 return false; | 579 return false; |
568 } | 580 } |
569 | 581 |
570 bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { | 582 bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { |
571 stat_wrapper_t file_info; | 583 stat_wrapper_t file_info; |
584 #if defined(OS_ANDROID) | |
585 if (file_path.IsContentUrl()) { | |
586 int fd = OpenContentUrlForRead(file_path); | |
587 if (fd < 0) | |
588 return false; | |
589 ScopedFD scoped_fd(&fd); | |
590 if (base::CallFstat(fd, &file_info) != 0) | |
591 return false; | |
592 } else { | |
593 #endif | |
572 if (CallStat(file_path.value().c_str(), &file_info) != 0) | 594 if (CallStat(file_path.value().c_str(), &file_info) != 0) |
joth
2013/11/06 00:27:08
It looks like CallStat() is already intended to ha
qinmin
2013/11/07 01:13:35
I think I would rather keep it separate. CallStat(
| |
573 return false; | 595 return false; |
596 #if defined(OS_ANDROID) | |
597 } | |
598 #endif | |
574 results->is_directory = S_ISDIR(file_info.st_mode); | 599 results->is_directory = S_ISDIR(file_info.st_mode); |
575 results->size = file_info.st_size; | 600 results->size = file_info.st_size; |
576 #if defined(OS_MACOSX) | 601 #if defined(OS_MACOSX) |
577 results->last_modified = base::Time::FromTimeSpec(file_info.st_mtimespec); | 602 results->last_modified = base::Time::FromTimeSpec(file_info.st_mtimespec); |
578 results->last_accessed = base::Time::FromTimeSpec(file_info.st_atimespec); | 603 results->last_accessed = base::Time::FromTimeSpec(file_info.st_atimespec); |
579 results->creation_time = base::Time::FromTimeSpec(file_info.st_ctimespec); | 604 results->creation_time = base::Time::FromTimeSpec(file_info.st_ctimespec); |
580 #elif defined(OS_ANDROID) | 605 #elif defined(OS_ANDROID) |
581 results->last_modified = base::Time::FromTimeT(file_info.st_mtime); | 606 results->last_modified = base::Time::FromTimeT(file_info.st_mtime); |
582 results->last_accessed = base::Time::FromTimeT(file_info.st_atime); | 607 results->last_accessed = base::Time::FromTimeT(file_info.st_atime); |
583 results->creation_time = base::Time::FromTimeT(file_info.st_ctime); | 608 results->creation_time = base::Time::FromTimeT(file_info.st_ctime); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
946 result = false; | 971 result = false; |
947 if (HANDLE_EINTR(close(outfile)) < 0) | 972 if (HANDLE_EINTR(close(outfile)) < 0) |
948 result = false; | 973 result = false; |
949 | 974 |
950 return result; | 975 return result; |
951 } | 976 } |
952 #endif // !defined(OS_MACOSX) | 977 #endif // !defined(OS_MACOSX) |
953 | 978 |
954 } // namespace internal | 979 } // namespace internal |
955 } // namespace base | 980 } // namespace base |
OLD | NEW |