Chromium Code Reviews| 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 /** | 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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 // relative path to 7zip in the SDK. | 678 // relative path to 7zip in the SDK. |
| 679 var pathTo7zip = '../../third_party/7zip/7za.exe'; | 679 var pathTo7zip = '../../third_party/7zip/7za.exe'; |
| 680 var command = scriptDir.append(pathTo7zip).canonicalize().toNativePath(); | 680 var command = scriptDir.append(pathTo7zip).canonicalize().toNativePath(); |
| 681 | 681 |
| 682 var tempDir; | 682 var tempDir; |
| 683 | 683 |
| 684 return createTempDir().chain((temp) { | 684 return createTempDir().chain((temp) { |
| 685 // Write the archive to a temp file. | 685 // Write the archive to a temp file. |
| 686 tempDir = temp; | 686 tempDir = temp; |
| 687 return createFileFromStream(stream, join(tempDir, 'data.tar.gz')); | 687 return createFileFromStream(stream, join(tempDir, 'data.tar.gz')); |
| 688 }).chain((tarGz) { | 688 }).chain((_) { |
| 689 // TODO(rnystrom): Hack. We get intermittent "file already in use" errors. | |
|
kasperl
2012/10/16 05:44:46
This smells like a dart:io issue. Did you file a b
| |
| 690 // It looks like the 7zip process is starting up before the file has | |
| 691 // finished being written. So we'll just sleep for a couple of seconds | |
| 692 // here. :( | |
| 693 return sleep(2000); | |
| 694 }).chain((_) { | |
| 689 // 7zip can't unarchive from gzip -> tar -> destination all in one step | 695 // 7zip can't unarchive from gzip -> tar -> destination all in one step |
| 690 // first we un-gzip it to a tar file. | 696 // first we un-gzip it to a tar file. |
| 691 // Note: Setting the working directory instead of passing in a full file | 697 // Note: Setting the working directory instead of passing in a full file |
| 692 // path because 7zip says "A full path is not allowed here." | 698 // path because 7zip says "A full path is not allowed here." |
| 693 return runProcess(command, ['e', 'data.tar.gz'], workingDir: tempDir); | 699 return runProcess(command, ['e', 'data.tar.gz'], workingDir: tempDir); |
| 694 }).chain((result) { | 700 }).chain((result) { |
| 695 if (result.exitCode != 0) { | 701 if (result.exitCode != 0) { |
| 696 throw 'Could not un-gzip (exit code ${result.exitCode}). Error:\n' | 702 throw 'Could not un-gzip (exit code ${result.exitCode}). Error:\n' |
| 697 '${Strings.join(result.stdout, "\n")}\n' | 703 '${Strings.join(result.stdout, "\n")}\n' |
| 698 '${Strings.join(result.stderr, "\n")}'; | 704 '${Strings.join(result.stderr, "\n")}'; |
| 699 } | 705 } |
| 700 | |
| 701 // Find the tar file we just created since we don't know its name. | 706 // Find the tar file we just created since we don't know its name. |
| 702 return listDir(tempDir); | 707 return listDir(tempDir); |
| 703 }).chain((files) { | 708 }).chain((files) { |
| 704 var tarFile; | 709 var tarFile; |
| 705 for (var file in files) { | 710 for (var file in files) { |
| 706 if (new Path(file).extension == 'tar') { | 711 if (new Path(file).extension == 'tar') { |
| 707 tarFile = file; | 712 tarFile = file; |
| 708 break; | 713 break; |
| 709 } | 714 } |
| 710 } | 715 } |
| 711 | 716 |
| 712 if (tarFile == null) throw 'The gzip file did not contain a tar file.'; | 717 if (tarFile == null) throw 'The gzip file did not contain a tar file.'; |
| 713 | 718 |
| 714 // Untar the archive into the destination directory. | 719 // Untar the archive into the destination directory. |
| 715 return runProcess(command, ['x', '-o"$destination"', tarFile], | 720 return runProcess(command, ['x', '-o"$destination"', tarFile], |
| 716 workingDir: tempDir); | 721 workingDir: tempDir); |
| 717 }).chain((result) { | 722 }).chain((result) { |
| 718 if (result.exitCode != 0) { | 723 if (result.exitCode != 0) { |
| 719 throw 'Could not un-tar (exit code ${result.exitCode}). Error:\n' | 724 throw 'Could not un-tar (exit code ${result.exitCode}). Error:\n' |
| 725 '${Strings.join(result.stdout, "\n")}\n' | |
| 720 '${Strings.join(result.stderr, "\n")}'; | 726 '${Strings.join(result.stderr, "\n")}'; |
| 721 } | 727 } |
| 722 | 728 |
| 723 // Clean up the temp directory. | 729 // Clean up the temp directory. |
| 724 // TODO(rnystrom): Should also delete this if anything fails. | 730 // TODO(rnystrom): Should also delete this if anything fails. |
| 725 return deleteDir(tempDir); | 731 return deleteDir(tempDir); |
| 726 }).transform((_) => true); | 732 }).transform((_) => true); |
| 727 } | 733 } |
| 728 | 734 |
| 729 /** | 735 /** |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 return new Directory(entry); | 785 return new Directory(entry); |
| 780 } | 786 } |
| 781 | 787 |
| 782 /** | 788 /** |
| 783 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 789 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 784 */ | 790 */ |
| 785 Uri _getUri(uri) { | 791 Uri _getUri(uri) { |
| 786 if (uri is Uri) return uri; | 792 if (uri is Uri) return uri; |
| 787 return new Uri.fromString(uri); | 793 return new Uri.fromString(uri); |
| 788 } | 794 } |
| OLD | NEW |