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

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

Issue 12225085: Make createTempDir() synchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « no previous file | utils/pub/io.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) 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 return httpClient.read(fullUrl).then((yaml) { 56 return httpClient.read(fullUrl).then((yaml) {
57 return new Pubspec.parse(yaml, systemCache.sources); 57 return new Pubspec.parse(yaml, systemCache.sources);
58 }).catchError((ex) { 58 }).catchError((ex) {
59 _throwFriendlyError(ex, id, parsed.last); 59 _throwFriendlyError(ex, id, parsed.last);
60 }); 60 });
61 } 61 }
62 62
63 /// Downloads a package from the site and unpacks it. 63 /// Downloads a package from the site and unpacks it.
64 Future<bool> install(PackageId id, String destPath) { 64 Future<bool> install(PackageId id, String destPath) {
65 var parsedDescription = _parseDescription(id.description); 65 return defer(() {
66 var name = parsedDescription.first; 66 var parsedDescription = _parseDescription(id.description);
67 var url = parsedDescription.last; 67 var name = parsedDescription.first;
68 var url = parsedDescription.last;
68 69
69 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz"; 70 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz";
70 71
71 log.message('Downloading $id...'); 72 log.message('Downloading $id...');
72 73
73 // Download and extract the archive to a temp directory. 74 // Download and extract the archive to a temp directory.
74 var tempDir; 75 var tempDir = systemCache.createTempDir();
75 return Future.wait([ 76 return httpClient.send(new http.Request("GET", Uri.parse(fullUrl)))
76 httpClient.send(new http.Request("GET", Uri.parse(fullUrl))) 77 .then((response) => response.stream)
77 .then((response) => response.stream), 78 .then((stream) {
78 systemCache.createTempDir() 79 return timeout(extractTarGz(stream, tempDir), HTTP_TIMEOUT,
79 ]).then((args) { 80 'fetching URL "$fullUrl"');
80 var stream = args[0]; 81 }).then((_) {
81 tempDir = args[1]; 82 // Now that the install has succeeded, move it to the real location in
82 return timeout(extractTarGz(stream, tempDir), HTTP_TIMEOUT, 83 // the cache. This ensures that we don't leave half-busted ghost
83 'fetching URL "$fullUrl"'); 84 // directories in the user's pub cache if an install fails.
84 }).then((_) { 85 return renameDir(tempDir, destPath);
85 // Now that the install has succeeded, move it to the real location in 86 }).then((_) => true);
86 // the cache. This ensures that we don't leave half-busted ghost 87 });
87 // directories in the user's pub cache if an install fails.
88 return renameDir(tempDir, destPath);
89 }).then((_) => true);
90 } 88 }
91 89
92 /// The system cache directory for the hosted source contains subdirectories 90 /// 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 91 /// for each separate repository URL that's used on the system. Each of these
94 /// subdirectories then contains a subdirectory for each package installed 92 /// subdirectories then contains a subdirectory for each package installed
95 /// from that site. 93 /// from that site.
96 Future<String> systemCacheDirectory(PackageId id) { 94 Future<String> systemCacheDirectory(PackageId id) {
97 var parsed = _parseDescription(id.description); 95 var parsed = _parseDescription(id.description);
98 var url = parsed.last.replaceAll(new RegExp(r"^https?://"), ""); 96 var url = parsed.last.replaceAll(new RegExp(r"^https?://"), "");
99 var urlDir = replace(url, new RegExp(r'[<>:"\\/|?*%]'), (match) { 97 var urlDir = replace(url, new RegExp(r'[<>:"\\/|?*%]'), (match) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 159
162 var name = description["name"]; 160 var name = description["name"];
163 if (name is! String) { 161 if (name is! String) {
164 throw new FormatException("The 'name' key must have a string value."); 162 throw new FormatException("The 'name' key must have a string value.");
165 } 163 }
166 164
167 var url = description.containsKey("url") ? description["url"] : defaultUrl; 165 var url = description.containsKey("url") ? description["url"] : defaultUrl;
168 return new Pair<String, String>(name, url); 166 return new Pair<String, String>(name, url);
169 } 167 }
170 } 168 }
OLDNEW
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698