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 |
| 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 <unistd.h> // NOLINT | 15 #include <unistd.h> // NOLINT |
| 15 #include <libgen.h> // NOLINT | 16 #include <libgen.h> // NOLINT |
| 16 | 17 |
| 17 #include "bin/builtin.h" | 18 #include "bin/builtin.h" |
| 18 #include "bin/log.h" | 19 #include "bin/log.h" |
| 19 | 20 |
| 20 | 21 |
| 21 namespace dart { | 22 namespace dart { |
| 22 namespace bin { | 23 namespace bin { |
| 23 | 24 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 return TEMP_FAILURE_RETRY(rename(old_path, new_path)) == 0; | 213 return TEMP_FAILURE_RETRY(rename(old_path, new_path)) == 0; |
| 213 } else if (type == kIsDirectory) { | 214 } else if (type == kIsDirectory) { |
| 214 errno = EISDIR; | 215 errno = EISDIR; |
| 215 } else { | 216 } else { |
| 216 errno = EINVAL; | 217 errno = EINVAL; |
| 217 } | 218 } |
| 218 return false; | 219 return false; |
| 219 } | 220 } |
| 220 | 221 |
| 221 | 222 |
| 223 bool File::Copy(const char* old_path, const char* new_path) { | |
| 224 File::Type type = File::GetType(old_path, true); | |
| 225 if (type == kIsFile) { | |
| 226 int old_fd = TEMP_FAILURE_RETRY(open(old_path, O_RDONLY | O_CLOEXEC)); | |
| 227 if (old_fd < 0) { | |
| 228 return false; | |
| 229 } | |
| 230 int new_fd = TEMP_FAILURE_RETRY( | |
| 231 open(new_path, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0666)); | |
|
Søren Gjesse
2013/12/13 11:32:09
0666 -> 0777?
Søren Gjesse
2013/12/13 11:57:38
Actually that should be the mode of the source.
Anders Johnsen
2013/12/13 12:04:17
Done.
| |
| 232 if (new_fd < 0) { | |
| 233 VOID_TEMP_FAILURE_RETRY(close(old_fd)); | |
| 234 return false; | |
| 235 } | |
| 236 off64_t offset = 0; | |
| 237 int bytes = 1; | |
| 238 while (bytes > 0) { | |
| 239 // Loop to ensure we copy everything, and not only up to 2GB. | |
| 240 bytes = TEMP_FAILURE_RETRY(sendfile(new_fd, old_fd, &offset, -1)); | |
| 241 } | |
| 242 if (bytes < 0) { | |
| 243 int e = errno; | |
| 244 VOID_TEMP_FAILURE_RETRY(close(old_fd)); | |
| 245 VOID_TEMP_FAILURE_RETRY(close(new_fd)); | |
| 246 VOID_TEMP_FAILURE_RETRY(unlink(new_path)); | |
| 247 errno = e; | |
| 248 return false; | |
| 249 } | |
| 250 return true; | |
| 251 } else if (type == kIsDirectory) { | |
| 252 errno = EISDIR; | |
| 253 } else { | |
| 254 errno = ENOENT; | |
| 255 } | |
| 256 return false; | |
| 257 } | |
| 258 | |
| 259 | |
| 222 off64_t File::LengthFromPath(const char* name) { | 260 off64_t File::LengthFromPath(const char* name) { |
| 223 struct stat st; | 261 struct stat st; |
| 224 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 262 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
| 225 return st.st_size; | 263 return st.st_size; |
| 226 } | 264 } |
| 227 return -1; | 265 return -1; |
| 228 } | 266 } |
| 229 | 267 |
| 230 | 268 |
| 231 void File::Stat(const char* name, int64_t* data) { | 269 void File::Stat(const char* name, int64_t* data) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 return (file_1_info.st_ino == file_2_info.st_ino && | 395 return (file_1_info.st_ino == file_2_info.st_ino && |
| 358 file_1_info.st_dev == file_2_info.st_dev) ? | 396 file_1_info.st_dev == file_2_info.st_dev) ? |
| 359 File::kIdentical : | 397 File::kIdentical : |
| 360 File::kDifferent; | 398 File::kDifferent; |
| 361 } | 399 } |
| 362 | 400 |
| 363 } // namespace bin | 401 } // namespace bin |
| 364 } // namespace dart | 402 } // namespace dart |
| 365 | 403 |
| 366 #endif // defined(TARGET_OS_ANDROID) | 404 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |