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 /// Helper functionality to make working with IO easier. | 5 /// Helper functionality to make working with IO easier. |
6 library pub.io; | 6 library pub.io; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:collection'; | 9 import 'dart:collection'; |
10 import 'dart:convert'; | 10 import 'dart:convert'; |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 void createSymlink(String target, String symlink, | 344 void createSymlink(String target, String symlink, |
345 {bool relative: false}) { | 345 {bool relative: false}) { |
346 if (relative) { | 346 if (relative) { |
347 // Relative junction points are not supported on Windows. Instead, just | 347 // Relative junction points are not supported on Windows. Instead, just |
348 // make sure we have a clean absolute path because it will interpret a | 348 // make sure we have a clean absolute path because it will interpret a |
349 // relative path to be relative to the cwd, not the symlink, and will be | 349 // relative path to be relative to the cwd, not the symlink, and will be |
350 // confused by forward slashes. | 350 // confused by forward slashes. |
351 if (Platform.operatingSystem == 'windows') { | 351 if (Platform.operatingSystem == 'windows') { |
352 target = path.normalize(path.absolute(target)); | 352 target = path.normalize(path.absolute(target)); |
353 } else { | 353 } else { |
354 target = path.normalize( | 354 // If the directory where we're creating the symlink was itself reached |
355 path.relative(target, from: path.dirname(symlink))); | 355 // by traversing a symlink, we want the relative path to be relative to |
| 356 // it's actual location, not the one we went through to get to it. |
| 357 var symlinkDir = canonicalize(path.dirname(symlink)); |
| 358 target = path.normalize(path.relative(target, from: symlinkDir)); |
356 } | 359 } |
357 } | 360 } |
358 | 361 |
359 log.fine("Creating $symlink pointing to $target"); | 362 log.fine("Creating $symlink pointing to $target"); |
360 new Link(symlink).createSync(target); | 363 new Link(symlink).createSync(target); |
361 } | 364 } |
362 | 365 |
363 /// Creates a new symlink that creates an alias at [symlink] that points to the | 366 /// Creates a new symlink that creates an alias at [symlink] that points to the |
364 /// `lib` directory of package [target]. If [target] does not have a `lib` | 367 /// `lib` directory of package [target]. If [target] does not have a `lib` |
365 /// directory, this shows a warning if appropriate and then does nothing. | 368 /// directory, this shows a warning if appropriate and then does nothing. |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 850 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
848 | 851 |
849 bool get success => exitCode == exit_codes.SUCCESS; | 852 bool get success => exitCode == exit_codes.SUCCESS; |
850 } | 853 } |
851 | 854 |
852 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 855 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
853 Uri _getUri(uri) { | 856 Uri _getUri(uri) { |
854 if (uri is Uri) return uri; | 857 if (uri is Uri) return uri; |
855 return Uri.parse(uri); | 858 return Uri.parse(uri); |
856 } | 859 } |
OLD | NEW |