OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 hosted_source; | 5 library hosted_source; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
10 import 'dart:uri'; | 10 import 'dart:uri'; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // the cache. This ensures that we don't leave half-busted ghost | 86 // the cache. This ensures that we don't leave half-busted ghost |
87 // directories in the user's pub cache if an install fails. | 87 // directories in the user's pub cache if an install fails. |
88 return renameDir(tempDir, destPath); | 88 return renameDir(tempDir, destPath); |
89 }).then((_) => true); | 89 }).then((_) => true); |
90 } | 90 } |
91 | 91 |
92 /// The system cache directory for the hosted source contains subdirectories | 92 /// The system cache directory for the hosted source contains subdirectories |
93 /// for each separate repository URL that's used on the system. Each of these | 93 /// for each separate repository URL that's used on the system. Each of these |
94 /// subdirectories then contains a subdirectory for each package installed | 94 /// subdirectories then contains a subdirectory for each package installed |
95 /// from that site. | 95 /// from that site. |
96 String systemCacheDirectory(PackageId id) { | 96 Future<String> systemCacheDirectory(PackageId id) { |
97 var parsed = _parseDescription(id.description); | 97 var parsed = _parseDescription(id.description); |
98 var url = parsed.last.replaceAll(new RegExp(r"^https?://"), ""); | 98 var url = parsed.last.replaceAll(new RegExp(r"^https?://"), ""); |
99 var urlDir = replace(url, new RegExp(r'[<>:"\\/|?*%]'), (match) { | 99 var urlDir = replace(url, new RegExp(r'[<>:"\\/|?*%]'), (match) { |
100 return '%${match[0].charCodeAt(0)}'; | 100 return '%${match[0].charCodeAt(0)}'; |
101 }); | 101 }); |
102 return join(systemCacheRoot, urlDir, "${parsed.first}-${id.version}"); | 102 |
| 103 return new Future.immediate( |
| 104 join(systemCacheRoot, urlDir, "${parsed.first}-${id.version}")); |
103 } | 105 } |
104 | 106 |
105 String packageName(description) => _parseDescription(description).first; | 107 String packageName(description) => _parseDescription(description).first; |
106 | 108 |
107 bool descriptionsEqual(description1, description2) => | 109 bool descriptionsEqual(description1, description2) => |
108 _parseDescription(description1) == _parseDescription(description2); | 110 _parseDescription(description1) == _parseDescription(description2); |
109 | 111 |
110 /// Ensures that [description] is a valid hosted package description. | 112 /// Ensures that [description] is a valid hosted package description. |
111 /// | 113 /// |
112 /// There are two valid formats. A plain string refers to a package with the | 114 /// There are two valid formats. A plain string refers to a package with the |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 161 |
160 var name = description["name"]; | 162 var name = description["name"]; |
161 if (name is! String) { | 163 if (name is! String) { |
162 throw new FormatException("The 'name' key must have a string value."); | 164 throw new FormatException("The 'name' key must have a string value."); |
163 } | 165 } |
164 | 166 |
165 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 167 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
166 return new Pair<String, String>(name, url); | 168 return new Pair<String, String>(name, url); |
167 } | 169 } |
168 } | 170 } |
OLD | NEW |