| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 7 | 7 |
| 8 #include "bin/file.h" | 8 #include "bin/file.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| 11 #include <fcntl.h> // NOLINT | 11 #include <fcntl.h> // NOLINT |
| 12 #include <sys/stat.h> // NOLINT | 12 #include <sys/stat.h> // NOLINT |
| 13 #include <sys/types.h> // NOLINT | 13 #include <sys/types.h> // NOLINT |
| 14 #include <sys/sendfile.h> // NOLINT | 14 #include <sys/sendfile.h> // NOLINT |
| 15 #include <unistd.h> // NOLINT | 15 #include <unistd.h> // NOLINT |
| 16 #include <libgen.h> // NOLINT | 16 #include <libgen.h> // NOLINT |
| 17 | 17 |
| 18 #include "platform/signal_blocker.h" |
| 18 #include "bin/builtin.h" | 19 #include "bin/builtin.h" |
| 19 #include "bin/log.h" | 20 #include "bin/log.h" |
| 20 #include "bin/signal_blocker.h" | |
| 21 | 21 |
| 22 | 22 |
| 23 namespace dart { | 23 namespace dart { |
| 24 namespace bin { | 24 namespace bin { |
| 25 | 25 |
| 26 class FileHandle { | 26 class FileHandle { |
| 27 public: | 27 public: |
| 28 explicit FileHandle(int fd) : fd_(fd) { } | 28 explicit FileHandle(int fd) : fd_(fd) { } |
| 29 ~FileHandle() { } | 29 ~FileHandle() { } |
| 30 int fd() const { return fd_; } | 30 int fd() const { return fd_; } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 45 | 45 |
| 46 void File::Close() { | 46 void File::Close() { |
| 47 ASSERT(handle_->fd() >= 0); | 47 ASSERT(handle_->fd() >= 0); |
| 48 if (handle_->fd() == STDOUT_FILENO) { | 48 if (handle_->fd() == STDOUT_FILENO) { |
| 49 // If stdout, redirect fd to /dev/null. | 49 // If stdout, redirect fd to /dev/null. |
| 50 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); | 50 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); |
| 51 ASSERT(null_fd >= 0); | 51 ASSERT(null_fd >= 0); |
| 52 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd())); | 52 VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd())); |
| 53 VOID_TEMP_FAILURE_RETRY(close(null_fd)); | 53 VOID_TEMP_FAILURE_RETRY(close(null_fd)); |
| 54 } else { | 54 } else { |
| 55 int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(handle_->fd())); | 55 int err = TEMP_FAILURE_RETRY(close(handle_->fd())); |
| 56 if (err != 0) { | 56 if (err != 0) { |
| 57 const int kBufferSize = 1024; | 57 const int kBufferSize = 1024; |
| 58 char error_buf[kBufferSize]; | 58 char error_buf[kBufferSize]; |
| 59 Log::PrintErr("%s\n", strerror_r(errno, error_buf, kBufferSize)); | 59 Log::PrintErr("%s\n", strerror_r(errno, error_buf, kBufferSize)); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 handle_->set_fd(kClosedFd); | 62 handle_->set_fd(kClosedFd); |
| 63 } | 63 } |
| 64 | 64 |
| 65 | 65 |
| 66 bool File::IsClosed() { | 66 bool File::IsClosed() { |
| 67 return handle_->fd() == kClosedFd; | 67 return handle_->fd() == kClosedFd; |
| 68 } | 68 } |
| 69 | 69 |
| 70 | 70 |
| 71 int64_t File::Read(void* buffer, int64_t num_bytes) { | 71 int64_t File::Read(void* buffer, int64_t num_bytes) { |
| 72 ASSERT(handle_->fd() >= 0); | 72 ASSERT(handle_->fd() >= 0); |
| 73 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(read(handle_->fd(), buffer, | 73 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
| 74 num_bytes)); | |
| 75 } | 74 } |
| 76 | 75 |
| 77 | 76 |
| 78 int64_t File::Write(const void* buffer, int64_t num_bytes) { | 77 int64_t File::Write(const void* buffer, int64_t num_bytes) { |
| 79 ASSERT(handle_->fd() >= 0); | 78 ASSERT(handle_->fd() >= 0); |
| 80 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(write(handle_->fd(), buffer, | 79 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); |
| 81 num_bytes)); | |
| 82 } | 80 } |
| 83 | 81 |
| 84 | 82 |
| 85 int64_t File::Position() { | 83 int64_t File::Position() { |
| 86 ASSERT(handle_->fd() >= 0); | 84 ASSERT(handle_->fd() >= 0); |
| 87 return lseek64(handle_->fd(), 0, SEEK_CUR); | 85 return lseek64(handle_->fd(), 0, SEEK_CUR); |
| 88 } | 86 } |
| 89 | 87 |
| 90 | 88 |
| 91 bool File::SetPosition(int64_t position) { | 89 bool File::SetPosition(int64_t position) { |
| 92 ASSERT(handle_->fd() >= 0); | 90 ASSERT(handle_->fd() >= 0); |
| 93 return lseek64(handle_->fd(), position, SEEK_SET) >= 0; | 91 return lseek64(handle_->fd(), position, SEEK_SET) >= 0; |
| 94 } | 92 } |
| 95 | 93 |
| 96 | 94 |
| 97 bool File::Truncate(int64_t length) { | 95 bool File::Truncate(int64_t length) { |
| 98 ASSERT(handle_->fd() >= 0); | 96 ASSERT(handle_->fd() >= 0); |
| 99 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS( | 97 return TEMP_FAILURE_RETRY(ftruncate64(handle_->fd(), length) != -1); |
| 100 ftruncate64(handle_->fd(), length) != -1); | |
| 101 } | 98 } |
| 102 | 99 |
| 103 | 100 |
| 104 bool File::Flush() { | 101 bool File::Flush() { |
| 105 ASSERT(handle_->fd() >= 0); | 102 ASSERT(handle_->fd() >= 0); |
| 106 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fsync(handle_->fd()) != -1); | 103 return fsync(handle_->fd()) != -1; |
| 107 } | 104 } |
| 108 | 105 |
| 109 | 106 |
| 110 int64_t File::Length() { | 107 int64_t File::Length() { |
| 111 ASSERT(handle_->fd() >= 0); | 108 ASSERT(handle_->fd() >= 0); |
| 112 struct stat64 st; | 109 struct stat64 st; |
| 113 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fstat64(handle_->fd(), &st)) == 0) { | 110 if (fstat64(handle_->fd(), &st) == 0) { |
| 114 return st.st_size; | 111 return st.st_size; |
| 115 } | 112 } |
| 116 return -1; | 113 return -1; |
| 117 } | 114 } |
| 118 | 115 |
| 119 | 116 |
| 120 File* File::Open(const char* name, FileOpenMode mode) { | 117 File* File::Open(const char* name, FileOpenMode mode) { |
| 121 // Report errors for non-regular files. | 118 // Report errors for non-regular files. |
| 122 struct stat64 st; | 119 struct stat64 st; |
| 123 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) { | 120 if (stat64(name, &st) == 0) { |
| 124 // Only accept regular files and character devices. | 121 // Only accept regular files and character devices. |
| 125 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) { | 122 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) { |
| 126 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; | 123 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
| 127 return NULL; | 124 return NULL; |
| 128 } | 125 } |
| 129 } | 126 } |
| 130 int flags = O_RDONLY; | 127 int flags = O_RDONLY; |
| 131 if ((mode & kWrite) != 0) { | 128 if ((mode & kWrite) != 0) { |
| 132 flags = (O_RDWR | O_CREAT); | 129 flags = (O_RDWR | O_CREAT); |
| 133 } | 130 } |
| 134 if ((mode & kTruncate) != 0) { | 131 if ((mode & kTruncate) != 0) { |
| 135 flags = flags | O_TRUNC; | 132 flags = flags | O_TRUNC; |
| 136 } | 133 } |
| 137 flags |= O_CLOEXEC; | 134 flags |= O_CLOEXEC; |
| 138 int fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(open64(name, flags, 0666)); | 135 int fd = TEMP_FAILURE_RETRY(open64(name, flags, 0666)); |
| 139 if (fd < 0) { | 136 if (fd < 0) { |
| 140 return NULL; | 137 return NULL; |
| 141 } | 138 } |
| 142 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { | 139 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { |
| 143 int64_t position = lseek64(fd, 0, SEEK_END); | 140 int64_t position = lseek64(fd, 0, SEEK_END); |
| 144 if (position < 0) { | 141 if (position < 0) { |
| 145 return NULL; | 142 return NULL; |
| 146 } | 143 } |
| 147 } | 144 } |
| 148 return new File(new FileHandle(fd)); | 145 return new File(new FileHandle(fd)); |
| 149 } | 146 } |
| 150 | 147 |
| 151 | 148 |
| 152 File* File::OpenStdio(int fd) { | 149 File* File::OpenStdio(int fd) { |
| 153 if (fd < 0 || 2 < fd) return NULL; | 150 if (fd < 0 || 2 < fd) return NULL; |
| 154 return new File(new FileHandle(fd)); | 151 return new File(new FileHandle(fd)); |
| 155 } | 152 } |
| 156 | 153 |
| 157 | 154 |
| 158 bool File::Exists(const char* name) { | 155 bool File::Exists(const char* name) { |
| 159 struct stat64 st; | 156 struct stat64 st; |
| 160 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) { | 157 if (stat64(name, &st) == 0) { |
| 161 return S_ISREG(st.st_mode); | 158 return S_ISREG(st.st_mode); |
| 162 } else { | 159 } else { |
| 163 return false; | 160 return false; |
| 164 } | 161 } |
| 165 } | 162 } |
| 166 | 163 |
| 167 | 164 |
| 168 bool File::Create(const char* name) { | 165 bool File::Create(const char* name) { |
| 169 int fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( | 166 int fd = TEMP_FAILURE_RETRY( |
| 170 open64(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666)); | 167 open64(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666)); |
| 171 if (fd < 0) { | 168 if (fd < 0) { |
| 172 return false; | 169 return false; |
| 173 } | 170 } |
| 174 return (close(fd) == 0); | 171 return (close(fd) == 0); |
| 175 } | 172 } |
| 176 | 173 |
| 177 | 174 |
| 178 bool File::CreateLink(const char* name, const char* target) { | 175 bool File::CreateLink(const char* name, const char* target) { |
| 179 int status = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(symlink(target, name)); | 176 return symlink(target, name) == 0; |
| 180 return (status == 0); | |
| 181 } | 177 } |
| 182 | 178 |
| 183 | 179 |
| 184 bool File::Delete(const char* name) { | 180 bool File::Delete(const char* name) { |
| 185 File::Type type = File::GetType(name, true); | 181 File::Type type = File::GetType(name, true); |
| 186 if (type == kIsFile) { | 182 if (type == kIsFile) { |
| 187 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(unlink(name)) == 0; | 183 return unlink(name) == 0; |
| 188 } else if (type == kIsDirectory) { | 184 } else if (type == kIsDirectory) { |
| 189 errno = EISDIR; | 185 errno = EISDIR; |
| 190 } else { | 186 } else { |
| 191 errno = ENOENT; | 187 errno = ENOENT; |
| 192 } | 188 } |
| 193 return false; | 189 return false; |
| 194 } | 190 } |
| 195 | 191 |
| 196 | 192 |
| 197 bool File::DeleteLink(const char* name) { | 193 bool File::DeleteLink(const char* name) { |
| 198 File::Type type = File::GetType(name, false); | 194 File::Type type = File::GetType(name, false); |
| 199 if (type == kIsLink) { | 195 if (type == kIsLink) { |
| 200 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(unlink(name)) == 0; | 196 return unlink(name) == 0; |
| 201 } | 197 } |
| 202 errno = EINVAL; | 198 errno = EINVAL; |
| 203 return false; | 199 return false; |
| 204 } | 200 } |
| 205 | 201 |
| 206 | 202 |
| 207 bool File::Rename(const char* old_path, const char* new_path) { | 203 bool File::Rename(const char* old_path, const char* new_path) { |
| 208 File::Type type = File::GetType(old_path, true); | 204 File::Type type = File::GetType(old_path, true); |
| 209 if (type == kIsFile) { | 205 if (type == kIsFile) { |
| 210 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(rename(old_path, new_path)) == 0; | 206 return rename(old_path, new_path) == 0; |
| 211 } else if (type == kIsDirectory) { | 207 } else if (type == kIsDirectory) { |
| 212 errno = EISDIR; | 208 errno = EISDIR; |
| 213 } else { | 209 } else { |
| 214 errno = ENOENT; | 210 errno = ENOENT; |
| 215 } | 211 } |
| 216 return false; | 212 return false; |
| 217 } | 213 } |
| 218 | 214 |
| 219 | 215 |
| 220 bool File::RenameLink(const char* old_path, const char* new_path) { | 216 bool File::RenameLink(const char* old_path, const char* new_path) { |
| 221 File::Type type = File::GetType(old_path, false); | 217 File::Type type = File::GetType(old_path, false); |
| 222 if (type == kIsLink) { | 218 if (type == kIsLink) { |
| 223 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(rename(old_path, new_path)) == 0; | 219 return rename(old_path, new_path) == 0; |
| 224 } else if (type == kIsDirectory) { | 220 } else if (type == kIsDirectory) { |
| 225 errno = EISDIR; | 221 errno = EISDIR; |
| 226 } else { | 222 } else { |
| 227 errno = EINVAL; | 223 errno = EINVAL; |
| 228 } | 224 } |
| 229 return false; | 225 return false; |
| 230 } | 226 } |
| 231 | 227 |
| 232 | 228 |
| 233 bool File::Copy(const char* old_path, const char* new_path) { | 229 bool File::Copy(const char* old_path, const char* new_path) { |
| 234 File::Type type = File::GetType(old_path, true); | 230 File::Type type = File::GetType(old_path, true); |
| 235 if (type == kIsFile) { | 231 if (type == kIsFile) { |
| 236 struct stat64 st; | 232 struct stat64 st; |
| 237 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(old_path, &st)) != 0) { | 233 if (stat64(old_path, &st) != 0) { |
| 238 return false; | 234 return false; |
| 239 } | 235 } |
| 240 int old_fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(open64(old_path, | 236 int old_fd = TEMP_FAILURE_RETRY(open64(old_path, O_RDONLY | O_CLOEXEC)); |
| 241 O_RDONLY | O_CLOEXEC)); | |
| 242 if (old_fd < 0) { | 237 if (old_fd < 0) { |
| 243 return false; | 238 return false; |
| 244 } | 239 } |
| 245 int new_fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( | 240 int new_fd = TEMP_FAILURE_RETRY( |
| 246 open64(new_path, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, st.st_mode)); | 241 open64(new_path, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, st.st_mode)); |
| 247 if (new_fd < 0) { | 242 if (new_fd < 0) { |
| 248 VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(old_fd)); | 243 VOID_TEMP_FAILURE_RETRY(close(old_fd)); |
| 249 return false; | 244 return false; |
| 250 } | 245 } |
| 251 int64_t offset = 0; | 246 int64_t offset = 0; |
| 252 intptr_t result = 1; | 247 intptr_t result = 1; |
| 253 while (result > 0) { | 248 while (result > 0) { |
| 254 // Loop to ensure we copy everything, and not only up to 2GB. | 249 // Loop to ensure we copy everything, and not only up to 2GB. |
| 255 result = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( | 250 result = sendfile64(new_fd, old_fd, &offset, kMaxUint32); |
| 256 sendfile64(new_fd, old_fd, &offset, kMaxUint32)); | |
| 257 } | 251 } |
| 258 // From sendfile man pages: | 252 // From sendfile man pages: |
| 259 // Applications may wish to fall back to read(2)/write(2) in the case | 253 // Applications may wish to fall back to read(2)/write(2) in the case |
| 260 // where sendfile() fails with EINVAL or ENOSYS. | 254 // where sendfile() fails with EINVAL or ENOSYS. |
| 261 if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { | 255 if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { |
| 262 const intptr_t kBufferSize = 8 * KB; | 256 const intptr_t kBufferSize = 8 * KB; |
| 263 uint8_t buffer[kBufferSize]; | 257 uint8_t buffer[kBufferSize]; |
| 264 while ((result = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( | 258 while ((result = TEMP_FAILURE_RETRY( |
| 265 read(old_fd, buffer, kBufferSize))) > 0) { | 259 read(old_fd, buffer, kBufferSize))) > 0) { |
| 266 int wrote = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(write(new_fd, buffer, | 260 int wrote = TEMP_FAILURE_RETRY(write(new_fd, buffer, result)); |
| 267 result)); | |
| 268 if (wrote != result) { | 261 if (wrote != result) { |
| 269 result = -1; | 262 result = -1; |
| 270 break; | 263 break; |
| 271 } | 264 } |
| 272 } | 265 } |
| 273 } | 266 } |
| 274 if (result < 0) { | 267 if (result < 0) { |
| 275 int e = errno; | 268 int e = errno; |
| 276 VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(old_fd)); | 269 VOID_TEMP_FAILURE_RETRY(close(old_fd)); |
| 277 VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(new_fd)); | 270 VOID_TEMP_FAILURE_RETRY(close(new_fd)); |
| 278 VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(unlink(new_path)); | 271 unlink(new_path); |
| 279 errno = e; | 272 errno = e; |
| 280 return false; | 273 return false; |
| 281 } | 274 } |
| 282 return true; | 275 return true; |
| 283 } else if (type == kIsDirectory) { | 276 } else if (type == kIsDirectory) { |
| 284 errno = EISDIR; | 277 errno = EISDIR; |
| 285 } else { | 278 } else { |
| 286 errno = ENOENT; | 279 errno = ENOENT; |
| 287 } | 280 } |
| 288 return false; | 281 return false; |
| 289 } | 282 } |
| 290 | 283 |
| 291 | 284 |
| 292 int64_t File::LengthFromPath(const char* name) { | 285 int64_t File::LengthFromPath(const char* name) { |
| 293 struct stat64 st; | 286 struct stat64 st; |
| 294 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) { | 287 if (stat64(name, &st) == 0) { |
| 295 return st.st_size; | 288 return st.st_size; |
| 296 } | 289 } |
| 297 return -1; | 290 return -1; |
| 298 } | 291 } |
| 299 | 292 |
| 300 | 293 |
| 301 void File::Stat(const char* name, int64_t* data) { | 294 void File::Stat(const char* name, int64_t* data) { |
| 302 struct stat64 st; | 295 struct stat64 st; |
| 303 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) { | 296 if (stat64(name, &st) == 0) { |
| 304 if (S_ISREG(st.st_mode)) { | 297 if (S_ISREG(st.st_mode)) { |
| 305 data[kType] = kIsFile; | 298 data[kType] = kIsFile; |
| 306 } else if (S_ISDIR(st.st_mode)) { | 299 } else if (S_ISDIR(st.st_mode)) { |
| 307 data[kType] = kIsDirectory; | 300 data[kType] = kIsDirectory; |
| 308 } else if (S_ISLNK(st.st_mode)) { | 301 } else if (S_ISLNK(st.st_mode)) { |
| 309 data[kType] = kIsLink; | 302 data[kType] = kIsLink; |
| 310 } else { | 303 } else { |
| 311 data[kType] = kDoesNotExist; | 304 data[kType] = kDoesNotExist; |
| 312 } | 305 } |
| 313 data[kCreatedTime] = st.st_ctime; | 306 data[kCreatedTime] = st.st_ctime; |
| 314 data[kModifiedTime] = st.st_mtime; | 307 data[kModifiedTime] = st.st_mtime; |
| 315 data[kAccessedTime] = st.st_atime; | 308 data[kAccessedTime] = st.st_atime; |
| 316 data[kMode] = st.st_mode; | 309 data[kMode] = st.st_mode; |
| 317 data[kSize] = st.st_size; | 310 data[kSize] = st.st_size; |
| 318 } else { | 311 } else { |
| 319 data[kType] = kDoesNotExist; | 312 data[kType] = kDoesNotExist; |
| 320 } | 313 } |
| 321 } | 314 } |
| 322 | 315 |
| 323 | 316 |
| 324 time_t File::LastModified(const char* name) { | 317 time_t File::LastModified(const char* name) { |
| 325 struct stat64 st; | 318 struct stat64 st; |
| 326 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) { | 319 if (stat64(name, &st) == 0) { |
| 327 return st.st_mtime; | 320 return st.st_mtime; |
| 328 } | 321 } |
| 329 return -1; | 322 return -1; |
| 330 } | 323 } |
| 331 | 324 |
| 332 | 325 |
| 333 char* File::LinkTarget(const char* pathname) { | 326 char* File::LinkTarget(const char* pathname) { |
| 334 struct stat64 link_stats; | 327 struct stat64 link_stats; |
| 335 if (lstat64(pathname, &link_stats) != 0) return NULL; | 328 if (lstat64(pathname, &link_stats) != 0) return NULL; |
| 336 if (!S_ISLNK(link_stats.st_mode)) { | 329 if (!S_ISLNK(link_stats.st_mode)) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 if (S_ISSOCK(buf.st_mode)) return kSocket; | 384 if (S_ISSOCK(buf.st_mode)) return kSocket; |
| 392 if (S_ISREG(buf.st_mode)) return kFile; | 385 if (S_ISREG(buf.st_mode)) return kFile; |
| 393 return kOther; | 386 return kOther; |
| 394 } | 387 } |
| 395 | 388 |
| 396 | 389 |
| 397 File::Type File::GetType(const char* pathname, bool follow_links) { | 390 File::Type File::GetType(const char* pathname, bool follow_links) { |
| 398 struct stat64 entry_info; | 391 struct stat64 entry_info; |
| 399 int stat_success; | 392 int stat_success; |
| 400 if (follow_links) { | 393 if (follow_links) { |
| 401 stat_success = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(pathname, | 394 stat_success = stat64(pathname, &entry_info); |
| 402 &entry_info)); | |
| 403 } else { | 395 } else { |
| 404 stat_success = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(lstat64(pathname, | 396 stat_success = lstat64(pathname, &entry_info); |
| 405 &entry_info)); | |
| 406 } | 397 } |
| 407 if (stat_success == -1) return File::kDoesNotExist; | 398 if (stat_success == -1) return File::kDoesNotExist; |
| 408 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; | 399 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; |
| 409 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; | 400 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; |
| 410 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; | 401 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; |
| 411 return File::kDoesNotExist; | 402 return File::kDoesNotExist; |
| 412 } | 403 } |
| 413 | 404 |
| 414 | 405 |
| 415 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { | 406 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { |
| 416 struct stat64 file_1_info; | 407 struct stat64 file_1_info; |
| 417 struct stat64 file_2_info; | 408 struct stat64 file_2_info; |
| 418 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(lstat64(file_1, &file_1_info)) == -1 || | 409 if (lstat64(file_1, &file_1_info) == -1 || |
| 419 TEMP_FAILURE_RETRY_BLOCK_SIGNALS(lstat64(file_2, &file_2_info)) == -1) { | 410 lstat64(file_2, &file_2_info) == -1) { |
| 420 return File::kError; | 411 return File::kError; |
| 421 } | 412 } |
| 422 return (file_1_info.st_ino == file_2_info.st_ino && | 413 return (file_1_info.st_ino == file_2_info.st_ino && |
| 423 file_1_info.st_dev == file_2_info.st_dev) ? | 414 file_1_info.st_dev == file_2_info.st_dev) ? |
| 424 File::kIdentical : | 415 File::kIdentical : |
| 425 File::kDifferent; | 416 File::kDifferent; |
| 426 } | 417 } |
| 427 | 418 |
| 428 } // namespace bin | 419 } // namespace bin |
| 429 } // namespace dart | 420 } // namespace dart |
| 430 | 421 |
| 431 #endif // defined(TARGET_OS_LINUX) | 422 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |