| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 FileStat statSync() => FileStat.statSync(path); | 167 FileStat statSync() => FileStat.statSync(path); |
| 168 | 168 |
| 169 Future<Link> create(String target, {bool recursive: false}) { | 169 Future<Link> create(String target, {bool recursive: false}) { |
| 170 if (Platform.isWindows) { | 170 if (Platform.isWindows) { |
| 171 target = _makeWindowsLinkTarget(target); | 171 target = _makeWindowsLinkTarget(target); |
| 172 } | 172 } |
| 173 var result = recursive ? parent.create(recursive: true) | 173 var result = recursive ? parent.create(recursive: true) |
| 174 : new Future.value(null); | 174 : new Future.value(null); |
| 175 return result | 175 return result |
| 176 .then((_) => _IOService.dispatch(_FILE_CREATE_LINK, [path, target])) | 176 .then((_) => _IOService._dispatch(_FILE_CREATE_LINK, [path, target])) |
| 177 .then((response) { | 177 .then((response) { |
| 178 if (_isErrorResponse(response)) { | 178 if (_isErrorResponse(response)) { |
| 179 throw _exceptionFromResponse( | 179 throw _exceptionFromResponse( |
| 180 response, "Cannot create link to target '$target'", path); | 180 response, "Cannot create link to target '$target'", path); |
| 181 } | 181 } |
| 182 return this; | 182 return this; |
| 183 }); | 183 }); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void createSync(String target, {bool recursive: false}) { | 186 void createSync(String target, {bool recursive: false}) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // Atomically changing a link can be done by creating the new link, with | 223 // Atomically changing a link can be done by creating the new link, with |
| 224 // a different name, and using the rename() posix call to move it to | 224 // a different name, and using the rename() posix call to move it to |
| 225 // the old name atomically. | 225 // the old name atomically. |
| 226 return delete().then((_) => create(target)); | 226 return delete().then((_) => create(target)); |
| 227 } | 227 } |
| 228 | 228 |
| 229 Future<Link> _delete({bool recursive: false}) { | 229 Future<Link> _delete({bool recursive: false}) { |
| 230 if (recursive) { | 230 if (recursive) { |
| 231 return new Directory(path).delete(recursive: true).then((_) => this); | 231 return new Directory(path).delete(recursive: true).then((_) => this); |
| 232 } | 232 } |
| 233 return _IOService.dispatch(_FILE_DELETE_LINK, [path]).then((response) { | 233 return _IOService._dispatch(_FILE_DELETE_LINK, [path]).then((response) { |
| 234 if (_isErrorResponse(response)) { | 234 if (_isErrorResponse(response)) { |
| 235 throw _exceptionFromResponse(response, "Cannot delete link", path); | 235 throw _exceptionFromResponse(response, "Cannot delete link", path); |
| 236 } | 236 } |
| 237 return this; | 237 return this; |
| 238 }); | 238 }); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void _deleteSync({bool recursive: false}) { | 241 void _deleteSync({bool recursive: false}) { |
| 242 if (recursive) { | 242 if (recursive) { |
| 243 return new Directory(path).deleteSync(recursive: true); | 243 return new Directory(path).deleteSync(recursive: true); |
| 244 } | 244 } |
| 245 var result = _File._deleteLinkNative(path); | 245 var result = _File._deleteLinkNative(path); |
| 246 throwIfError(result, "Cannot delete link", path); | 246 throwIfError(result, "Cannot delete link", path); |
| 247 } | 247 } |
| 248 | 248 |
| 249 Future<Link> rename(String newPath) { | 249 Future<Link> rename(String newPath) { |
| 250 return _IOService.dispatch(_FILE_RENAME_LINK, [path, newPath]) | 250 return _IOService._dispatch(_FILE_RENAME_LINK, [path, newPath]) |
| 251 .then((response) { | 251 .then((response) { |
| 252 if (_isErrorResponse(response)) { | 252 if (_isErrorResponse(response)) { |
| 253 throw _exceptionFromResponse( | 253 throw _exceptionFromResponse( |
| 254 response, "Cannot rename link to '$newPath'", path); | 254 response, "Cannot rename link to '$newPath'", path); |
| 255 } | 255 } |
| 256 return new Link(newPath); | 256 return new Link(newPath); |
| 257 }); | 257 }); |
| 258 } | 258 } |
| 259 | 259 |
| 260 Link renameSync(String newPath) { | 260 Link renameSync(String newPath) { |
| 261 var result = _File._renameLink(path, newPath); | 261 var result = _File._renameLink(path, newPath); |
| 262 throwIfError(result, "Cannot rename link '$path' to '$newPath'"); | 262 throwIfError(result, "Cannot rename link '$path' to '$newPath'"); |
| 263 return new Link(newPath); | 263 return new Link(newPath); |
| 264 } | 264 } |
| 265 | 265 |
| 266 Future<String> target() { | 266 Future<String> target() { |
| 267 return _IOService.dispatch(_FILE_LINK_TARGET, [path]).then((response) { | 267 return _IOService._dispatch(_FILE_LINK_TARGET, [path]).then((response) { |
| 268 if (_isErrorResponse(response)) { | 268 if (_isErrorResponse(response)) { |
| 269 throw _exceptionFromResponse( | 269 throw _exceptionFromResponse( |
| 270 response, "Cannot get target of link", path); | 270 response, "Cannot get target of link", path); |
| 271 } | 271 } |
| 272 return response; | 272 return response; |
| 273 }); | 273 }); |
| 274 } | 274 } |
| 275 | 275 |
| 276 String targetSync() { | 276 String targetSync() { |
| 277 var result = _File._linkTarget(path); | 277 var result = _File._linkTarget(path); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 296 return new ArgumentError(); | 296 return new ArgumentError(); |
| 297 case _OSERROR_RESPONSE: | 297 case _OSERROR_RESPONSE: |
| 298 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], | 298 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], |
| 299 response[_OSERROR_RESPONSE_ERROR_CODE]); | 299 response[_OSERROR_RESPONSE_ERROR_CODE]); |
| 300 return new FileSystemException(message, path, err); | 300 return new FileSystemException(message, path, err); |
| 301 default: | 301 default: |
| 302 return new Exception("Unknown error"); | 302 return new Exception("Unknown error"); |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 } | 305 } |
| OLD | NEW |