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_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
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 <copyfile.h> // NOLINT |
12 #include <sys/stat.h> // NOLINT | 13 #include <sys/stat.h> // NOLINT |
13 #include <unistd.h> // NOLINT | 14 #include <unistd.h> // NOLINT |
14 #include <libgen.h> // NOLINT | 15 #include <libgen.h> // NOLINT |
15 #include <limits.h> // NOLINT | 16 #include <limits.h> // NOLINT |
16 | 17 |
17 #include "bin/builtin.h" | 18 #include "bin/builtin.h" |
18 #include "bin/fdutils.h" | 19 #include "bin/fdutils.h" |
19 #include "bin/log.h" | 20 #include "bin/log.h" |
20 | 21 |
21 | 22 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 return TEMP_FAILURE_RETRY(rename(old_path, new_path)) == 0; | 215 return TEMP_FAILURE_RETRY(rename(old_path, new_path)) == 0; |
215 } else if (type == kIsDirectory) { | 216 } else if (type == kIsDirectory) { |
216 errno = EISDIR; | 217 errno = EISDIR; |
217 } else { | 218 } else { |
218 errno = EINVAL; | 219 errno = EINVAL; |
219 } | 220 } |
220 return false; | 221 return false; |
221 } | 222 } |
222 | 223 |
223 | 224 |
| 225 bool File::Copy(const char* old_path, const char* new_path) { |
| 226 File::Type type = File::GetType(old_path, true); |
| 227 if (type == kIsFile) { |
| 228 return copyfile(old_path, new_path, NULL, COPYFILE_ALL) == 0; |
| 229 } else if (type == kIsDirectory) { |
| 230 errno = EISDIR; |
| 231 } else { |
| 232 errno = ENOENT; |
| 233 } |
| 234 return false; |
| 235 } |
| 236 |
| 237 |
224 off64_t File::LengthFromPath(const char* name) { | 238 off64_t File::LengthFromPath(const char* name) { |
225 struct stat st; | 239 struct stat st; |
226 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 240 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
227 return st.st_size; | 241 return st.st_size; |
228 } | 242 } |
229 return -1; | 243 return -1; |
230 } | 244 } |
231 | 245 |
232 | 246 |
233 void File::Stat(const char* name, int64_t* data) { | 247 void File::Stat(const char* name, int64_t* data) { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 return (file_1_info.st_ino == file_2_info.st_ino && | 372 return (file_1_info.st_ino == file_2_info.st_ino && |
359 file_1_info.st_dev == file_2_info.st_dev) ? | 373 file_1_info.st_dev == file_2_info.st_dev) ? |
360 File::kIdentical : | 374 File::kIdentical : |
361 File::kDifferent; | 375 File::kDifferent; |
362 } | 376 } |
363 | 377 |
364 } // namespace bin | 378 } // namespace bin |
365 } // namespace dart | 379 } // namespace dart |
366 | 380 |
367 #endif // defined(TARGET_OS_MACOS) | 381 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |