OSDN Git Service

applied timestamping archive patch
authorKoji Arai <jca02266@gmail.com>
Thu, 21 Aug 2008 03:23:58 +0000 (12:23 +0900)
committerKoji Arai <jca02266@gmail.com>
Sat, 23 Aug 2008 18:55:25 +0000 (03:55 +0900)
src/header.c
src/lha.h
src/lhadd.c
src/lharc.c

index 5b710b9..fc7c1fa 100644 (file)
@@ -611,9 +611,12 @@ get_extended_header(fp, hdr, header_size, hcrc)
             /* set last modified time */
             if (hdr->header_level >= 2)
                 skip_bytes(8);  /* time_t has been already set */
-            else
+            else {
                 hdr->unix_last_modified_stamp = wintime_to_unix_stamp();
-
+                if (file_time_stamp < hdr->unix_last_modified_stamp) {
+                    file_time_stamp = hdr->unix_last_modified_stamp;
+                }
+            }
             skip_bytes(8); /* last access time is ignored */
 
             break;
@@ -668,6 +671,9 @@ get_extended_header(fp, hdr, header_size, hcrc)
 #endif
             /* UNIX last modified time */
             hdr->unix_last_modified_stamp = (time_t) get_longword();
+            if (file_time_stamp < hdr->unix_last_modified_stamp) {
+                file_time_stamp = hdr->unix_last_modified_stamp;
+            }
             break;
         default:
             /* other headers */
@@ -809,6 +815,9 @@ get_header_level0(fp, hdr, data)
     hdr->packed_size = (unsigned long)get_longword();
     hdr->original_size = (unsigned long)get_longword();
     hdr->unix_last_modified_stamp = generic_to_unix_stamp(get_longword());
+    if (file_time_stamp < hdr->unix_last_modified_stamp) {
+        file_time_stamp = hdr->unix_last_modified_stamp;
+    }
     hdr->attribute = get_byte(); /* MS-DOS attribute */
     hdr->header_level = get_byte();
     name_length = get_byte();
