Chromium Code Reviews| 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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include "bin/file.h" | 8 #include "bin/file.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 if (old_fd < 0) { | 231 if (old_fd < 0) { |
| 232 return false; | 232 return false; |
| 233 } | 233 } |
| 234 int new_fd = TEMP_FAILURE_RETRY( | 234 int new_fd = TEMP_FAILURE_RETRY( |
| 235 open(new_path, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, st.st_mode)); | 235 open(new_path, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, st.st_mode)); |
| 236 if (new_fd < 0) { | 236 if (new_fd < 0) { |
| 237 VOID_TEMP_FAILURE_RETRY(close(old_fd)); | 237 VOID_TEMP_FAILURE_RETRY(close(old_fd)); |
| 238 return false; | 238 return false; |
| 239 } | 239 } |
| 240 off64_t offset = 0; | 240 off64_t offset = 0; |
| 241 int bytes = 1; | 241 int result = 1; |
| 242 while (bytes > 0) { | 242 while (result > 0) { |
| 243 // Loop to ensure we copy everything, and not only up to 2GB. | 243 // Loop to ensure we copy everything, and not only up to 2GB. |
| 244 bytes = TEMP_FAILURE_RETRY( | 244 result = TEMP_FAILURE_RETRY( |
| 245 sendfile(new_fd, old_fd, &offset, kMaxUint32)); | 245 sendfile(new_fd, old_fd, &offset, kMaxUint32)); |
| 246 } | 246 } |
| 247 if (bytes < 0) { | 247 if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { |
| 248 const intptr_t kBufferSize = 8 * 1024; | |
| 249 uint8_t buffer[kBufferSize]; | |
| 250 while ((result = TEMP_FAILURE_RETRY( | |
| 251 read(old_fd, buffer, kBufferSize))) > 0) { | |
| 252 int wrote = TEMP_FAILURE_RETRY(write(new_fd, buffer, result)); | |
| 253 if (wrote != result) { | |
|
Bill Hesse
2013/12/13 14:17:59
LGTM, with result = wrote changed to result = -1.
| |
| 254 result = wrote; | |
| 255 break; | |
| 256 } | |
| 257 } | |
| 258 } | |
| 259 if (result < 0) { | |
| 248 int e = errno; | 260 int e = errno; |
| 249 VOID_TEMP_FAILURE_RETRY(close(old_fd)); | 261 VOID_TEMP_FAILURE_RETRY(close(old_fd)); |
| 250 VOID_TEMP_FAILURE_RETRY(close(new_fd)); | 262 VOID_TEMP_FAILURE_RETRY(close(new_fd)); |
| 251 VOID_TEMP_FAILURE_RETRY(unlink(new_path)); | 263 VOID_TEMP_FAILURE_RETRY(unlink(new_path)); |
| 252 errno = e; | 264 errno = e; |
| 253 return false; | 265 return false; |
| 254 } | 266 } |
| 255 return true; | 267 return true; |
| 256 } else if (type == kIsDirectory) { | 268 } else if (type == kIsDirectory) { |
| 257 errno = EISDIR; | 269 errno = EISDIR; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 return (file_1_info.st_ino == file_2_info.st_ino && | 412 return (file_1_info.st_ino == file_2_info.st_ino && |
| 401 file_1_info.st_dev == file_2_info.st_dev) ? | 413 file_1_info.st_dev == file_2_info.st_dev) ? |
| 402 File::kIdentical : | 414 File::kIdentical : |
| 403 File::kDifferent; | 415 File::kDifferent; |
| 404 } | 416 } |
| 405 | 417 |
| 406 } // namespace bin | 418 } // namespace bin |
| 407 } // namespace dart | 419 } // namespace dart |
| 408 | 420 |
| 409 #endif // defined(TARGET_OS_ANDROID) | 421 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |