| 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 /** | 5 /** |
| 6 * Helper functionality to make working with IO easier. | 6 * Helper functionality to make working with IO easier. |
| 7 */ | 7 */ |
| 8 #library('io'); | 8 #library('io'); |
| 9 | 9 |
| 10 #import('dart:io'); | 10 #import('dart:io'); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 } | 248 } |
| 249 }); | 249 }); |
| 250 } | 250 } |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * Creates a new symlink that creates an alias from [from] to [to], both of | 253 * Creates a new symlink that creates an alias from [from] to [to], both of |
| 254 * which can be a [String], [File], or [Directory]. Returns a [Future] which | 254 * which can be a [String], [File], or [Directory]. Returns a [Future] which |
| 255 * completes to the symlink file (i.e. [to]). | 255 * completes to the symlink file (i.e. [to]). |
| 256 */ | 256 */ |
| 257 Future<File> createSymlink(from, to) { | 257 Future<File> createSymlink(from, to) { |
| 258 // TODO(rnystrom): What should this do on Windows? | |
| 259 from = _getPath(from); | 258 from = _getPath(from); |
| 260 to = _getPath(to); | 259 to = _getPath(to); |
| 261 | 260 |
| 262 return runProcess('ln', ['-s', from, to]).transform((result) { | 261 var command = 'ln'; |
| 262 var args = ['-s', from, to]; |
| 263 |
| 264 if (Platform.operatingSystem == 'windows') { |
| 265 // Call mklink on Windows to create an NTFS junction point. Only works on |
| 266 // Vista or later. (Junction points are available earlier, but the "mklink" |
| 267 // command is not.) I'm using a junction point (/j) here instead of a soft |
| 268 // link (/d) because the latter requires some privilege shenanigans that |
| 269 // I'm not sure how to specify from the command line. |
| 270 command = 'cmd'; |
| 271 args = ['/c', 'mklink', '/j', to, from]; |
| 272 } |
| 273 |
| 274 return runProcess(command, args).transform((result) { |
| 263 // TODO(rnystrom): Check exit code and output? | 275 // TODO(rnystrom): Check exit code and output? |
| 264 return new File(to); | 276 return new File(to); |
| 265 }); | 277 }); |
| 266 } | 278 } |
| 267 | 279 |
| 268 /** | 280 /** |
| 269 * Given [entry] which may be a [String], [File], or [Directory] relative to | 281 * Given [entry] which may be a [String], [File], or [Directory] relative to |
| 270 * the current working directory, returns its full canonicalized path. | 282 * the current working directory, returns its full canonicalized path. |
| 271 */ | 283 */ |
| 272 // TODO(rnystrom): Should this be async? | 284 // TODO(rnystrom): Should this be async? |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 return new Directory(entry); | 483 return new Directory(entry); |
| 472 } | 484 } |
| 473 | 485 |
| 474 /** | 486 /** |
| 475 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 487 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 476 */ | 488 */ |
| 477 Uri _getUri(uri) { | 489 Uri _getUri(uri) { |
| 478 if (uri is Uri) return uri; | 490 if (uri is Uri) return uri; |
| 479 return new Uri.fromString(uri); | 491 return new Uri.fromString(uri); |
| 480 } | 492 } |
| OLD | NEW |