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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 char full_path[PATH_MAX]; | 153 char full_path[PATH_MAX]; |
154 if (realpath(input.value().c_str(), full_path) == NULL) | 154 if (realpath(input.value().c_str(), full_path) == NULL) |
155 return FilePath(); | 155 return FilePath(); |
156 return FilePath(full_path); | 156 return FilePath(full_path); |
157 } | 157 } |
158 | 158 |
159 // TODO(erikkay): The Windows version of this accepts paths like "foo/bar/*" | 159 // TODO(erikkay): The Windows version of this accepts paths like "foo/bar/*" |
160 // which works both with and without the recursive flag. I'm not sure we need | 160 // which works both with and without the recursive flag. I'm not sure we need |
161 // that functionality. If not, remove from file_util_win.cc, otherwise add it | 161 // that functionality. If not, remove from file_util_win.cc, otherwise add it |
162 // here. | 162 // here. |
163 bool Delete(const FilePath& path, bool recursive) { | 163 bool DeleteFile(const FilePath& path, bool recursive) { |
164 ThreadRestrictions::AssertIOAllowed(); | 164 ThreadRestrictions::AssertIOAllowed(); |
165 const char* path_str = path.value().c_str(); | 165 const char* path_str = path.value().c_str(); |
166 stat_wrapper_t file_info; | 166 stat_wrapper_t file_info; |
167 int test = CallLstat(path_str, &file_info); | 167 int test = CallLstat(path_str, &file_info); |
168 if (test != 0) { | 168 if (test != 0) { |
169 // The Windows version defines this condition as success. | 169 // The Windows version defines this condition as success. |
170 bool ret = (errno == ENOENT || errno == ENOTDIR); | 170 bool ret = (errno == ENOENT || errno == ENOTDIR); |
171 return ret; | 171 return ret; |
172 } | 172 } |
173 if (!S_ISDIR(file_info.st_mode)) | 173 if (!S_ISDIR(file_info.st_mode)) |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 // but its kernel allows mprotect with PROT_EXEC anyway. | 728 // but its kernel allows mprotect with PROT_EXEC anyway. |
729 | 729 |
730 namespace { | 730 namespace { |
731 | 731 |
732 bool DetermineDevShmExecutable() { | 732 bool DetermineDevShmExecutable() { |
733 bool result = false; | 733 bool result = false; |
734 FilePath path; | 734 FilePath path; |
735 int fd = CreateAndOpenFdForTemporaryFile(FilePath("/dev/shm"), &path); | 735 int fd = CreateAndOpenFdForTemporaryFile(FilePath("/dev/shm"), &path); |
736 if (fd >= 0) { | 736 if (fd >= 0) { |
737 ScopedFD shm_fd_closer(&fd); | 737 ScopedFD shm_fd_closer(&fd); |
738 Delete(path, false); | 738 DeleteFile(path, false); |
739 long sysconf_result = sysconf(_SC_PAGESIZE); | 739 long sysconf_result = sysconf(_SC_PAGESIZE); |
740 CHECK_GE(sysconf_result, 0); | 740 CHECK_GE(sysconf_result, 0); |
741 size_t pagesize = static_cast<size_t>(sysconf_result); | 741 size_t pagesize = static_cast<size_t>(sysconf_result); |
742 CHECK_GE(sizeof(pagesize), sizeof(sysconf_result)); | 742 CHECK_GE(sizeof(pagesize), sizeof(sysconf_result)); |
743 void *mapping = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0); | 743 void *mapping = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0); |
744 if (mapping != MAP_FAILED) { | 744 if (mapping != MAP_FAILED) { |
745 if (mprotect(mapping, pagesize, PROT_READ | PROT_EXEC) == 0) | 745 if (mprotect(mapping, pagesize, PROT_READ | PROT_EXEC) == 0) |
746 result = true; | 746 result = true; |
747 munmap(mapping, pagesize); | 747 munmap(mapping, pagesize); |
748 } | 748 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 return false; | 893 return false; |
894 } | 894 } |
895 } | 895 } |
896 | 896 |
897 if (rename(from_path.value().c_str(), to_path.value().c_str()) == 0) | 897 if (rename(from_path.value().c_str(), to_path.value().c_str()) == 0) |
898 return true; | 898 return true; |
899 | 899 |
900 if (!CopyDirectory(from_path, to_path, true)) | 900 if (!CopyDirectory(from_path, to_path, true)) |
901 return false; | 901 return false; |
902 | 902 |
903 Delete(from_path, true); | 903 DeleteFile(from_path, true); |
904 return true; | 904 return true; |
905 } | 905 } |
906 | 906 |
907 #if !defined(OS_MACOSX) | 907 #if !defined(OS_MACOSX) |
908 // Mac has its own implementation, this is for all other Posix systems. | 908 // Mac has its own implementation, this is for all other Posix systems. |
909 bool CopyFileUnsafe(const FilePath& from_path, const FilePath& to_path) { | 909 bool CopyFileUnsafe(const FilePath& from_path, const FilePath& to_path) { |
910 ThreadRestrictions::AssertIOAllowed(); | 910 ThreadRestrictions::AssertIOAllowed(); |
911 int infile = HANDLE_EINTR(open(from_path.value().c_str(), O_RDONLY)); | 911 int infile = HANDLE_EINTR(open(from_path.value().c_str(), O_RDONLY)); |
912 if (infile < 0) | 912 if (infile < 0) |
913 return false; | 913 return false; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 result = false; | 949 result = false; |
950 if (HANDLE_EINTR(close(outfile)) < 0) | 950 if (HANDLE_EINTR(close(outfile)) < 0) |
951 result = false; | 951 result = false; |
952 | 952 |
953 return result; | 953 return result; |
954 } | 954 } |
955 #endif // !defined(OS_MACOSX) | 955 #endif // !defined(OS_MACOSX) |
956 | 956 |
957 } // namespace internal | 957 } // namespace internal |
958 } // namespace base | 958 } // namespace base |
OLD | NEW |