aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-01-09 13:10:10 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-09 13:10:10 +0100
commit8c1d857d2582c689681c7e6d3dc299613b4a7167 (patch)
tree2f956b2103f5ef4e1ba4669ce30c001b444dd051
parent6b4f4b52845d903f6e06f4dbca22ad0e2f67f473 (diff)
downloadbusybox-w32-8c1d857d2582c689681c7e6d3dc299613b4a7167.tar.gz
busybox-w32-8c1d857d2582c689681c7e6d3dc299613b4a7167.tar.bz2
busybox-w32-8c1d857d2582c689681c7e6d3dc299613b4a7167.zip
unzip: match "Defl:?" display with info-zip; cosmetic code shuffling
Large nested indented code blocks made more sane with a few gotos. function old new delta unzip_main 2491 2519 +28 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/unzip.c211
1 files changed, 109 insertions, 102 deletions
diff --git a/archival/unzip.c b/archival/unzip.c
index 6dc5d89c2..028e4e62e 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -659,8 +659,9 @@ int unzip_main(int argc, char **argv)
659 659
660 xread(zip_fd, zip.raw, ZIP_HEADER_LEN); 660 xread(zip_fd, zip.raw, ZIP_HEADER_LEN);
661 FIX_ENDIANNESS_ZIP(zip); 661 FIX_ENDIANNESS_ZIP(zip);
662 if (zip.fmt.zip_flags & SWAP_LE16(0x0009)) { 662 if (zip.fmt.zip_flags & SWAP_LE16(0x0008)) {
663 bb_error_msg_and_die("zip flags 1 and 8 are not supported"); 663 bb_error_msg_and_die("zip flag %s is not supported",
664 "8 (streaming)");
664 } 665 }
665 } 666 }
666#if ENABLE_FEATURE_UNZIP_CDF 667#if ENABLE_FEATURE_UNZIP_CDF
@@ -704,7 +705,8 @@ int unzip_main(int argc, char **argv)
704 705
705 if (zip.fmt.zip_flags & SWAP_LE16(0x0001)) { 706 if (zip.fmt.zip_flags & SWAP_LE16(0x0001)) {
706 /* 0x0001 - encrypted */ 707 /* 0x0001 - encrypted */
707 bb_error_msg_and_die("zip flag 1 (encryption) is not supported"); 708 bb_error_msg_and_die("zip flag %s is not supported",
709 "1 (encryption)");
708 } 710 }
709 dbg("File cmpsize:0x%x extra_len:0x%x ucmpsize:0x%x", 711 dbg("File cmpsize:0x%x extra_len:0x%x ucmpsize:0x%x",
710 (unsigned)zip.fmt.cmpsize, 712 (unsigned)zip.fmt.cmpsize,
@@ -727,118 +729,123 @@ int unzip_main(int argc, char **argv)
727 if (find_list_entry(zreject, dst_fn) 729 if (find_list_entry(zreject, dst_fn)
728 || (zaccept && !find_list_entry(zaccept, dst_fn)) 730 || (zaccept && !find_list_entry(zaccept, dst_fn))
729 ) { /* Skip entry */ 731 ) { /* Skip entry */
730 i = 'n'; 732 goto skip_cmpsize;
731 } else { 733 }
732 if (listing) { 734
733 /* List entry */ 735 if (listing) {
734 char dtbuf[sizeof("mm-dd-yyyy hh:mm")]; 736 /* List entry */
735 sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u", 737 char dtbuf[sizeof("mm-dd-yyyy hh:mm")];
736 (zip.fmt.moddate >> 5) & 0xf, // mm: 0x01e0 738 sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u",
737 (zip.fmt.moddate) & 0x1f, // dd: 0x001f 739 (zip.fmt.moddate >> 5) & 0xf, // mm: 0x01e0
738 (zip.fmt.moddate >> 9) + 1980, // yy: 0xfe00 740 (zip.fmt.moddate) & 0x1f, // dd: 0x001f
739 (zip.fmt.modtime >> 11), // hh: 0xf800 741 (zip.fmt.moddate >> 9) + 1980, // yy: 0xfe00
740 (zip.fmt.modtime >> 5) & 0x3f // mm: 0x07e0 742 (zip.fmt.modtime >> 11), // hh: 0xf800
741 // seconds/2 not shown, encoded in -- 0x001f 743 (zip.fmt.modtime >> 5) & 0x3f // mm: 0x07e0
742 ); 744 // seconds/2 not shown, encoded in -- 0x001f
743 if (!verbose) { 745 );
744 // " Length Date Time Name\n" 746 if (!verbose) {
745 // "--------- ---------- ----- ----" 747 // " Length Date Time Name\n"
746 printf( "%9u " "%s " "%s\n", 748 // "--------- ---------- ----- ----"
747 (unsigned)zip.fmt.ucmpsize, 749 printf( "%9u " "%s " "%s\n",
748 dtbuf, 750 (unsigned)zip.fmt.ucmpsize,
749 dst_fn); 751 dtbuf,
750 } else { 752 dst_fn);
751 char method6[7]; 753 } else {
752 unsigned long percents; 754 char method6[7];
753 755 unsigned long percents;
754 sprintf(method6, "%6u", zip.fmt.method); 756
755 percents = zip.fmt.ucmpsize - zip.fmt.cmpsize; 757 sprintf(method6, "%6u", zip.fmt.method);
756 if ((int32_t)percents < 0) 758 if (zip.fmt.method == 0) {
757 percents = 0; /* happens if ucmpsize < cmpsize */ 759 strcpy(method6, "Stored");
758 percents = percents * 100;
759 if (zip.fmt.ucmpsize)
760 percents /= zip.fmt.ucmpsize;
761 // " Length Method Size Cmpr Date Time CRC-32 Name\n"
762 // "-------- ------ ------- ---- ---------- ----- -------- ----"
763 printf( "%8u %s" "%9u%4u%% " "%s " "%08x " "%s\n",
764 (unsigned)zip.fmt.ucmpsize,
765 zip.fmt.method == 0 ? "Stored"
766 : zip.fmt.method == 8 ? "Defl:N"
767 : method6,
768 (unsigned)zip.fmt.cmpsize,
769 (unsigned)percents,
770 dtbuf,
771 zip.fmt.crc32,
772 dst_fn);
773 total_size += zip.fmt.cmpsize;
774 } 760 }
775 total_usize += zip.fmt.ucmpsize; 761 if (zip.fmt.method == 8) {
776 i = 'n'; 762 strcpy(method6, "Defl:N");
777 } else if (dst_fd == STDOUT_FILENO) { 763 /* normal, maximum, fast, superfast */
778 /* Extracting to STDOUT */ 764 IF_DESKTOP(method6[5] = "NXFS"[(zip.fmt.zip_flags >> 1) & 3];)
779 i = -1; 765 }
780 } else if (last_char_is(dst_fn, '/')) { 766 percents = zip.fmt.ucmpsize - zip.fmt.cmpsize;
781 /* Extract directory */ 767 if ((int32_t)percents < 0)
782 if (stat(dst_fn, &stat_buf) == -1) { 768 percents = 0; /* happens if ucmpsize < cmpsize */
783 if (errno != ENOENT) { 769 percents = percents * 100;
784 bb_perror_msg_and_die("can't stat '%s'", dst_fn); 770 if (zip.fmt.ucmpsize)
785 } 771 percents /= zip.fmt.ucmpsize;
786 if (!quiet) { 772 // " Length Method Size Cmpr Date Time CRC-32 Name\n"
787 printf(" creating: %s\n", dst_fn); 773 // "-------- ------ ------- ---- ---------- ----- -------- ----"
788 } 774 printf( "%8u %s" "%9u%4u%% " "%s " "%08x " "%s\n",
789 unzip_create_leading_dirs(dst_fn); 775 (unsigned)zip.fmt.ucmpsize,
790 if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) { 776 method6,
791 xfunc_die(); 777 (unsigned)zip.fmt.cmpsize,
792 } 778 (unsigned)percents,
793 } else { 779 dtbuf,
794 if (!S_ISDIR(stat_buf.st_mode)) { 780 zip.fmt.crc32,
795 bb_error_msg_and_die("'%s' exists but is not a %s", 781 dst_fn);
796 dst_fn, "directory"); 782 total_size += zip.fmt.cmpsize;
797 } 783 }
784 total_usize += zip.fmt.ucmpsize;
785 goto skip_cmpsize;
786 }
787
788 if (dst_fd == STDOUT_FILENO) {
789 /* Extracting to STDOUT */
790 goto do_extract;
791 }
792 if (last_char_is(dst_fn, '/')) {
793 /* Extract directory */
794 if (stat(dst_fn, &stat_buf) == -1) {
795 if (errno != ENOENT) {
796 bb_perror_msg_and_die("can't stat '%s'", dst_fn);
797 }
798 if (!quiet) {
799 printf(" creating: %s\n", dst_fn);
800 }
801 unzip_create_leading_dirs(dst_fn);
802 if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) {
803 xfunc_die();
798 } 804 }
799 i = 'n';
800 } else { 805 } else {
801 /* Extract file */ 806 if (!S_ISDIR(stat_buf.st_mode)) {
802 check_file: 807 bb_error_msg_and_die("'%s' exists but is not a %s",
803 if (stat(dst_fn, &stat_buf) == -1) { 808 dst_fn, "directory");
804 /* File does not exist */
805 if (errno != ENOENT) {
806 bb_perror_msg_and_die("can't stat '%s'", dst_fn);
807 }
808 i = 'y';
809 } else {
810 /* File already exists */
811 if (overwrite == O_NEVER) {
812 i = 'n';
813 } else if (S_ISREG(stat_buf.st_mode)) {
814 /* File is regular file */
815 if (overwrite == O_ALWAYS) {
816 i = 'y';
817 } else {
818 printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
819 my_fgets80(key_buf);
820 i = key_buf[0];
821 }
822 } else {
823 /* File is not regular file */
824 bb_error_msg_and_die("'%s' exists but is not a %s",
825 dst_fn, "regular file");
826 }
827 } 809 }
828 } 810 }
811 goto skip_cmpsize;
812 }
813 check_file:
814 /* Extract file */
815 if (stat(dst_fn, &stat_buf) == -1) {
816 /* File does not exist */
817 if (errno != ENOENT) {
818 bb_perror_msg_and_die("can't stat '%s'", dst_fn);
819 }
820 goto do_open_and_extract;
821 }
822 /* File already exists */
823 if (overwrite == O_NEVER) {
824 goto skip_cmpsize;
825 }
826 if (!S_ISREG(stat_buf.st_mode)) {
827 /* File is not regular file */
828 bb_error_msg_and_die("'%s' exists but is not a %s",
829 dst_fn, "regular file");
829 } 830 }
831 /* File is regular file */
832 if (overwrite == O_ALWAYS)
833 goto do_open_and_extract;
834 printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
835 my_fgets80(key_buf);
830 836
831 switch (i) { 837 switch (key_buf[0]) {
832 case 'A': 838 case 'A':
833 overwrite = O_ALWAYS; 839 overwrite = O_ALWAYS;
834 case 'y': /* Open file and fall into unzip */ 840 case 'y': /* Open file and fall into unzip */
841 do_open_and_extract:
835 unzip_create_leading_dirs(dst_fn); 842 unzip_create_leading_dirs(dst_fn);
836#if ENABLE_FEATURE_UNZIP_CDF 843#if ENABLE_FEATURE_UNZIP_CDF
837 dst_fd = xopen3(dst_fn, O_WRONLY | O_CREAT | O_TRUNC, file_mode); 844 dst_fd = xopen3(dst_fn, O_WRONLY | O_CREAT | O_TRUNC, file_mode);
838#else 845#else
839 dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC); 846 dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
840#endif 847#endif
841 case -1: /* Unzip */ 848 do_extract:
842 if (!quiet) { 849 if (!quiet) {
843 printf(/* zip.fmt.method == 0 850 printf(/* zip.fmt.method == 0
844 ? " extracting: %s\n" 851 ? " extracting: %s\n"
@@ -853,8 +860,8 @@ int unzip_main(int argc, char **argv)
853 860
854 case 'N': 861 case 'N':
855 overwrite = O_NEVER; 862 overwrite = O_NEVER;
856 case 'n': 863 case 'n': /* Skip entry data */
857 /* Skip entry data */ 864 skip_cmpsize:
858 unzip_skip(zip.fmt.cmpsize); 865 unzip_skip(zip.fmt.cmpsize);
859 break; 866 break;
860 867
@@ -868,7 +875,7 @@ int unzip_main(int argc, char **argv)
868 goto check_file; 875 goto check_file;
869 876
870 default: 877 default:
871 printf("error: invalid response [%c]\n", (char)i); 878 printf("error: invalid response [%c]\n", (char)key_buf[0]);
872 goto check_file; 879 goto check_file;
873 } 880 }
874 881