@@ -848,6 +857,9 @@ get_header_level0(fp, hdr, data)
         if (extend_size >= 11) {
             hdr->minor_version = get_byte();
             hdr->unix_last_modified_stamp = (time_t) get_longword();
+            if (file_time_stamp < hdr->unix_last_modified_stamp) {
+                file_time_stamp = hdr->unix_last_modified_stamp;
+            }
             hdr->unix_mode = get_word();
             hdr->unix_uid = get_word();
             hdr->unix_gid = get_word();
@@ -925,6 +937,9 @@ get_header_level1(fp, hdr, data)
     hdr->packed_size = (unsigned long)get_longword(); /* skip size */
     hdr->original_size = (unsigned long)get_longword();
     hdr->unix_last_modified_stamp = generic_to_unix_stamp(get_longword());
+    if (file_time_stamp < hdr->unix_last_modified_stamp) {
+        file_time_stamp = hdr->unix_last_modified_stamp;
+    }
     hdr->attribute = get_byte(); /* 0x20 fixed */
     hdr->header_level = get_byte();
 
@@ -1012,6 +1027,9 @@ get_header_level2(fp, hdr, data)
     hdr->packed_size = (unsigned long)get_longword();
     hdr->original_size = (unsigned long)get_longword();
     hdr->unix_last_modified_stamp = get_longword();
+    if (file_time_stamp < hdr->unix_last_modified_stamp) {
+        file_time_stamp = hdr->unix_last_modified_stamp;
+    }
     hdr->attribute = get_byte(); /* reserved */
     hdr->header_level = get_byte();
 
@@ -1092,6 +1110,9 @@ get_header_level3(fp, hdr, data)
     hdr->packed_size = (unsigned long)get_longword();
     hdr->original_size = (unsigned long)get_longword();
     hdr->unix_last_modified_stamp = get_longword();
+    if (file_time_stamp < hdr->unix_last_modified_stamp) {
+        file_time_stamp = hdr->unix_last_modified_stamp;
+    }
     hdr->attribute = get_byte(); /* reserved */
     hdr->header_level = get_byte();
 
@@ -1398,6 +1419,7 @@ init_header(name, v_stat, hdr)
     hdr->crc = 0x0000;
     hdr->extend_type = EXTEND_UNIX;
     hdr->unix_last_modified_stamp = v_stat->st_mtime;
+    if (file_time_stamp < v_stat->st_mtime) { file_time_stamp = v_stat->st_mtime; }
     /* since 00:00:00 JAN.1.1970 */
 #ifdef NOT_COMPATIBLE_MODE
     /* Please need your modification in this space. */
index 5fa157c..2da60e3 100644 (file)
--- a/src/lha.h
+++ b/src/lha.h
@@ -298,6 +298,7 @@ EXTERN boolean  text_mode;
 EXTERN boolean  verbose;
 EXTERN boolean  noexec;     /* debugging option */
 EXTERN boolean  force;
+EXTERN boolean  timestamping;
 EXTERN boolean  delete_after_append;
 EXTERN int      compress_method;
 EXTERN int      header_level;
@@ -365,6 +366,7 @@ EXTERN off_t decode_count;
 EXTERN unsigned long loc;           /* short -> long .. Changed N.Watazaki */
 EXTERN unsigned char *text;         /* encoding buffer */
 EXTERN unsigned char *dtext;        /* decoding buffer */
+EXTERN time_t file_time_stamp;
 
 /* huf.c */
 #ifndef LHA_MAIN_SRC  /* t.okamoto 96/2/20 */
index c9facf0..0620a0e 100644 (file)
@@ -206,6 +206,9 @@ find_update_files(oafp)
         if ((hdr.unix_mode & UNIX_FILE_TYPEMASK) == UNIX_FILE_REGULAR) {
             if (stat(hdr.name, &stbuf) >= 0)    /* exist ? */
                 add_sp(&sp, hdr.name, strlen(hdr.name) + 1);
+            if (file_time_stamp < hdr.unix_last_modified_stamp) {
+                file_time_stamp = hdr.unix_last_modified_stamp;
+            }
         }
         else if ((hdr.unix_mode & UNIX_FILE_TYPEMASK) == UNIX_FILE_DIRECTORY) {
             strcpy(name, hdr.name); /* ok */
@@ -358,6 +361,7 @@ set_archive_file_mode()
 {
     int             umask_value;
     struct stat     stbuf;
+    struct utimbuf  utimebuf;
 
     if (archive_file_gid < 0) {
         umask(umask_value = umask(0));
@@ -369,6 +373,11 @@ set_archive_file_mode()
         chown(new_archive_name, getuid(), archive_file_gid);
 
     chmod(new_archive_name, archive_file_mode);
+
+    if (timestamping) {
+        utimebuf.actime = utimebuf.modtime = file_time_stamp;
+        utime(new_archive_name, &utimebuf);
+    }
 }
 
 /* ------------------------------------------------------------------------ */
index 23b0755..cf9fe61 100644 (file)
@@ -64,11 +64,13 @@ init_variable()     /* Added N.Watazaki */
     verbose         = 0;
     noexec          = FALSE;    /* debugging option */
     force           = FALSE;
+    timestamping    = FALSE;
 
     compress_method = DEFAULT_LZHUFF_METHOD; /* defined in config.h */
 
     header_level    = 2;        /* level 2 */
     quiet_mode      = 0;
+    file_time_stamp = 0;
 
 #ifdef EUC
     euc_mode        = FALSE;
@@ -125,7 +127,7 @@ print_tiny_usage()
     fprintf(stdout, "\
 usage: lha [-]<commands>[<options>] [-<options> ...] archive_file [file...]\n\
   commands:  [axelvudmcpt]\n\
-  options:   [q[012]vnfto[567]dizg012%s%s[w=<dir>|x=<pattern>]]\n\
+  options:   [q[012]vnfto[567]dizg012s%s%s[w=<dir>|x=<pattern>]]\n\
   long options: --system-kanji-code={euc,sjis,utf8,cap}\n\
                 --archive-kanji-code={euc,sjis,utf8,cap}\n\
                 --extract-broken-archive\n\
@@ -197,6 +199,7 @@ commands:                           options:\n\
 ");
 #endif
     fprintf(stdout, "\
+                                     s  time-stamp archive (a)\n\
                                      w=<dir> specify extract directory (x/e)\n\
                                      x=<pattern>  eXclude files (a/u/c)\n\
 ");
@@ -236,7 +239,7 @@ parse_suboption(int argc, char **argv)
     };
     int i;
 
-    char short_options[256] = "q[012]vnfto[567]dizg012ew:x:";
+    char short_options[256] = "q[012]vnfto[567]dizg012esw:x:";
     /* "[...]" means optional 1 byte argument (original extention) */
 
 #if HAVE_LIBAPPLEFILE
@@ -308,6 +311,9 @@ parse_suboption(int argc, char **argv)
             decode_macbinary_contents = TRUE;
             break;
 #endif
+        case 's':
+            timestamping = TRUE;
+            break;
         case 'n':
             noexec = TRUE;
             break;