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 library path_source; | 5 library path_source; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import '../../pkg/pathos/lib/path.dart' as path; | 10 import '../../pkg/pathos/lib/path.dart' as path; |
11 | 11 |
| 12 import 'log.dart' as log; |
| 13 |
12 import 'io.dart'; | 14 import 'io.dart'; |
13 import 'package.dart'; | 15 import 'package.dart'; |
14 import 'pubspec.dart'; | 16 import 'pubspec.dart'; |
15 import 'version.dart'; | 17 import 'version.dart'; |
16 import 'source.dart'; | 18 import 'source.dart'; |
17 import 'utils.dart'; | 19 import 'utils.dart'; |
18 | 20 |
19 // TODO(rnystrom): Support relative paths. (See comment in _validatePath().) | 21 // TODO(rnystrom): Support relative paths. (See comment in _validatePath().) |
20 /// A package [Source] that installs packages from a given local file path. | 22 /// A package [Source] that installs packages from a given local file path. |
21 class PathSource extends Source { | 23 class PathSource extends Source { |
22 final name = 'path'; | 24 final name = 'path'; |
23 final shouldCache = false; | 25 final shouldCache = false; |
24 | 26 |
25 Future<Pubspec> describe(PackageId id) { | 27 Future<Pubspec> describe(PackageId id) { |
26 return defer(() { | 28 return defer(() { |
27 _validatePath(id.name, id.description); | 29 _validatePath(id.name, id.description); |
28 return new Pubspec.load(id.name, id.description["path"], | 30 return new Pubspec.load(id.name, id.description["path"], |
29 systemCache.sources); | 31 systemCache.sources); |
30 }); | 32 }); |
31 } | 33 } |
32 | 34 |
| 35 bool descriptionsEqual(description1, description2) { |
| 36 // Compare real paths after normalizing and resolving symlinks. |
| 37 var path1 = new File(description1["path"]).fullPathSync(); |
| 38 var path2 = new File(description2["path"]).fullPathSync(); |
| 39 return path1 == path2; |
| 40 } |
| 41 |
33 Future<bool> install(PackageId id, String destination) { | 42 Future<bool> install(PackageId id, String destination) { |
34 return defer(() { | 43 return defer(() { |
35 try { | 44 try { |
36 _validatePath(id.name, id.description); | 45 _validatePath(id.name, id.description); |
37 } on FormatException catch(err) { | 46 } on FormatException catch(err) { |
38 return false; | 47 return false; |
39 } | 48 } |
40 | 49 |
41 return createPackageSymlink(id.name, id.description["path"], destination, | 50 return createPackageSymlink(id.name, id.description["path"], destination, |
42 relative: id.description["relative"]); | 51 relative: id.description["relative"]); |
43 }).then((_) => true); | 52 }).then((_) => true); |
44 } | 53 } |
45 | 54 |
46 /// Parses a path dependency. This takes in a path string and returns a map. | 55 /// Parses a path dependency. This takes in a path string and returns a map. |
47 /// The "path" key will be the original path but resolves relative to the | 56 /// The "path" key will be the original path but resolved relative to the |
48 /// containing path. The "relative" key will be `true` if the original path | 57 /// containing path. The "relative" key will be `true` if the original path |
49 /// was relative. | 58 /// was relative. |
50 /// | 59 /// |
51 /// A path coming from a pubspec is a simple string. From a lock file, it's | 60 /// A path coming from a pubspec is a simple string. From a lock file, it's |
52 /// an expanded {"path": ..., "relative": ...} map. | 61 /// an expanded {"path": ..., "relative": ...} map. |
53 dynamic parseDescription(String containingPath, description, | 62 dynamic parseDescription(String containingPath, description, |
54 {bool fromLockFile: false}) { | 63 {bool fromLockFile: false}) { |
55 if (fromLockFile) { | 64 if (fromLockFile) { |
56 if (description is! Map) { | 65 if (description is! Map) { |
57 throw new FormatException("The description must be a map."); | 66 throw new FormatException("The description must be a map."); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 throw new FormatException( | 110 throw new FormatException( |
102 "Path dependency for package '$name' must refer to a " | 111 "Path dependency for package '$name' must refer to a " |
103 "directory, not a file. Was '$dir'."); | 112 "directory, not a file. Was '$dir'."); |
104 } | 113 } |
105 | 114 |
106 if (!dirExists(dir)) { | 115 if (!dirExists(dir)) { |
107 throw new FormatException("Could not find package '$name' at '$dir'."); | 116 throw new FormatException("Could not find package '$name' at '$dir'."); |
108 } | 117 } |
109 } | 118 } |
110 } | 119 } |
OLD | NEW |