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/path/lib/path.dart' as path; | 10 import '../../pkg/path/lib/path.dart' as path; |
(...skipping 11 matching lines...) Expand all Loading... | |
22 final name = 'path'; | 22 final name = 'path'; |
23 final shouldCache = false; | 23 final shouldCache = false; |
24 | 24 |
25 Future<Pubspec> describe(PackageId id) { | 25 Future<Pubspec> describe(PackageId id) { |
26 return defer(() { | 26 return defer(() { |
27 _validatePath(id.name, id.description); | 27 _validatePath(id.name, id.description); |
28 return new Pubspec.load(id.name, id.description, systemCache.sources); | 28 return new Pubspec.load(id.name, id.description, systemCache.sources); |
29 }); | 29 }); |
30 } | 30 } |
31 | 31 |
32 Future<bool> install(PackageId id, String path) { | 32 Future<bool> install(PackageId id, String destination) { |
33 return defer(() { | 33 return defer(() { |
34 try { | 34 try { |
35 _validatePath(id.name, id.description); | 35 _validatePath(id.name, id.description); |
36 } on FormatException catch(err) { | 36 } on FormatException catch(err) { |
37 return false; | 37 return false; |
38 } | 38 } |
39 return createPackageSymlink(id.name, id.description, path); | 39 |
40 return createPackageSymlink(id.name, destination, id.description, | |
41 relative: true); | |
nweiz
2013/02/15 23:09:24
This should be relative iff the path the user spec
Bob Nystrom
2013/02/16 00:09:57
Done.
| |
40 }).then((_) => true); | 42 }).then((_) => true); |
41 } | 43 } |
42 | 44 |
43 void validateDescription(description, {bool fromLockFile: false}) { | 45 dynamic parseDescription(String containingPath, description, |
46 {bool fromLockFile: false}) { | |
44 if (description is! String) { | 47 if (description is! String) { |
45 throw new FormatException("The description must be a path string."); | 48 throw new FormatException("The description must be a path string."); |
46 } | 49 } |
50 | |
51 if (path.isRelative(description)) { | |
52 // Can't handle relative paths coming from pubspecs that are not on the | |
53 // local file system. | |
nweiz
2013/02/15 23:09:24
Can this ever happen in practice? If so, we should
Bob Nystrom
2013/02/16 00:09:57
If a hosted package had a path dependency (which i
nweiz
2013/02/16 01:02:14
What if a remote git dependency has a path depende
Bob Nystrom
2013/02/16 01:19:03
I believe that will get installed locally, and the
nweiz
2013/02/16 01:33:11
That sounds like something else we should throw a
| |
54 assert(containingPath != null); | |
55 description = path.join(path.dirname(containingPath), description); | |
56 } | |
57 | |
58 return description; | |
47 } | 59 } |
48 | 60 |
49 /// Ensures that [dir] is a valid path. It must be an absolute path that | 61 /// Ensures that [dir] is a valid path. It must be an absolute path that |
50 /// points to an existing directory. Throws a [FormatException] if the path | 62 /// points to an existing directory. Throws a [FormatException] if the path |
51 /// is invalid. | 63 /// is invalid. |
52 void _validatePath(String name, String dir) { | 64 void _validatePath(String name, String dir) { |
53 // Relative paths are not (currently) allowed because the user would expect | 65 // Relative paths are not (currently) allowed because the user would expect |
54 // them to be relative to the pubspec where the dependency appears. That in | 66 // them to be relative to the pubspec where the dependency appears. That in |
55 // turn means that two pubspecs in different locations with the same | 67 // turn means that two pubspecs in different locations with the same |
56 // relative path dependency could refer to two different packages. That | 68 // relative path dependency could refer to two different packages. That |
(...skipping 12 matching lines...) Expand all Loading... | |
69 throw new FormatException( | 81 throw new FormatException( |
70 "Path dependency for package '$name' must refer to a " | 82 "Path dependency for package '$name' must refer to a " |
71 "directory, not a file. Was '$dir'."); | 83 "directory, not a file. Was '$dir'."); |
72 } | 84 } |
73 | 85 |
74 if (!dirExists(dir)) { | 86 if (!dirExists(dir)) { |
75 throw new FormatException("Could not find package '$name' at '$dir'."); | 87 throw new FormatException("Could not find package '$name' at '$dir'."); |
76 } | 88 } |
77 } | 89 } |
78 } | 90 } |
OLD | NEW |