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

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

Issue 14070010: Refactor Future constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added co19 issue number. Created 7 years, 8 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/oauth2.dart ('k') | utils/pub/pub.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'package:pathos/path.dart' as path; 10 import 'package:pathos/path.dart' as path;
11 11
12 import 'log.dart' as log; 12 import 'log.dart' as log;
13 13
14 import 'io.dart'; 14 import 'io.dart';
15 import 'package.dart'; 15 import 'package.dart';
16 import 'pubspec.dart'; 16 import 'pubspec.dart';
17 import 'version.dart'; 17 import 'version.dart';
18 import 'source.dart'; 18 import 'source.dart';
19 import 'utils.dart'; 19 import 'utils.dart';
20 20
21 // TODO(rnystrom): Support relative paths. (See comment in _validatePath().) 21 // TODO(rnystrom): Support relative paths. (See comment in _validatePath().)
22 /// 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.
23 class PathSource extends Source { 23 class PathSource extends Source {
24 final name = 'path'; 24 final name = 'path';
25 final shouldCache = false; 25 final shouldCache = false;
26 26
27 Future<Pubspec> describe(PackageId id) { 27 Future<Pubspec> describe(PackageId id) {
28 return new Future.of(() { 28 return new Future.sync(() {
29 _validatePath(id.name, id.description); 29 _validatePath(id.name, id.description);
30 return new Pubspec.load(id.name, id.description["path"], 30 return new Pubspec.load(id.name, id.description["path"],
31 systemCache.sources); 31 systemCache.sources);
32 }); 32 });
33 } 33 }
34 34
35 bool descriptionsEqual(description1, description2) { 35 bool descriptionsEqual(description1, description2) {
36 // Compare real paths after normalizing and resolving symlinks. 36 // Compare real paths after normalizing and resolving symlinks.
37 var path1 = new File(description1["path"]).fullPathSync(); 37 var path1 = new File(description1["path"]).fullPathSync();
38 var path2 = new File(description2["path"]).fullPathSync(); 38 var path2 = new File(description2["path"]).fullPathSync();
39 return path1 == path2; 39 return path1 == path2;
40 } 40 }
41 41
42 Future<bool> install(PackageId id, String destination) { 42 Future<bool> install(PackageId id, String destination) {
43 return new Future.of(() { 43 return new Future.sync(() {
44 try { 44 try {
45 _validatePath(id.name, id.description); 45 _validatePath(id.name, id.description);
46 } on FormatException catch(err) { 46 } on FormatException catch(err) {
47 return false; 47 return false;
48 } 48 }
49 49
50 createPackageSymlink(id.name, id.description["path"], destination, 50 createPackageSymlink(id.name, id.description["path"], destination,
51 relative: id.description["relative"]); 51 relative: id.description["relative"]);
52 return true; 52 return true;
53 }); 53 });
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 if (fileExists(dir)) { 112 if (fileExists(dir)) {
113 throw new FormatException( 113 throw new FormatException(
114 "Path dependency for package '$name' must refer to a " 114 "Path dependency for package '$name' must refer to a "
115 "directory, not a file. Was '$dir'."); 115 "directory, not a file. Was '$dir'.");
116 } 116 }
117 117
118 throw new FormatException("Could not find package '$name' at '$dir'."); 118 throw new FormatException("Could not find package '$name' at '$dir'.");
119 } 119 }
120 } 120 }
OLDNEW
« no previous file with comments | « utils/pub/oauth2.dart ('k') | utils/pub/pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698