| 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 entrypoint; | 5 library entrypoint; |
| 6 | 6 |
| 7 import 'io.dart'; | 7 import 'io.dart'; |
| 8 import 'lock_file.dart'; | 8 import 'lock_file.dart'; |
| 9 import 'log.dart' as log; | 9 import 'log.dart' as log; |
| 10 import 'package.dart'; | 10 import 'package.dart'; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 160 } |
| 161 | 161 |
| 162 /** | 162 /** |
| 163 * Loads the list of concrete package versions from the `pubspec.lock`, if it | 163 * Loads the list of concrete package versions from the `pubspec.lock`, if it |
| 164 * exists. If it doesn't, this completes to an empty [LockFile]. | 164 * exists. If it doesn't, this completes to an empty [LockFile]. |
| 165 * | 165 * |
| 166 * If there's an error reading the `pubspec.lock` file, this will print a | 166 * If there's an error reading the `pubspec.lock` file, this will print a |
| 167 * warning message and act as though the file doesn't exist. | 167 * warning message and act as though the file doesn't exist. |
| 168 */ | 168 */ |
| 169 Future<LockFile> _loadLockFile() { | 169 Future<LockFile> _loadLockFile() { |
| 170 var completer = new Completer<LockFile>(); | |
| 171 var lockFilePath = join(root.dir, 'pubspec.lock'); | 170 var lockFilePath = join(root.dir, 'pubspec.lock'); |
| 172 | 171 |
| 173 log.fine("Loading lockfile."); | 172 log.fine("Loading lockfile."); |
| 174 var future = readTextFile(lockFilePath); | 173 return fileExists(lockFilePath).chain((exists) { |
| 174 if (!exists) { |
| 175 log.fine("No lock file at $lockFilePath, creating empty one."); |
| 176 return new Future<LockFile>.immediate(new LockFile.empty()); |
| 177 } |
| 175 | 178 |
| 176 future.handleException((_) { | 179 return readTextFile(lockFilePath).transform((text) => |
| 177 // If we failed to load the lockfile but it does exist, something's | 180 new LockFile.parse(text, cache.sources)); |
| 178 // probably wrong and we should notify the user. | |
| 179 fileExists(lockFilePath).transform((exists) { | |
| 180 if (!exists) return; | |
| 181 log.error("Error reading pubspec.lock: ${future.exception}"); | |
| 182 }).then((_) { | |
| 183 log.fine("No lock file at $lockFilePath, creating empty one."); | |
| 184 completer.complete(new LockFile.empty()); | |
| 185 }); | |
| 186 | |
| 187 return true; | |
| 188 }); | 181 }); |
| 189 | |
| 190 future.then((text) => | |
| 191 completer.complete(new LockFile.parse(text, cache.sources))); | |
| 192 return completer.future; | |
| 193 } | 182 } |
| 194 | 183 |
| 195 /** | 184 /** |
| 196 * Saves a list of concrete package versions to the `pubspec.lock` file. | 185 * Saves a list of concrete package versions to the `pubspec.lock` file. |
| 197 */ | 186 */ |
| 198 Future _saveLockFile(List<PackageId> packageIds) { | 187 Future _saveLockFile(List<PackageId> packageIds) { |
| 199 var lockFile = new LockFile.empty(); | 188 var lockFile = new LockFile.empty(); |
| 200 for (var id in packageIds) { | 189 for (var id in packageIds) { |
| 201 if (id.source is! RootSource) lockFile.packages[id.name] = id; | 190 if (id.source is! RootSource) lockFile.packages[id.name] = id; |
| 202 } | 191 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 * Creates a symlink to the `packages` directory in [dir] if none exists. | 275 * Creates a symlink to the `packages` directory in [dir] if none exists. |
| 287 */ | 276 */ |
| 288 Future _linkSecondaryPackageDir(String dir) { | 277 Future _linkSecondaryPackageDir(String dir) { |
| 289 var to = join(dir, 'packages'); | 278 var to = join(dir, 'packages'); |
| 290 return exists(to).chain((exists) { | 279 return exists(to).chain((exists) { |
| 291 if (exists) return new Future.immediate(null); | 280 if (exists) return new Future.immediate(null); |
| 292 return createSymlink(path, to); | 281 return createSymlink(path, to); |
| 293 }); | 282 }); |
| 294 } | 283 } |
| 295 } | 284 } |
| OLD | NEW |