• R/O
  • SSH
  • HTTPS

lha: Commit


Commit MetaInfo

Revision890 (tree)
Zeit2008-03-10 23:58:32
Autorarai

Log Message

add_dirinfo() no longer suppose that contents of the LZH archive is sorted by pathname.

* src/lhext.c (add_dirinfo): no longer suppose that contents of the LZH archive is sorted by pathname.

* tests/lha-test18: added tests for above.

* src/lharc.c (parse_suboption): added debugging option --debug=nosort' and --debug=norecursion'
for above tests.

* src/lha.h: added two global variables for above options: sort_contents, recursive_archiving;

* src/lharc.c (init_variable): ditto.
(sort_files): no sort arguments with --debug=nosort.
(find_files): no sort directory entries with --debug=nosort.

* src/lhadd.c (append_it): non-sorted and non-recursive archiving with --debug=nosort and --debug=norecursion.

* src/lhadd.c (remove_one): should use the message() instead of printf().

Ändern Zusammenfassung

Diff

--- lha/trunk/ChangeLog (revision 889)
+++ lha/trunk/ChangeLog (revision 890)
@@ -1,3 +1,22 @@
1+2008-03-08 Koji Arai <arai@users.sourceforge.jp>
2+
3+ * src/lhext.c (add_dirinfo): no longer suppose that contents of the LZH archive is sorted by pathname.
4+
5+ * tests/lha-test18: added tests for above.
6+
7+ * src/lharc.c (parse_suboption): added debugging option `--debug=nosort' and `--debug=norecursion'
8+ for above tests.
9+
10+ * src/lha.h: added two global variables for above options: sort_contents, recursive_archiving;
11+
12+ * src/lharc.c (init_variable): ditto.
13+ (sort_files): no sort arguments with --debug=nosort.
14+ (find_files): no sort directory entries with --debug=nosort.
15+
16+ * src/lhadd.c (append_it): non-sorted and non-recursive archiving with --debug=nosort and --debug=norecursion.
17+
18+ * src/lhadd.c (remove_one): should use the message() instead of printf().
19+
120 2008-03-07 Koji Arai <arai@users.sourceforge.jp>
221
322 * man/lha.1: correct the description about the -m command.
--- lha/trunk/src/lha.h (revision 889)
+++ lha/trunk/src/lha.h (revision 890)
@@ -329,9 +329,14 @@
329329 EXTERN int quiet_mode;
330330
331331 EXTERN boolean backup_old_archive;
332-EXTERN boolean extract_broken_archive;
332+EXTERN boolean extract_broken_archive;
333333 EXTERN boolean decode_macbinary_contents;
334334
335+/* for debugging */
336+EXTERN boolean sort_contents;
337+EXTERN boolean recursive_archiving;
338+
339+
335340 /* ------------------------------------------------------------------------ */
336341 /* Globale Variable */
337342 /* ------------------------------------------------------------------------ */
--- lha/trunk/src/lhadd.c (revision 889)
+++ lha/trunk/src/lhadd.c (revision 890)
@@ -122,6 +122,17 @@
122122 break;
123123 }
124124
125+ if (!sort_contents) {
126+ if (!noexec) {
127+ fseeko(oafp, old_header, SEEK_SET);
128+ copy_old_one(oafp, nafp, &ahdr);
129+ }
130+ else
131+ fseeko(oafp, ahdr.packed_size, SEEK_CUR);
132+ cmp = -1; /* to be -1 always */
133+ continue;
134+ }
135+
125136 cmp = strcmp(ahdr.name, hdr.name);
126137 if (cmp < 0) { /* SKIP */
127138 /* copy old to new */
@@ -166,7 +177,7 @@
166177
167178 if (fp) fclose(fp);
168179
169- if (directory) { /* recursive call */
180+ if (directory && recursive_archiving) { /* recursive call */
170181 if (find_files(name, &filec, &filev)) {
171182 for (i = 0; i < filec; i++)
172183 oafp = append_it(filev[i], oafp, nafp);
@@ -400,7 +411,7 @@
400411 #ifdef S_IFLNK
401412 else if (is_symlink(&stbuf)) {
402413 if (noexec)
403- printf("REMOVE SYMBOLIC LINK %s.\n", name);
414+ message("REMOVE SYMBOLIC LINK %s.", name);
404415 else if (unlink(name) < 0)
405416 warning("Cannot remove", name);
406417 else if (verbose)
--- lha/trunk/src/lharc.c (revision 889)
+++ lha/trunk/src/lharc.c (revision 890)
@@ -106,6 +106,8 @@
106106
107107 extract_broken_archive = FALSE;
108108 decode_macbinary_contents = FALSE;
109+ sort_contents = TRUE;
110+ recursive_archiving = TRUE;
109111 }
110112
111113 /* ------------------------------------------------------------------------ */
@@ -214,6 +216,7 @@
214216 ARCHIVE_KANJI_CODE_OPTION,
215217 TRADITIONAL_BEHAVIOR,
216218 IGNORE_MAC_FILES,
219+ DEBUG_OPTION,
217220 };
218221
219222 struct option long_options[] = {
@@ -227,6 +230,7 @@
227230 {"convert-filename-case", no_argument, &convertcase, TRUE},
228231 {"traditional", no_argument, 0, TRADITIONAL_BEHAVIOR},
229232 {"ignore-mac-files", no_argument, 0, IGNORE_MAC_FILES},
233+ {"debug", required_argument, 0, DEBUG_OPTION},
230234 {0, 0, 0, 0}
231235 };
232236 int i;
@@ -444,6 +448,25 @@
444448 exclude_files[i+3] = 0;
445449 break;
446450
451+ case DEBUG_OPTION:
452+ if (!optarg) {
453+ error("debugging item is not specified for --%s=item",
454+ long_options[option_index].name);
455+ return -1;
456+ }
457+ if (strcmp(optarg, "nosort") == 0) {
458+ sort_contents = FALSE;
459+ }
460+ else if (strcmp(optarg, "norecursion") == 0) {
461+ recursive_archiving = FALSE;
462+ }
463+ else {
464+ error("unknown debugging item \"%s\" for --%s=item",
465+ optarg, long_options[option_index].name);
466+ return -1;
467+ }
468+ break;
469+
447470 default:
448471 error("unknown option `-%c'.", c);
449472 return -1;
@@ -845,7 +868,7 @@
845868 static void
846869 sort_files()
847870 {
848- if (cmd_filec > 1)
871+ if (cmd_filec > 1 && sort_contents)
849872 qsort(cmd_filev, cmd_filec, sizeof(char *), sort_by_ascii);
850873 }
851874
@@ -1139,7 +1162,7 @@
11391162 }
11401163 closedir(dirp);
11411164 finish_sp(&sp, v_filec, v_filev);
1142- if (*v_filec > 1)
1165+ if (*v_filec > 1 && sort_contents)
11431166 qsort(*v_filev, *v_filec, sizeof(char *), sort_by_ascii);
11441167 cleaning_files(v_filec, v_filev);
11451168
--- lha/trunk/src/lhext.c (revision 889)
+++ lha/trunk/src/lhext.c (revision 890)
@@ -600,7 +600,7 @@
600600
601601 static void add_dirinfo(char *name, LzHeader *hdr)
602602 {
603- LzHeaderList *p;
603+ LzHeaderList *p, *tmp, top;
604604
605605 if (memcmp(hdr->method, LZHDIRS_METHOD, 5) != 0)
606606 return;
@@ -611,16 +611,54 @@
611611 strncpy(p->hdr.name, name, sizeof(p->hdr.name));
612612 p->hdr.name[sizeof(p->hdr.name)-1] = 0;
613613
614+#if 0
615+ /* push front */
614616 {
615- LzHeaderList *tmp = dirinfo;
617+ tmp = dirinfo;
616618 dirinfo = p;
617619 dirinfo->next = tmp;
618620 }
621+#else
622+
623+ /*
624+ reverse sorted by pathname order
625+
626+ p->hdr.name = "a"
627+
628+ dirinfo->hdr.name = "a/b/d"
629+ dirinfo->next->hdr.name = "a/b/c"
630+ dirinfo->next->next->hdr.name = "a/b"
631+
632+ result:
633+
634+ dirinfo->hdr.name = "a/b/d"
635+ dirinfo->next->hdr.name = "a/b/c"
636+ dirinfo->next->next->hdr.name = "a/b"
637+ dirinfo->next->next->next->hdr.name = "a"
638+ */
639+
640+ top.next = dirinfo;
641+
642+ for (tmp = &top; tmp->next; tmp = tmp->next) {
643+ if (strcmp(p->hdr.name, tmp->next->hdr.name) > 0) {
644+ p->next = tmp->next;
645+ tmp->next = p;
646+ break;
647+ }
648+ }
649+ if (tmp->next == NULL) {
650+ p->next = NULL;
651+ tmp->next = p;
652+ }
653+
654+ dirinfo = top.next;
655+#endif
619656 }
620657
621658 static void adjust_dirinfo()
622659 {
623660 while (dirinfo) {
661+ /* message("adjusting [%s]", dirinfo->hdr.name); */
624662 adjust_info(dirinfo->hdr.name, &dirinfo->hdr);
625663
626664 {
Show on old repository browser