| 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 <copyfile.h> // NOLINT | 10 #include <copyfile.h> // NOLINT |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 | 224 |
| 225 File* File::OpenStdio(int fd) { | 225 File* File::OpenStdio(int fd) { |
| 226 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); | 226 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); |
| 227 } | 227 } |
| 228 | 228 |
| 229 | 229 |
| 230 bool File::Exists(const char* name) { | 230 bool File::Exists(const char* name) { |
| 231 struct stat st; | 231 struct stat st; |
| 232 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { | 232 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
| 233 // Everything but a directory and a link is a file to Dart. | 233 return S_ISREG(st.st_mode); |
| 234 return !S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode); | |
| 235 } else { | 234 } else { |
| 236 return false; | 235 return false; |
| 237 } | 236 } |
| 238 } | 237 } |
| 239 | 238 |
| 240 | 239 |
| 241 bool File::Create(const char* name) { | 240 bool File::Create(const char* name) { |
| 242 int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CREAT, 0666)); | 241 int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CREAT, 0666)); |
| 243 if (fd < 0) { | 242 if (fd < 0) { |
| 244 return false; | 243 return false; |
| 245 } | 244 } |
| 246 // File.create returns a File, so we shouldn't be giving the illusion that the | 245 return (close(fd) == 0); |
| 247 // call has created a file or that a file already exists if there is already | |
| 248 // an entity at the same path that is a directory or a link. | |
| 249 bool is_file = true; | |
| 250 struct stat st; | |
| 251 if (NO_RETRY_EXPECTED(fstat(fd, &st)) == 0) { | |
| 252 if (S_ISDIR(st.st_mode)) { | |
| 253 errno = EISDIR; | |
| 254 is_file = false; | |
| 255 } else if (S_ISLNK(st.st_mode)) { | |
| 256 errno = ENOENT; | |
| 257 is_file = false; | |
| 258 } | |
| 259 } | |
| 260 FDUtils::SaveErrorAndClose(fd); | |
| 261 return is_file; | |
| 262 } | 246 } |
| 263 | 247 |
| 264 | 248 |
| 265 bool File::CreateLink(const char* name, const char* target) { | 249 bool File::CreateLink(const char* name, const char* target) { |
| 266 int status = NO_RETRY_EXPECTED(symlink(target, name)); | 250 int status = NO_RETRY_EXPECTED(symlink(target, name)); |
| 267 return (status == 0); | 251 return (status == 0); |
| 268 } | 252 } |
| 269 | 253 |
| 270 | 254 |
| 271 bool File::Delete(const char* name) { | 255 bool File::Delete(const char* name) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 return ((file_1_info.st_ino == file_2_info.st_ino) && | 483 return ((file_1_info.st_ino == file_2_info.st_ino) && |
| 500 (file_1_info.st_dev == file_2_info.st_dev)) | 484 (file_1_info.st_dev == file_2_info.st_dev)) |
| 501 ? File::kIdentical | 485 ? File::kIdentical |
| 502 : File::kDifferent; | 486 : File::kDifferent; |
| 503 } | 487 } |
| 504 | 488 |
| 505 } // namespace bin | 489 } // namespace bin |
| 506 } // namespace dart | 490 } // namespace dart |
| 507 | 491 |
| 508 #endif // defined(TARGET_OS_MACOS) | 492 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |