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

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

Issue 11151026: Download to a temp dir and rename on success. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. Created 8 years, 2 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/hosted_source.dart ('k') | utils/pub/version_solver.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 /** 5 /**
6 * Helper functionality to make working with IO easier. 6 * Helper functionality to make working with IO easier.
7 */ 7 */
8 library io; 8 library io;
9 9
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 if (exists) { 276 if (exists) {
277 // Delete it first. 277 // Delete it first.
278 return deleteDir(dir).chain((_) => createDir(dir)); 278 return deleteDir(dir).chain((_) => createDir(dir));
279 } else { 279 } else {
280 // Just create it. 280 // Just create it.
281 return createDir(dir); 281 return createDir(dir);
282 } 282 }
283 }); 283 });
284 } 284 }
285 285
286 /// Renames (i.e. moves) the directory [from] to [to]. Returns a [Future] with
287 /// the destination directory.
288 Future<Directory> renameDir(from, String to) =>_getDirectory(from).rename(to);
289
286 /** 290 /**
287 * Creates a new symlink that creates an alias from [from] to [to], both of 291 * Creates a new symlink that creates an alias from [from] to [to], both of
288 * which can be a [String], [File], or [Directory]. Returns a [Future] which 292 * which can be a [String], [File], or [Directory]. Returns a [Future] which
289 * completes to the symlink file (i.e. [to]). 293 * completes to the symlink file (i.e. [to]).
290 */ 294 */
291 Future<File> createSymlink(from, to) { 295 Future<File> createSymlink(from, to) {
292 from = _getPath(from); 296 from = _getPath(from);
293 to = _getPath(to); 297 to = _getPath(to);
294 298
295 var command = 'ln'; 299 var command = 'ln';
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 return createFileFromStream(stream, join(tempDir, 'data.tar.gz')); 687 return createFileFromStream(stream, join(tempDir, 'data.tar.gz'));
684 }).chain((tarGz) { 688 }).chain((tarGz) {
685 // 7zip can't unarchive from gzip -> tar -> destination all in one step 689 // 7zip can't unarchive from gzip -> tar -> destination all in one step
686 // first we un-gzip it to a tar file. 690 // first we un-gzip it to a tar file.
687 // Note: Setting the working directory instead of passing in a full file 691 // Note: Setting the working directory instead of passing in a full file
688 // path because 7zip says "A full path is not allowed here." 692 // path because 7zip says "A full path is not allowed here."
689 return runProcess(command, ['e', 'data.tar.gz'], workingDir: tempDir); 693 return runProcess(command, ['e', 'data.tar.gz'], workingDir: tempDir);
690 }).chain((result) { 694 }).chain((result) {
691 if (result.exitCode != 0) { 695 if (result.exitCode != 0) {
692 throw 'Could not un-gzip (exit code ${result.exitCode}). Error:\n' 696 throw 'Could not un-gzip (exit code ${result.exitCode}). Error:\n'
697 '${Strings.join(result.stdout, "\n")}\n'
693 '${Strings.join(result.stderr, "\n")}'; 698 '${Strings.join(result.stderr, "\n")}';
694 } 699 }
695 700
696 // Find the tar file we just created since we don't know its name. 701 // Find the tar file we just created since we don't know its name.
697 return listDir(tempDir); 702 return listDir(tempDir);
698 }).chain((files) { 703 }).chain((files) {
699 var tarFile; 704 var tarFile;
700 for (var file in files) { 705 for (var file in files) {
701 if (new Path(file).extension == 'tar') { 706 if (new Path(file).extension == 'tar') {
702 tarFile = file; 707 tarFile = file;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 return new Directory(entry); 779 return new Directory(entry);
775 } 780 }
776 781
777 /** 782 /**
778 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. 783 * Gets a [Uri] for [uri], which can either already be one, or be a [String].
779 */ 784 */
780 Uri _getUri(uri) { 785 Uri _getUri(uri) {
781 if (uri is Uri) return uri; 786 if (uri is Uri) return uri;
782 return new Uri.fromString(uri); 787 return new Uri.fromString(uri);
783 } 788 }
OLDNEW
« no previous file with comments | « utils/pub/hosted_source.dart ('k') | utils/pub/version_solver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698