| 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/files/file_util.h" | 5 #include "base/files/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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "base/android/content_uri_utils.h" | 50 #include "base/android/content_uri_utils.h" |
| 51 #include "base/os_compat_android.h" | 51 #include "base/os_compat_android.h" |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 #if !defined(OS_IOS) | 54 #if !defined(OS_IOS) |
| 55 #include <grp.h> | 55 #include <grp.h> |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 namespace base { | 58 namespace base { |
| 59 | 59 |
| 60 #if !defined(OS_NACL_NONSFI) | |
| 61 namespace { | 60 namespace { |
| 62 | 61 |
| 63 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) | 62 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) |
| 64 static int CallStat(const char *path, stat_wrapper_t *sb) { | 63 static int CallStat(const char *path, stat_wrapper_t *sb) { |
| 65 ThreadRestrictions::AssertIOAllowed(); | 64 ThreadRestrictions::AssertIOAllowed(); |
| 66 return stat(path, sb); | 65 return stat(path, sb); |
| 67 } | 66 } |
| 68 static int CallLstat(const char *path, stat_wrapper_t *sb) { | 67 static int CallLstat(const char *path, stat_wrapper_t *sb) { |
| 69 ThreadRestrictions::AssertIOAllowed(); | 68 ThreadRestrictions::AssertIOAllowed(); |
| 70 return lstat(path, sb); | 69 return lstat(path, sb); |
| 71 } | 70 } |
| 72 #else // defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) | 71 #else // defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) |
| 73 static int CallStat(const char *path, stat_wrapper_t *sb) { | 72 static int CallStat(const char *path, stat_wrapper_t *sb) { |
| 74 ThreadRestrictions::AssertIOAllowed(); | 73 ThreadRestrictions::AssertIOAllowed(); |
| 75 return stat64(path, sb); | 74 return stat64(path, sb); |
| 76 } | 75 } |
| 77 static int CallLstat(const char *path, stat_wrapper_t *sb) { | 76 static int CallLstat(const char *path, stat_wrapper_t *sb) { |
| 78 ThreadRestrictions::AssertIOAllowed(); | 77 ThreadRestrictions::AssertIOAllowed(); |
| 79 return lstat64(path, sb); | 78 return lstat64(path, sb); |
| 80 } | 79 } |
| 81 #endif // !(defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL)) | 80 #endif // !(defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL)) |
| 82 | 81 |
| 82 #if !defined(OS_NACL_NONSFI) |
| 83 // Helper for NormalizeFilePath(), defined below. | 83 // Helper for NormalizeFilePath(), defined below. |
| 84 bool RealPath(const FilePath& path, FilePath* real_path) { | 84 bool RealPath(const FilePath& path, FilePath* real_path) { |
| 85 ThreadRestrictions::AssertIOAllowed(); // For realpath(). | 85 ThreadRestrictions::AssertIOAllowed(); // For realpath(). |
| 86 FilePath::CharType buf[PATH_MAX]; | 86 FilePath::CharType buf[PATH_MAX]; |
| 87 if (!realpath(path.value().c_str(), buf)) | 87 if (!realpath(path.value().c_str(), buf)) |
| 88 return false; | 88 return false; |
| 89 | 89 |
| 90 *real_path = FilePath(buf); | 90 *real_path = FilePath(buf); |
| 91 return true; | 91 return true; |
| 92 } | 92 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 void* mapping = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd.get(), 0); | 175 void* mapping = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd.get(), 0); |
| 176 if (mapping != MAP_FAILED) { | 176 if (mapping != MAP_FAILED) { |
| 177 if (mprotect(mapping, pagesize, PROT_READ | PROT_EXEC) == 0) | 177 if (mprotect(mapping, pagesize, PROT_READ | PROT_EXEC) == 0) |
| 178 result = true; | 178 result = true; |
| 179 munmap(mapping, pagesize); | 179 munmap(mapping, pagesize); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 return result; | 182 return result; |
| 183 } | 183 } |
| 184 #endif // defined(OS_LINUX) | 184 #endif // defined(OS_LINUX) |
| 185 #endif // !defined(OS_NACL_NONSFI) |
| 185 | 186 |
| 186 } // namespace | 187 } // namespace |
| 187 | 188 |
| 189 #if !defined(OS_NACL_NONSFI) |
| 188 FilePath MakeAbsoluteFilePath(const FilePath& input) { | 190 FilePath MakeAbsoluteFilePath(const FilePath& input) { |
| 189 ThreadRestrictions::AssertIOAllowed(); | 191 ThreadRestrictions::AssertIOAllowed(); |
| 190 char full_path[PATH_MAX]; | 192 char full_path[PATH_MAX]; |
| 191 if (realpath(input.value().c_str(), full_path) == NULL) | 193 if (realpath(input.value().c_str(), full_path) == NULL) |
| 192 return FilePath(); | 194 return FilePath(); |
| 193 return FilePath(full_path); | 195 return FilePath(full_path); |
| 194 } | 196 } |
| 195 | 197 |
| 196 // TODO(erikkay): The Windows version of this accepts paths like "foo/bar/*" | 198 // TODO(erikkay): The Windows version of this accepts paths like "foo/bar/*" |
| 197 // which works both with and without the recursive flag. I'm not sure we need | 199 // which works both with and without the recursive flag. I'm not sure we need |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 } | 358 } |
| 357 #endif | 359 #endif |
| 358 return access(path.value().c_str(), F_OK) == 0; | 360 return access(path.value().c_str(), F_OK) == 0; |
| 359 } | 361 } |
| 360 | 362 |
| 361 #if !defined(OS_NACL_NONSFI) | 363 #if !defined(OS_NACL_NONSFI) |
| 362 bool PathIsWritable(const FilePath& path) { | 364 bool PathIsWritable(const FilePath& path) { |
| 363 ThreadRestrictions::AssertIOAllowed(); | 365 ThreadRestrictions::AssertIOAllowed(); |
| 364 return access(path.value().c_str(), W_OK) == 0; | 366 return access(path.value().c_str(), W_OK) == 0; |
| 365 } | 367 } |
| 368 #endif // !defined(OS_NACL_NONSFI) |
| 366 | 369 |
| 367 bool DirectoryExists(const FilePath& path) { | 370 bool DirectoryExists(const FilePath& path) { |
| 368 ThreadRestrictions::AssertIOAllowed(); | 371 ThreadRestrictions::AssertIOAllowed(); |
| 369 stat_wrapper_t file_info; | 372 stat_wrapper_t file_info; |
| 370 if (CallStat(path.value().c_str(), &file_info) == 0) | 373 if (CallStat(path.value().c_str(), &file_info) == 0) |
| 371 return S_ISDIR(file_info.st_mode); | 374 return S_ISDIR(file_info.st_mode); |
| 372 return false; | 375 return false; |
| 373 } | 376 } |
| 374 #endif // !defined(OS_NACL_NONSFI) | |
| 375 | 377 |
| 376 bool ReadFromFD(int fd, char* buffer, size_t bytes) { | 378 bool ReadFromFD(int fd, char* buffer, size_t bytes) { |
| 377 size_t total_read = 0; | 379 size_t total_read = 0; |
| 378 while (total_read < bytes) { | 380 while (total_read < bytes) { |
| 379 ssize_t bytes_read = | 381 ssize_t bytes_read = |
| 380 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read)); | 382 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read)); |
| 381 if (bytes_read <= 0) | 383 if (bytes_read <= 0) |
| 382 break; | 384 break; |
| 383 total_read += bytes_read; | 385 total_read += bytes_read; |
| 384 } | 386 } |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 return false; | 923 return false; |
| 922 | 924 |
| 923 DeleteFile(from_path, true); | 925 DeleteFile(from_path, true); |
| 924 return true; | 926 return true; |
| 925 } | 927 } |
| 926 | 928 |
| 927 } // namespace internal | 929 } // namespace internal |
| 928 | 930 |
| 929 #endif // !defined(OS_NACL_NONSFI) | 931 #endif // !defined(OS_NACL_NONSFI) |
| 930 } // namespace base | 932 } // namespace base |
| OLD | NEW |