| 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 160 } |
| 161 | 161 |
| 162 | 162 |
| 163 bool File::CreateLink(const char* name, const char* target) { | 163 bool File::CreateLink(const char* name, const char* target) { |
| 164 int status = TEMP_FAILURE_RETRY(symlink(target, name)); | 164 int status = TEMP_FAILURE_RETRY(symlink(target, name)); |
| 165 return (status == 0); | 165 return (status == 0); |
| 166 } | 166 } |
| 167 | 167 |
| 168 | 168 |
| 169 bool File::Delete(const char* name) { | 169 bool File::Delete(const char* name) { |
| 170 int status = TEMP_FAILURE_RETRY(remove(name)); | 170 File::Type type = File::GetType(name, true); |
| 171 if (status == -1) { | 171 if (type == kIsFile) { |
| 172 return false; | 172 return TEMP_FAILURE_RETRY(unlink(name)) == 0; |
| 173 } else if (type == kIsDirectory) { |
| 174 errno = EISDIR; |
| 175 } else { |
| 176 errno = ENOENT; |
| 173 } | 177 } |
| 174 return true; | 178 return false; |
| 175 } | 179 } |
| 176 | 180 |
| 177 | 181 |
| 182 bool File::DeleteLink(const char* name) { |
| 183 File::Type type = File::GetType(name, false); |
| 184 if (type == kIsLink) { |
| 185 return TEMP_FAILURE_RETRY(unlink(name)) == 0; |
| 186 } |
| 187 errno = EINVAL; |
| 188 return false; |
| 189 } |
| 190 |
| 191 |
| 178 off_t File::LengthFromPath(const char* name) { | 192 off_t File::LengthFromPath(const char* name) { |
| 179 struct stat st; | 193 struct stat st; |
| 180 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 194 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
| 181 return st.st_size; | 195 return st.st_size; |
| 182 } | 196 } |
| 183 return -1; | 197 return -1; |
| 184 } | 198 } |
| 185 | 199 |
| 186 | 200 |
| 187 time_t File::LastModified(const char* name) { | 201 time_t File::LastModified(const char* name) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 TEMP_FAILURE_RETRY(lstat(file_2, &file_2_info)) == -1) { | 310 TEMP_FAILURE_RETRY(lstat(file_2, &file_2_info)) == -1) { |
| 297 return File::kError; | 311 return File::kError; |
| 298 } | 312 } |
| 299 return (file_1_info.st_ino == file_2_info.st_ino && | 313 return (file_1_info.st_ino == file_2_info.st_ino && |
| 300 file_1_info.st_dev == file_2_info.st_dev) ? | 314 file_1_info.st_dev == file_2_info.st_dev) ? |
| 301 File::kIdentical : | 315 File::kIdentical : |
| 302 File::kDifferent; | 316 File::kDifferent; |
| 303 } | 317 } |
| 304 | 318 |
| 305 #endif // defined(TARGET_OS_LINUX) | 319 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |