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 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 bool File::CreateLink(const char* name, const char* target) { | 165 bool File::CreateLink(const char* name, const char* target) { |
166 int status = TEMP_FAILURE_RETRY(symlink(target, name)); | 166 int status = TEMP_FAILURE_RETRY(symlink(target, name)); |
167 return (status == 0); | 167 return (status == 0); |
168 } | 168 } |
169 | 169 |
170 | 170 |
171 bool File::Delete(const char* name) { | 171 bool File::Delete(const char* name) { |
172 int status = TEMP_FAILURE_RETRY(remove(name)); | 172 File::Type type = File::GetType(name, true); |
173 if (status == -1) { | 173 if (type == kIsFile) { |
174 return false; | 174 return TEMP_FAILURE_RETRY(unlink(name)) == 0; |
| 175 } else if (type == kIsDirectory) { |
| 176 errno = EISDIR; |
| 177 } else { |
| 178 errno = ENOENT; |
175 } | 179 } |
176 return true; | 180 return false; |
177 } | 181 } |
178 | 182 |
179 | 183 |
| 184 bool File::DeleteLink(const char* name) { |
| 185 File::Type type = File::GetType(name, false); |
| 186 if (type == kIsLink) { |
| 187 return TEMP_FAILURE_RETRY(unlink(name)) == 0; |
| 188 } |
| 189 errno = EINVAL; |
| 190 return false; |
| 191 } |
| 192 |
| 193 |
180 off_t File::LengthFromPath(const char* name) { | 194 off_t File::LengthFromPath(const char* name) { |
181 struct stat st; | 195 struct stat st; |
182 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 196 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
183 return st.st_size; | 197 return st.st_size; |
184 } | 198 } |
185 return -1; | 199 return -1; |
186 } | 200 } |
187 | 201 |
188 | 202 |
189 time_t File::LastModified(const char* name) { | 203 time_t File::LastModified(const char* name) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 TEMP_FAILURE_RETRY(lstat(file_2, &file_2_info)) == -1) { | 318 TEMP_FAILURE_RETRY(lstat(file_2, &file_2_info)) == -1) { |
305 return File::kError; | 319 return File::kError; |
306 } | 320 } |
307 return (file_1_info.st_ino == file_2_info.st_ino && | 321 return (file_1_info.st_ino == file_2_info.st_ino && |
308 file_1_info.st_dev == file_2_info.st_dev) ? | 322 file_1_info.st_dev == file_2_info.st_dev) ? |
309 File::kIdentical : | 323 File::kIdentical : |
310 File::kDifferent; | 324 File::kDifferent; |
311 } | 325 } |
312 | 326 |
313 #endif // defined(TARGET_OS_MACOS) | 327 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |