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

Side by Side Diff: base/file_util_posix.cc

Issue 7184032: Upstream android file related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 months 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
OLDNEW
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>
11 #include <libgen.h> 11 #include <libgen.h>
12 #include <limits.h> 12 #include <limits.h>
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <string.h> 15 #include <string.h>
16 #include <sys/errno.h> 16 #include <sys/errno.h>
17 #include <sys/mman.h> 17 #include <sys/mman.h>
18 #include <sys/param.h> 18 #include <sys/param.h>
19 #include <sys/stat.h> 19 #include <sys/stat.h>
20 #include <sys/time.h> 20 #include <sys/time.h>
21 #include <sys/types.h> 21 #include <sys/types.h>
22 #include <time.h> 22 #include <time.h>
23 #include <unistd.h> 23 #include <unistd.h>
24 24
25 #if defined(OS_MACOSX) 25 #if defined(OS_MACOSX)
26 #include <AvailabilityMacros.h> 26 #include <AvailabilityMacros.h>
27 #include "base/mac/foundation_util.h" 27 #include "base/mac/foundation_util.h"
28 #else 28 #elif !defined(OS_ANDROID)
29 #include <glib.h> 29 #include <glib.h>
30 #endif 30 #endif
31 31
32 #include <fstream> 32 #include <fstream>
33 33
34 #include "base/basictypes.h" 34 #include "base/basictypes.h"
35 #include "base/eintr_wrapper.h" 35 #include "base/eintr_wrapper.h"
36 #include "base/file_path.h" 36 #include "base/file_path.h"
37 #include "base/logging.h" 37 #include "base/logging.h"
38 #if defined(OS_ANDROID)
brettw 2011/06/17 16:29:14 Can you put this below all other includes with a b
michaelbai 2011/06/17 22:41:29 Done.
39 #include "base/platform_file.h"
darin (slow to review) 2011/06/17 16:29:29 nit: this include looks unnecessary.
michaelbai 2011/06/17 22:41:29 Removed, but still need 'base/platform_file_androi
40 #endif
38 #include "base/memory/scoped_ptr.h" 41 #include "base/memory/scoped_ptr.h"
39 #include "base/memory/singleton.h" 42 #include "base/memory/singleton.h"
40 #include "base/string_util.h" 43 #include "base/string_util.h"
41 #include "base/stringprintf.h" 44 #include "base/stringprintf.h"
42 #include "base/sys_string_conversions.h" 45 #include "base/sys_string_conversions.h"
43 #include "base/threading/thread_restrictions.h" 46 #include "base/threading/thread_restrictions.h"
44 #include "base/time.h" 47 #include "base/time.h"
45 #include "base/utf_string_conversions.h" 48 #include "base/utf_string_conversions.h"
46 49
47 namespace file_util { 50 namespace file_util {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 102 }
100 103
101 int CountFilesCreatedAfter(const FilePath& path, 104 int CountFilesCreatedAfter(const FilePath& path,
102 const base::Time& comparison_time) { 105 const base::Time& comparison_time) {
103 base::ThreadRestrictions::AssertIOAllowed(); 106 base::ThreadRestrictions::AssertIOAllowed();
104 int file_count = 0; 107 int file_count = 0;
105 108
106 DIR* dir = opendir(path.value().c_str()); 109 DIR* dir = opendir(path.value().c_str());
107 if (dir) { 110 if (dir) {
108 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_FREEBSD) && \ 111 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_FREEBSD) && \
109 !defined(OS_OPENBSD) && !defined(OS_SOLARIS) 112 !defined(OS_OPENBSD) && !defined(OS_SOLARIS) && !defined(OS_ANDROID)
110 #error Port warning: depending on the definition of struct dirent, \ 113 #error Port warning: depending on the definition of struct dirent, \
111 additional space for pathname may be needed 114 additional space for pathname may be needed
112 #endif 115 #endif
113 struct dirent ent_buf; 116 struct dirent ent_buf;
114 struct dirent* ent; 117 struct dirent* ent;
115 while (readdir_r(dir, &ent_buf, &ent) == 0 && ent) { 118 while (readdir_r(dir, &ent_buf, &ent) == 0 && ent) {
116 if ((strcmp(ent->d_name, ".") == 0) || 119 if ((strcmp(ent->d_name, ".") == 0) ||
117 (strcmp(ent->d_name, "..") == 0)) 120 (strcmp(ent->d_name, "..") == 0))
118 continue; 121 continue;
119 122
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 } 735 }
733 736
734 bool FileEnumerator::ReadDirectory(std::vector<DirectoryEntryInfo>* entries, 737 bool FileEnumerator::ReadDirectory(std::vector<DirectoryEntryInfo>* entries,
735 const FilePath& source, bool show_links) { 738 const FilePath& source, bool show_links) {
736 base::ThreadRestrictions::AssertIOAllowed(); 739 base::ThreadRestrictions::AssertIOAllowed();
737 DIR* dir = opendir(source.value().c_str()); 740 DIR* dir = opendir(source.value().c_str());
738 if (!dir) 741 if (!dir)
739 return false; 742 return false;
740 743
741 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_FREEBSD) && \ 744 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_FREEBSD) && \
742 !defined(OS_OPENBSD) && !defined(OS_SOLARIS) 745 !defined(OS_OPENBSD) && !defined(OS_SOLARIS) && !defined(OS_ANDROID)
743 #error Port warning: depending on the definition of struct dirent, \ 746 #error Port warning: depending on the definition of struct dirent, \
744 additional space for pathname may be needed 747 additional space for pathname may be needed
745 #endif 748 #endif
746 749
747 struct dirent dent_buf; 750 struct dirent dent_buf;
748 struct dirent* dent; 751 struct dirent* dent;
749 while (readdir_r(dir, &dent_buf, &dent) == 0 && dent) { 752 while (readdir_r(dir, &dent_buf, &dent) == 0 && dent) {
750 DirectoryEntryInfo info; 753 DirectoryEntryInfo info;
751 info.filename = FilePath(dent->d_name); 754 info.filename = FilePath(dent->d_name);
752 755
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 *normalized_path = real_path_result; 835 *normalized_path = real_path_result;
833 return true; 836 return true;
834 } 837 }
835 838
836 #if !defined(OS_MACOSX) 839 #if !defined(OS_MACOSX)
837 bool GetTempDir(FilePath* path) { 840 bool GetTempDir(FilePath* path) {
838 const char* tmp = getenv("TMPDIR"); 841 const char* tmp = getenv("TMPDIR");
839 if (tmp) 842 if (tmp)
840 *path = FilePath(tmp); 843 *path = FilePath(tmp);
841 else 844 else
845 #if defined(OS_ANDROID)
846 *path = FilePath("/data/local/tmp");
847 #else
842 *path = FilePath("/tmp"); 848 *path = FilePath("/tmp");
849 #endif
843 return true; 850 return true;
844 } 851 }
845 852
846 bool GetShmemTempDir(FilePath* path) { 853 bool GetShmemTempDir(FilePath* path) {
854 #if defined(OS_ANDROID)
855 *path = FilePath("/data/local/tmp");
856 #else
847 *path = FilePath("/dev/shm"); 857 *path = FilePath("/dev/shm");
858 #endif
848 return true; 859 return true;
849 } 860 }
850 861
851 FilePath GetHomeDir() { 862 FilePath GetHomeDir() {
852 const char* home_dir = getenv("HOME"); 863 const char* home_dir = getenv("HOME");
853 if (home_dir && home_dir[0]) 864 if (home_dir && home_dir[0])
854 return FilePath(home_dir); 865 return FilePath(home_dir);
855 866
867 #if defined(OS_ANDROID)
868 LOG(WARNING) << "OS_ANDROID: Home directory lookup not yet implemented.";
869 #else
856 // g_get_home_dir calls getpwent, which can fall through to LDAP calls. 870 // g_get_home_dir calls getpwent, which can fall through to LDAP calls.
857 base::ThreadRestrictions::AssertIOAllowed(); 871 base::ThreadRestrictions::AssertIOAllowed();
858 872
859 home_dir = g_get_home_dir(); 873 home_dir = g_get_home_dir();
860 if (home_dir && home_dir[0]) 874 if (home_dir && home_dir[0])
861 return FilePath(home_dir); 875 return FilePath(home_dir);
876 #endif
862 877
863 FilePath rv; 878 FilePath rv;
864 if (file_util::GetTempDir(&rv)) 879 if (file_util::GetTempDir(&rv))
865 return rv; 880 return rv;
866 881
867 // Last resort. 882 // Last resort.
868 return FilePath("/tmp"); 883 return FilePath("/tmp");
869 } 884 }
870 885
871 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { 886 bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 if (HANDLE_EINTR(close(infile)) < 0) 925 if (HANDLE_EINTR(close(infile)) < 0)
911 result = false; 926 result = false;
912 if (HANDLE_EINTR(close(outfile)) < 0) 927 if (HANDLE_EINTR(close(outfile)) < 0)
913 result = false; 928 result = false;
914 929
915 return result; 930 return result;
916 } 931 }
917 #endif // defined(OS_MACOSX) 932 #endif // defined(OS_MACOSX)
918 933
919 } // namespace file_util 934 } // namespace file_util
OLDNEW
« no previous file with comments | « base/base_paths_android.cc ('k') | base/path_service.cc » ('j') | base/platform_file.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698