| 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:io' as io; | 7 import 'dart:io' as io; |
| 8 import 'dart:json'; | 8 import 'dart:json'; |
| 9 import 'dart:uri'; | 9 import 'dart:uri'; |
| 10 | 10 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 var tempDir; | 79 var tempDir; |
| 80 return Futures.wait([httpGet(fullUrl), | 80 return Futures.wait([httpGet(fullUrl), |
| 81 systemCache.createTempDir()]).chain((args) { | 81 systemCache.createTempDir()]).chain((args) { |
| 82 tempDir = args[1]; | 82 tempDir = args[1]; |
| 83 return timeout(extractTarGz(args[0], tempDir), HTTP_TIMEOUT, | 83 return timeout(extractTarGz(args[0], tempDir), HTTP_TIMEOUT, |
| 84 'Timed out while fetching URL "$fullUrl".'); | 84 'Timed out while fetching URL "$fullUrl".'); |
| 85 }).chain((_) { | 85 }).chain((_) { |
| 86 // Now that the install has succeeded, move it to the real location in | 86 // Now that the install has succeeded, move it to the real location in |
| 87 // the cache. This ensures that we don't leave half-busted ghost | 87 // the cache. This ensures that we don't leave half-busted ghost |
| 88 // directories in the user's pub cache if an install fails. | 88 // directories in the user's pub cache if an install fails. |
| 89 | 89 return renameDir(tempDir, destPath); |
| 90 if (io.Platform.operatingSystem == "windows") { | |
| 91 // TODO(rnystrom): Awful hack. On Windows, we see cases where the | |
| 92 // extract has not finished by the time we get here, so the rename fails | |
| 93 // with a "directory in use" error. So, we will just wait a couple of | |
| 94 // seconds before we start. | |
| 95 return sleep(2000).chain((_) => renameDir(tempDir, destPath)); | |
| 96 } else { | |
| 97 return renameDir(tempDir, destPath); | |
| 98 } | |
| 99 }).transform((_) => true); | 90 }).transform((_) => true); |
| 100 } | 91 } |
| 101 | 92 |
| 102 /** | 93 /** |
| 103 * The system cache directory for the hosted source contains subdirectories | 94 * The system cache directory for the hosted source contains subdirectories |
| 104 * for each separate repository URL that's used on the system. Each of these | 95 * for each separate repository URL that's used on the system. Each of these |
| 105 * subdirectories then contains a subdirectory for each package installed | 96 * subdirectories then contains a subdirectory for each package installed |
| 106 * from that site. | 97 * from that site. |
| 107 */ | 98 */ |
| 108 String systemCacheDirectory(PackageId id) { | 99 String systemCacheDirectory(PackageId id) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 144 |
| 154 var name = description["name"]; | 145 var name = description["name"]; |
| 155 if (name is! String) { | 146 if (name is! String) { |
| 156 throw new FormatException("The 'name' key must have a string value."); | 147 throw new FormatException("The 'name' key must have a string value."); |
| 157 } | 148 } |
| 158 | 149 |
| 159 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 150 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
| 160 return new Pair<String, String>(name, url); | 151 return new Pair<String, String>(name, url); |
| 161 } | 152 } |
| 162 } | 153 } |
| OLD | NEW |