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 // TODO(rnystrom): Traverse symlinks and compare real paths? | |
nweiz
2013/02/25 22:08:46
I'm leaning towards yes.
Bob Nystrom
2013/02/25 22:50:26
Done.
| |
37 var path1 = path.normalize(description1["path"]); | |
38 var path2 = path.normalize(description2["path"]); | |
39 return path1 == path2 && | |
40 description1["relative"] == description2["relative"]; | |
nweiz
2013/02/25 22:08:46
I don't think this is correct. If both paths resol
Bob Nystrom
2013/02/25 22:50:26
Done.
| |
41 } | |
42 | |
33 Future<bool> install(PackageId id, String destination) { | 43 Future<bool> install(PackageId id, String destination) { |
34 return defer(() { | 44 return defer(() { |
35 try { | 45 try { |
36 _validatePath(id.name, id.description); | 46 _validatePath(id.name, id.description); |
37 } on FormatException catch(err) { | 47 } on FormatException catch(err) { |
38 return false; | 48 return false; |
39 } | 49 } |
40 | 50 |
41 return createPackageSymlink(id.name, id.description["path"], destination, | 51 return createPackageSymlink(id.name, id.description["path"], destination, |
42 relative: id.description["relative"]); | 52 relative: id.description["relative"]); |
43 }).then((_) => true); | 53 }).then((_) => true); |
44 } | 54 } |
45 | 55 |
46 /// Parses a path dependency. This takes in a path string and returns a map. | 56 /// 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 | 57 /// 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 | 58 /// containing path. The "relative" key will be `true` if the original path |
49 /// was relative. | 59 /// was relative. |
50 /// | 60 /// |
51 /// A path coming from a pubspec is a simple string. From a lock file, it's | 61 /// A path coming from a pubspec is a simple string. From a lock file, it's |
52 /// an expanded {"path": ..., "relative": ...} map. | 62 /// an expanded {"path": ..., "relative": ...} map. |
53 dynamic parseDescription(String containingPath, description, | 63 dynamic parseDescription(String containingPath, description, |
54 {bool fromLockFile: false}) { | 64 {bool fromLockFile: false}) { |
55 if (fromLockFile) { | 65 if (fromLockFile) { |
56 if (description is! Map) { | 66 if (description is! Map) { |
57 throw new FormatException("The description must be a map."); | 67 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( | 111 throw new FormatException( |
102 "Path dependency for package '$name' must refer to a " | 112 "Path dependency for package '$name' must refer to a " |
103 "directory, not a file. Was '$dir'."); | 113 "directory, not a file. Was '$dir'."); |
104 } | 114 } |
105 | 115 |
106 if (!dirExists(dir)) { | 116 if (!dirExists(dir)) { |
107 throw new FormatException("Could not find package '$name' at '$dir'."); | 117 throw new FormatException("Could not find package '$name' at '$dir'."); |
108 } | 118 } |
109 } | 119 } |
110 } | 120 } |
OLD | NEW |