| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 _ensureFileService(); | 147 _ensureFileService(); |
| 148 if (Platform.operatingSystem == 'windows') { | 148 if (Platform.operatingSystem == 'windows') { |
| 149 target = _makeWindowsLinkTarget(target); | 149 target = _makeWindowsLinkTarget(target); |
| 150 } | 150 } |
| 151 List request = new List(3); | 151 List request = new List(3); |
| 152 request[0] = _CREATE_LINK_REQUEST; | 152 request[0] = _CREATE_LINK_REQUEST; |
| 153 request[1] = path; | 153 request[1] = path; |
| 154 request[2] = target; | 154 request[2] = target; |
| 155 return _fileService.call(request).then((response) { | 155 return _fileService.call(request).then((response) { |
| 156 if (_isErrorResponse(response)) { | 156 if (_isErrorResponse(response)) { |
| 157 throw _exceptionFromResponse(response, | 157 throw _exceptionFromResponse( |
| 158 "Cannot create link '$path' to target '$target'"); | 158 response, "Cannot create link to target '$target'", path); |
| 159 } | 159 } |
| 160 return this; | 160 return this; |
| 161 }); | 161 }); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void createSync(String target) { | 164 void createSync(String target) { |
| 165 if (Platform.operatingSystem == 'windows') { | 165 if (Platform.operatingSystem == 'windows') { |
| 166 target = _makeWindowsLinkTarget(target); | 166 target = _makeWindowsLinkTarget(target); |
| 167 } | 167 } |
| 168 var result = _File._createLink(path, target); | 168 var result = _File._createLink(path, target); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 197 createSync(target); | 197 createSync(target); |
| 198 } | 198 } |
| 199 | 199 |
| 200 Future<Link> delete() { | 200 Future<Link> delete() { |
| 201 _ensureFileService(); | 201 _ensureFileService(); |
| 202 List request = new List(2); | 202 List request = new List(2); |
| 203 request[0] = _DELETE_LINK_REQUEST; | 203 request[0] = _DELETE_LINK_REQUEST; |
| 204 request[1] = path; | 204 request[1] = path; |
| 205 return _fileService.call(request).then((response) { | 205 return _fileService.call(request).then((response) { |
| 206 if (_isErrorResponse(response)) { | 206 if (_isErrorResponse(response)) { |
| 207 throw _exceptionFromResponse(response, "Cannot delete link '$path'"); | 207 throw _exceptionFromResponse(response, "Cannot delete link", path); |
| 208 } | 208 } |
| 209 return this; | 209 return this; |
| 210 }); | 210 }); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void deleteSync() { | 213 void deleteSync() { |
| 214 var result = _File._deleteLink(path); | 214 var result = _File._deleteLink(path); |
| 215 throwIfError(result, "Cannot delete link", path); | 215 throwIfError(result, "Cannot delete link", path); |
| 216 } | 216 } |
| 217 | 217 |
| 218 Future<Link> rename(String newPath) { | 218 Future<Link> rename(String newPath) { |
| 219 _ensureFileService(); | 219 _ensureFileService(); |
| 220 List request = new List(3); | 220 List request = new List(3); |
| 221 request[0] = _RENAME_LINK_REQUEST; | 221 request[0] = _RENAME_LINK_REQUEST; |
| 222 request[1] = path; | 222 request[1] = path; |
| 223 request[2] = newPath; | 223 request[2] = newPath; |
| 224 return _fileService.call(request).then((response) { | 224 return _fileService.call(request).then((response) { |
| 225 if (_isErrorResponse(response)) { | 225 if (_isErrorResponse(response)) { |
| 226 throw _exceptionFromResponse( | 226 throw _exceptionFromResponse( |
| 227 response, "Cannot rename link '$path' to '$newPath'"); | 227 response, "Cannot rename link to '$newPath'", path); |
| 228 } | 228 } |
| 229 return new Link(newPath); | 229 return new Link(newPath); |
| 230 }); | 230 }); |
| 231 } | 231 } |
| 232 | 232 |
| 233 Link renameSync(String newPath) { | 233 Link renameSync(String newPath) { |
| 234 var result = _File._renameLink(path, newPath); | 234 var result = _File._renameLink(path, newPath); |
| 235 throwIfError(result, "Cannot rename link '$path' to '$newPath'"); | 235 throwIfError(result, "Cannot rename link '$path' to '$newPath'"); |
| 236 return new Link(newPath); | 236 return new Link(newPath); |
| 237 } | 237 } |
| 238 | 238 |
| 239 Future<String> target() { | 239 Future<String> target() { |
| 240 _ensureFileService(); | 240 _ensureFileService(); |
| 241 List request = new List(2); | 241 List request = new List(2); |
| 242 request[0] = _LINK_TARGET_REQUEST; | 242 request[0] = _LINK_TARGET_REQUEST; |
| 243 request[1] = path; | 243 request[1] = path; |
| 244 return _fileService.call(request).then((response) { | 244 return _fileService.call(request).then((response) { |
| 245 if (_isErrorResponse(response)) { | 245 if (_isErrorResponse(response)) { |
| 246 throw _exceptionFromResponse(response, | 246 throw _exceptionFromResponse( |
| 247 "Cannot get target of link '$path'"); | 247 response, "Cannot get target of link", path); |
| 248 } | 248 } |
| 249 return response; | 249 return response; |
| 250 }); | 250 }); |
| 251 } | 251 } |
| 252 | 252 |
| 253 String targetSync() { | 253 String targetSync() { |
| 254 var result = _File._linkTarget(path); | 254 var result = _File._linkTarget(path); |
| 255 throwIfError(result, "Cannot read link", path); | 255 throwIfError(result, "Cannot read link", path); |
| 256 return result; | 256 return result; |
| 257 } | 257 } |
| 258 | 258 |
| 259 static throwIfError(Object result, String msg, [String path = ""]) { | 259 static throwIfError(Object result, String msg, [String path = ""]) { |
| 260 if (result is OSError) { | 260 if (result is OSError) { |
| 261 throw new LinkException(msg, path, result); | 261 throw new LinkException(msg, path, result); |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 | 264 |
| 265 bool _isErrorResponse(response) { | 265 bool _isErrorResponse(response) { |
| 266 return response is List && response[0] != _SUCCESS_RESPONSE; | 266 return response is List && response[0] != _SUCCESS_RESPONSE; |
| 267 } | 267 } |
| 268 | 268 |
| 269 void _ensureFileService() { | 269 void _ensureFileService() { |
| 270 if (_fileService == null) { | 270 if (_fileService == null) { |
| 271 _fileService = _FileUtils._newServicePort(); | 271 _fileService = _FileUtils._newServicePort(); |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 | 274 |
| 275 _exceptionFromResponse(response, String message) { | 275 _exceptionFromResponse(response, String message, String path) { |
| 276 assert(_isErrorResponse(response)); | 276 assert(_isErrorResponse(response)); |
| 277 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { | 277 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { |
| 278 case _ILLEGAL_ARGUMENT_RESPONSE: | 278 case _ILLEGAL_ARGUMENT_RESPONSE: |
| 279 return new ArgumentError(); | 279 return new ArgumentError(); |
| 280 case _OSERROR_RESPONSE: | 280 case _OSERROR_RESPONSE: |
| 281 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], | 281 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], |
| 282 response[_OSERROR_RESPONSE_ERROR_CODE]); | 282 response[_OSERROR_RESPONSE_ERROR_CODE]); |
| 283 return new LinkException(message, err); | 283 return new LinkException(message, path, err); |
| 284 default: | 284 default: |
| 285 return new Exception("Unknown error"); | 285 return new Exception("Unknown error"); |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 | 289 |
| 290 | 290 |
| 291 class LinkException implements IOException { | 291 class LinkException implements IOException { |
| 292 const LinkException([String this.message = "", | 292 const LinkException([String this.message = "", |
| 293 String this.path = "", | 293 String this.path = "", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 308 if (path != null) { | 308 if (path != null) { |
| 309 sb.write(", path = $path"); | 309 sb.write(", path = $path"); |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 return sb.toString(); | 312 return sb.toString(); |
| 313 } | 313 } |
| 314 final String message; | 314 final String message; |
| 315 final String path; | 315 final String path; |
| 316 final OSError osError; | 316 final OSError osError; |
| 317 } | 317 } |
| OLD | NEW |