| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * [Link] objects are references to filesystem links. | 8 * [Link] objects are references to filesystem links. |
| 9 * | 9 * |
| 10 */ | 10 */ |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 * On the Windows platform, this will only work with directories, and the | 61 * On the Windows platform, this will only work with directories, and the |
| 62 * target directory must exist. | 62 * target directory must exist. |
| 63 */ | 63 */ |
| 64 void updateSync(String target, {bool linkRelative: false }); | 64 void updateSync(String target, {bool linkRelative: false }); |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * Deletes the link. Returns a [:Future<Link>:] that completes with | 67 * Deletes the link. Returns a [:Future<Link>:] that completes with |
| 68 * the link when it has been deleted. This does not delete, or otherwise | 68 * the link when it has been deleted. This does not delete, or otherwise |
| 69 * affect, the target of the link. It also works on broken links, but if | 69 * affect, the target of the link. It also works on broken links, but if |
| 70 * the link does not exist or is not actually a link, it completes the | 70 * the link does not exist or is not actually a link, it completes the |
| 71 * future with a LinkIOException. | 71 * future with a LinkException. |
| 72 */ | 72 */ |
| 73 Future<Link> delete(); | 73 Future<Link> delete(); |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Synchronously deletes the link. This does not delete, or otherwise | 76 * Synchronously deletes the link. This does not delete, or otherwise |
| 77 * affect, the target of the link. It also works on broken links, but if | 77 * affect, the target of the link. It also works on broken links, but if |
| 78 * the link does not exist or is not actually a link, it throws a | 78 * the link does not exist or is not actually a link, it throws a |
| 79 * LinkIOException. | 79 * LinkException. |
| 80 */ | 80 */ |
| 81 void deleteSync(); | 81 void deleteSync(); |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * Gets the target of the link. Returns a future that completes with | 84 * Gets the target of the link. Returns a future that completes with |
| 85 * the path to the target. | 85 * the path to the target. |
| 86 * | 86 * |
| 87 * If the returned target is a relative path, it is relative to the | 87 * If the returned target is a relative path, it is relative to the |
| 88 * directory containing the link. | 88 * directory containing the link. |
| 89 * | 89 * |
| 90 * If the link does not exist, or is not a link, the future completes with | 90 * If the link does not exist, or is not a link, the future completes with |
| 91 * a LinkIOException. | 91 * a LinkException. |
| 92 */ | 92 */ |
| 93 Future<String> target(); | 93 Future<String> target(); |
| 94 | 94 |
| 95 /** | 95 /** |
| 96 * Synchronously gets the target of the link. Returns the path to the target. | 96 * Synchronously gets the target of the link. Returns the path to the target. |
| 97 * | 97 * |
| 98 * If the returned target is a relative path, it is relative to the | 98 * If the returned target is a relative path, it is relative to the |
| 99 * directory containing the link. | 99 * directory containing the link. |
| 100 * | 100 * |
| 101 * If the link does not exist, or is not a link, throws a LinkIOException. | 101 * If the link does not exist, or is not a link, throws a LinkException. |
| 102 */ | 102 */ |
| 103 String targetSync(); | 103 String targetSync(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 class _Link extends FileSystemEntity implements Link { | 107 class _Link extends FileSystemEntity implements Link { |
| 108 final String path; | 108 final String path; |
| 109 | 109 |
| 110 SendPort _fileService; | 110 SendPort _fileService; |
| 111 | 111 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 206 } |
| 207 | 207 |
| 208 String targetSync() { | 208 String targetSync() { |
| 209 var result = _File._linkTarget(path); | 209 var result = _File._linkTarget(path); |
| 210 throwIfError(result, "Cannot read link '$path'"); | 210 throwIfError(result, "Cannot read link '$path'"); |
| 211 return result; | 211 return result; |
| 212 } | 212 } |
| 213 | 213 |
| 214 static throwIfError(Object result, String msg) { | 214 static throwIfError(Object result, String msg) { |
| 215 if (result is OSError) { | 215 if (result is OSError) { |
| 216 throw new LinkIOException(msg, result); | 216 throw new LinkException(msg, result); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 bool _isErrorResponse(response) { | 220 bool _isErrorResponse(response) { |
| 221 return response is List && response[0] != _SUCCESS_RESPONSE; | 221 return response is List && response[0] != _SUCCESS_RESPONSE; |
| 222 } | 222 } |
| 223 | 223 |
| 224 void _ensureFileService() { | 224 void _ensureFileService() { |
| 225 if (_fileService == null) { | 225 if (_fileService == null) { |
| 226 _fileService = _FileUtils._newServicePort(); | 226 _fileService = _FileUtils._newServicePort(); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 _exceptionFromResponse(response, String message) { | 230 _exceptionFromResponse(response, String message) { |
| 231 assert(_isErrorResponse(response)); | 231 assert(_isErrorResponse(response)); |
| 232 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { | 232 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { |
| 233 case _ILLEGAL_ARGUMENT_RESPONSE: | 233 case _ILLEGAL_ARGUMENT_RESPONSE: |
| 234 return new ArgumentError(); | 234 return new ArgumentError(); |
| 235 case _OSERROR_RESPONSE: | 235 case _OSERROR_RESPONSE: |
| 236 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], | 236 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], |
| 237 response[_OSERROR_RESPONSE_ERROR_CODE]); | 237 response[_OSERROR_RESPONSE_ERROR_CODE]); |
| 238 return new LinkIOException(message, err); | 238 return new LinkException(message, err); |
| 239 default: | 239 default: |
| 240 return new Exception("Unknown error"); | 240 return new Exception("Unknown error"); |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 | 244 |
| 245 | 245 |
| 246 class LinkIOException implements Exception { | 246 class LinkException implements IOException { |
| 247 const LinkIOException([String this.message = "", | 247 const LinkException([String this.message = "", |
| 248 String this.path = "", | 248 String this.path = "", |
| 249 OSError this.osError = null]); | 249 OSError this.osError = null]); |
| 250 String toString() { | 250 String toString() { |
| 251 StringBuffer sb = new StringBuffer(); | 251 StringBuffer sb = new StringBuffer(); |
| 252 sb.write("LinkIOException"); | 252 sb.write("LinkException"); |
| 253 if (!message.isEmpty) { | 253 if (!message.isEmpty) { |
| 254 sb.write(": $message"); | 254 sb.write(": $message"); |
| 255 if (path != null) { | 255 if (path != null) { |
| 256 sb.write(", path = $path"); | 256 sb.write(", path = $path"); |
| 257 } | 257 } |
| 258 if (osError != null) { | 258 if (osError != null) { |
| 259 sb.write(" ($osError)"); | 259 sb.write(" ($osError)"); |
| 260 } | 260 } |
| 261 } else if (osError != null) { | 261 } else if (osError != null) { |
| 262 sb.write(": $osError"); | 262 sb.write(": $osError"); |
| 263 if (path != null) { | 263 if (path != null) { |
| 264 sb.write(", path = $path"); | 264 sb.write(", path = $path"); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 return sb.toString(); | 267 return sb.toString(); |
| 268 } | 268 } |
| 269 final String message; | 269 final String message; |
| 270 final String path; | 270 final String path; |
| 271 final OSError osError; | 271 final OSError osError; |
| 272 } | 272 } |
| OLD | NEW |