| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_FUCHSIA) | 6 #if defined(TARGET_OS_FUCHSIA) |
| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return new File(new FileHandle(fd)); | 201 return new File(new FileHandle(fd)); |
| 202 } | 202 } |
| 203 | 203 |
| 204 | 204 |
| 205 File* File::OpenStdio(int fd) { | 205 File* File::OpenStdio(int fd) { |
| 206 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); | 206 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); |
| 207 } | 207 } |
| 208 | 208 |
| 209 | 209 |
| 210 bool File::Exists(const char* name) { | 210 bool File::Exists(const char* name) { |
| 211 struct stat64 st; | 211 struct stat st; |
| 212 if (NO_RETRY_EXPECTED(stat64(name, &st)) == 0) { | 212 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
| 213 // Everything but a directory and a link is a file to Dart. | 213 return S_ISREG(st.st_mode); |
| 214 return !S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode); | |
| 215 } else { | 214 } else { |
| 216 return false; | 215 return false; |
| 217 } | 216 } |
| 218 } | 217 } |
| 219 | 218 |
| 220 | 219 |
| 221 bool File::Create(const char* name) { | 220 bool File::Create(const char* name) { |
| 222 int fd = | 221 int fd = NO_RETRY_EXPECTED(open(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666)); |
| 223 NO_RETRY_EXPECTED(open64(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666)); | |
| 224 if (fd < 0) { | 222 if (fd < 0) { |
| 225 return false; | 223 return false; |
| 226 } | 224 } |
| 227 // File.create returns a File, so we shouldn't be giving the illusion that the | 225 return (close(fd) == 0); |
| 228 // call has created a file or that a file already exists if there is already | |
| 229 // an entity at the same path that is a directory or a link. | |
| 230 bool is_file = true; | |
| 231 struct stat64 st; | |
| 232 if (NO_RETRY_EXPECTED(fstat64(fd, &st)) == 0) { | |
| 233 if (S_ISDIR(st.st_mode)) { | |
| 234 errno = EISDIR; | |
| 235 is_file = false; | |
| 236 } else if (S_ISLNK(st.st_mode)) { | |
| 237 errno = ENOENT; | |
| 238 is_file = false; | |
| 239 } | |
| 240 } | |
| 241 FDUtils::SaveErrorAndClose(fd); | |
| 242 return is_file; | |
| 243 } | 226 } |
| 244 | 227 |
| 245 | 228 |
| 246 bool File::CreateLink(const char* name, const char* target) { | 229 bool File::CreateLink(const char* name, const char* target) { |
| 247 return NO_RETRY_EXPECTED(symlink(target, name)) == 0; | 230 return NO_RETRY_EXPECTED(symlink(target, name)) == 0; |
| 248 } | 231 } |
| 249 | 232 |
| 250 | 233 |
| 251 bool File::Delete(const char* name) { | 234 bool File::Delete(const char* name) { |
| 252 File::Type type = File::GetType(name, true); | 235 File::Type type = File::GetType(name, true); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 return ((file_1_info.st_ino == file_2_info.st_ino) && | 484 return ((file_1_info.st_ino == file_2_info.st_ino) && |
| 502 (file_1_info.st_dev == file_2_info.st_dev)) | 485 (file_1_info.st_dev == file_2_info.st_dev)) |
| 503 ? File::kIdentical | 486 ? File::kIdentical |
| 504 : File::kDifferent; | 487 : File::kDifferent; |
| 505 } | 488 } |
| 506 | 489 |
| 507 } // namespace bin | 490 } // namespace bin |
| 508 } // namespace dart | 491 } // namespace dart |
| 509 | 492 |
| 510 #endif // defined(TARGET_OS_FUCHSIA) | 493 #endif // defined(TARGET_OS_FUCHSIA) |
| OLD | NEW |