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

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: 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) {
289 from = _getDirectory(from);
290 return from.rename(to);
nweiz 2012/10/15 20:56:27 Style nit: this would be cleaner as a one-liner.
Bob Nystrom 2012/10/15 20:59:23 Done.
291 }
292
286 /** 293 /**
287 * Creates a new symlink that creates an alias from [from] to [to], both of 294 * 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 295 * which can be a [String], [File], or [Directory]. Returns a [Future] which
289 * completes to the symlink file (i.e. [to]). 296 * completes to the symlink file (i.e. [to]).
290 */ 297 */
291 Future<File> createSymlink(from, to) { 298 Future<File> createSymlink(from, to) {
292 from = _getPath(from); 299 from = _getPath(from);
293 to = _getPath(to); 300 to = _getPath(to);
294 301
295 var command = 'ln'; 302 var command = 'ln';
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 return createFileFromStream(stream, join(tempDir, 'data.tar.gz')); 690 return createFileFromStream(stream, join(tempDir, 'data.tar.gz'));
684 }).chain((tarGz) { 691 }).chain((tarGz) {
685 // 7zip can't unarchive from gzip -> tar -> destination all in one step 692 // 7zip can't unarchive from gzip -> tar -> destination all in one step
686 // first we un-gzip it to a tar file. 693 // first we un-gzip it to a tar file.
687 // Note: Setting the working directory instead of passing in a full file 694 // Note: Setting the working directory instead of passing in a full file
688 // path because 7zip says "A full path is not allowed here." 695 // path because 7zip says "A full path is not allowed here."
689 return runProcess(command, ['e', 'data.tar.gz'], workingDir: tempDir); 696 return runProcess(command, ['e', 'data.tar.gz'], workingDir: tempDir);
690 }).chain((result) { 697 }).chain((result) {
691 if (result.exitCode != 0) { 698 if (result.exitCode != 0) {
692 throw 'Could not un-gzip (exit code ${result.exitCode}). Error:\n' 699 throw 'Could not un-gzip (exit code ${result.exitCode}). Error:\n'
700 '${Strings.join(result.stdout, "\n")}\n'
693 '${Strings.join(result.stderr, "\n")}'; 701 '${Strings.join(result.stderr, "\n")}';
694 } 702 }
695 703
696 // Find the tar file we just created since we don't know its name. 704 // Find the tar file we just created since we don't know its name.
697 return listDir(tempDir); 705 return listDir(tempDir);
698 }).chain((files) { 706 }).chain((files) {
699 var tarFile; 707 var tarFile;
700 for (var file in files) { 708 for (var file in files) {
701 if (new Path(file).extension == 'tar') { 709 if (new Path(file).extension == 'tar') {
702 tarFile = file; 710 tarFile = file;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 return new Directory(entry); 782 return new Directory(entry);
775 } 783 }
776 784
777 /** 785 /**
778 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. 786 * Gets a [Uri] for [uri], which can either already be one, or be a [String].
779 */ 787 */
780 Uri _getUri(uri) { 788 Uri _getUri(uri) {
781 if (uri is Uri) return uri; 789 if (uri is Uri) return uri;
782 return new Uri.fromString(uri); 790 return new Uri.fromString(uri);
783 } 791 }
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