Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: trunk/src/base/file_util_posix.cc

Issue 65043023: Revert 235752 "Fix chrome upload with content uri" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/base/base.gypi ('k') | trunk/src/base/file_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"
52 #include "base/os_compat_android.h" 51 #include "base/os_compat_android.h"
53 #endif 52 #endif
54 53
55 #if !defined(OS_IOS) 54 #if !defined(OS_IOS)
56 #include <grp.h> 55 #include <grp.h>
57 #endif 56 #endif
58 57
59 namespace base { 58 namespace base {
60 59
61 namespace { 60 namespace {
(...skipping 11 matching lines...) Expand all
73 #else 72 #else
74 typedef struct stat64 stat_wrapper_t; 73 typedef struct stat64 stat_wrapper_t;
75 static int CallStat(const char *path, stat_wrapper_t *sb) { 74 static int CallStat(const char *path, stat_wrapper_t *sb) {
76 ThreadRestrictions::AssertIOAllowed(); 75 ThreadRestrictions::AssertIOAllowed();
77 return stat64(path, sb); 76 return stat64(path, sb);
78 } 77 }
79 static int CallLstat(const char *path, stat_wrapper_t *sb) { 78 static int CallLstat(const char *path, stat_wrapper_t *sb) {
80 ThreadRestrictions::AssertIOAllowed(); 79 ThreadRestrictions::AssertIOAllowed();
81 return lstat64(path, sb); 80 return lstat64(path, sb);
82 } 81 }
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
89 #endif 82 #endif
90 83
91 // Helper for NormalizeFilePath(), defined below. 84 // Helper for NormalizeFilePath(), defined below.
92 bool RealPath(const FilePath& path, FilePath* real_path) { 85 bool RealPath(const FilePath& path, FilePath* real_path) {
93 ThreadRestrictions::AssertIOAllowed(); // For realpath(). 86 ThreadRestrictions::AssertIOAllowed(); // For realpath().
94 FilePath::CharType buf[PATH_MAX]; 87 FilePath::CharType buf[PATH_MAX];
95 if (!realpath(path.value().c_str(), buf)) 88 if (!realpath(path.value().c_str(), buf))
96 return false; 89 return false;
97 90
98 *real_path = FilePath(buf); 91 *real_path = FilePath(buf);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 current = traversal.Next(); 301 current = traversal.Next();
309 if (!current.empty()) 302 if (!current.empty())
310 from_stat = traversal.GetInfo().stat(); 303 from_stat = traversal.GetInfo().stat();
311 } 304 }
312 305
313 return success; 306 return success;
314 } 307 }
315 308
316 bool PathExists(const FilePath& path) { 309 bool PathExists(const FilePath& path) {
317 ThreadRestrictions::AssertIOAllowed(); 310 ThreadRestrictions::AssertIOAllowed();
318 #if defined(OS_ANDROID)
319 if (path.IsContentUri()) {
320 return ContentUriExists(path);
321 }
322 #endif
323 return access(path.value().c_str(), F_OK) == 0; 311 return access(path.value().c_str(), F_OK) == 0;
324 } 312 }
325 313
326 bool PathIsWritable(const FilePath& path) { 314 bool PathIsWritable(const FilePath& path) {
327 ThreadRestrictions::AssertIOAllowed(); 315 ThreadRestrictions::AssertIOAllowed();
328 return access(path.value().c_str(), W_OK) == 0; 316 return access(path.value().c_str(), W_OK) == 0;
329 } 317 }
330 318
331 bool DirectoryExists(const FilePath& path) { 319 bool DirectoryExists(const FilePath& path) {
332 ThreadRestrictions::AssertIOAllowed(); 320 ThreadRestrictions::AssertIOAllowed();
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 return false; 562 return false;
575 563
576 if (S_ISLNK(st.st_mode)) 564 if (S_ISLNK(st.st_mode))
577 return true; 565 return true;
578 else 566 else
579 return false; 567 return false;
580 } 568 }
581 569
582 bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { 570 bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) {
583 stat_wrapper_t file_info; 571 stat_wrapper_t file_info;
584 #if defined(OS_ANDROID) 572 if (CallStat(file_path.value().c_str(), &file_info) != 0)
585 if (file_path.IsContentUri()) { 573 return false;
586 int fd = OpenContentUriForRead(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 // defined(OS_ANDROID)
594 if (CallStat(file_path.value().c_str(), &file_info) != 0)
595 return false;
596 #if defined(OS_ANDROID)
597 }
598 #endif // defined(OS_ANDROID)
599 results->is_directory = S_ISDIR(file_info.st_mode); 574 results->is_directory = S_ISDIR(file_info.st_mode);
600 results->size = file_info.st_size; 575 results->size = file_info.st_size;
601 #if defined(OS_MACOSX) 576 #if defined(OS_MACOSX)
602 results->last_modified = base::Time::FromTimeSpec(file_info.st_mtimespec); 577 results->last_modified = base::Time::FromTimeSpec(file_info.st_mtimespec);
603 results->last_accessed = base::Time::FromTimeSpec(file_info.st_atimespec); 578 results->last_accessed = base::Time::FromTimeSpec(file_info.st_atimespec);
604 results->creation_time = base::Time::FromTimeSpec(file_info.st_ctimespec); 579 results->creation_time = base::Time::FromTimeSpec(file_info.st_ctimespec);
605 #elif defined(OS_ANDROID) 580 #elif defined(OS_ANDROID)
606 results->last_modified = base::Time::FromTimeT(file_info.st_mtime); 581 results->last_modified = base::Time::FromTimeT(file_info.st_mtime);
607 results->last_accessed = base::Time::FromTimeT(file_info.st_atime); 582 results->last_accessed = base::Time::FromTimeT(file_info.st_atime);
608 results->creation_time = base::Time::FromTimeT(file_info.st_ctime); 583 results->creation_time = base::Time::FromTimeT(file_info.st_ctime);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 result = false; 946 result = false;
972 if (HANDLE_EINTR(close(outfile)) < 0) 947 if (HANDLE_EINTR(close(outfile)) < 0)
973 result = false; 948 result = false;
974 949
975 return result; 950 return result;
976 } 951 }
977 #endif // !defined(OS_MACOSX) 952 #endif // !defined(OS_MACOSX)
978 953
979 } // namespace internal 954 } // namespace internal
980 } // namespace base 955 } // namespace base
OLDNEW
« no previous file with comments | « trunk/src/base/base.gypi ('k') | trunk/src/base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698