Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(701)

Side by Side Diff: utils/pub/path_source.dart

Issue 12208138: Take Sam Elkhateeb's path for "path" dependencies and clean it up some. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/pub/io.dart ('k') | utils/pub/system_cache.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library path_source;
6
7 import 'dart:async';
8 import 'dart:io';
9
10 import '../../pkg/path/lib/path.dart' as path;
11
12 import 'io.dart';
13 import 'package.dart';
14 import 'pubspec.dart';
15 import 'version.dart';
16 import 'source.dart';
17 import 'utils.dart';
18
19 // TODO(rnystrom): Support relative paths. (See comment in _validatePath().)
20 /// A package [Source] that installs packages from a given local file path.
21 class PathSource extends Source {
22 final name = 'path';
23 final shouldCache = false;
24
25 Future<Pubspec> describe(PackageId id) {
26 return defer(() {
27 _validatePath(id.name, id.description);
28 return new Pubspec.load(id.name, id.description, systemCache.sources);
29 });
30 }
31
32 Future<bool> install(PackageId id, String path) {
33 return defer(() {
34 try {
35 _validatePath(id.name, id.description);
36 } on FormatException catch(err) {
37 return false;
38 }
39 return createPackageSymlink(id.name, id.description, path);
40 }).then((_) => true);
41 }
42
43 void validateDescription(description, {bool fromLockFile: false}) {
44 if (description is! String) {
45 throw new FormatException("The description must be a path string.");
46 }
47 }
48
49 /// 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
51 /// is invalid.
52 void _validatePath(String name, String dir) {
53 // 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
55 // turn means that two pubspecs in different locations with the same
56 // relative path dependency could refer to two different packages. That
57 // violates pub's rule that a description should uniquely identify a
58 // package.
59 //
60 // At some point, we may want to loosen this, but it will mean tracking
61 // where a given PackageId appeared.
62 if (!path.isAbsolute(dir)) {
63 throw new FormatException(
64 "Path dependency for package '$name' must be an absolute path. "
65 "Was '$dir'.");
66 }
67
68 if (fileExists(dir)) {
69 throw new FormatException(
70 "Path dependency for package '$name' must refer to a "
71 "directory, not a file. Was '$dir'.");
72 }
73
74 if (!dirExists(dir)) {
75 throw new FormatException("Could not find package '$name' at '$dir'.");
76 }
77 }
78 }
OLDNEW
« no previous file with comments | « utils/pub/io.dart ('k') | utils/pub/system_cache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698