OSDN Git Service

remade the timestamping archive patch
authorKoji Arai <jca02266@gmail.com>
Wed, 27 Aug 2008 15:51:32 +0000 (00:51 +0900)
committerKoji Arai <jca02266@gmail.com>
Wed, 27 Aug 2008 15:51:32 +0000 (00:51 +0900)
src/header.c
src/lha.h
src/lhadd.c
src/lharc.c
src/prototypes.h

index fc7c1fa..5b710b9 100644 (file)
@@ -611,12 +611,9 @@ 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;
@@ -671,9 +668,6 @@ 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 */
@@ -815,9 +809,6 @@ 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();
@@ -857,9 +848,6 @@ 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();
@@ -937,9 +925,6 @@ 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();
 
@@ -1027,9 +1012,6 @@ 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();
 
@@ -1110,9 +1092,6 @@ 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();
 
@@ -1419,7 +1398,6 @@ 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 2da60e3..2aaeb74 100644 (file)
--- a/src/lha.h
+++ b/src/lha.h
@@ -298,7 +298,7 @@ EXTERN boolean  text_mode;
 EXTERN boolean  verbose;
 EXTERN boolean  noexec;     /* debugging option */
 EXTERN boolean  force;
-EXTERN boolean  timestamping;
+EXTERN boolean  timestamp_archive;
 EXTERN boolean  delete_after_append;
 EXTERN int      compress_method;
 EXTERN int      header_level;
@@ -366,7 +366,6 @@ 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 0620a0e..6ee90e1 100644 (file)
@@ -13,7 +13,29 @@ static void     remove_files();
 
 static char     new_archive_name_buffer[FILENAME_LENGTH];
 static char    *new_archive_name;
-/* ------------------------------------------------------------------------ */
+static time_t most_recent;      /* for time-stamp archiving */
+
+static void
+copy_old_one(oafp, nafp, hdr)
+    FILE           *oafp, *nafp;
+    LzHeader       *hdr;
+{
+    if (noexec) {
+        fseeko(oafp, hdr->header_size + hdr->packed_size, SEEK_CUR);
+    }
+    else {
+        reading_filename = archive_name;
+        writing_filename = temporary_name;
+        copyfile(oafp, nafp, hdr->header_size + hdr->packed_size, 0, 0);
+
+        if (!((hdr->unix_mode & UNIX_FILE_SYMLINK) == UNIX_FILE_SYMLINK ||
+              (hdr->unix_mode & UNIX_FILE_DIRECTORY) == UNIX_FILE_DIRECTORY)) {
+            if (most_recent < hdr->unix_last_modified_stamp)
+                most_recent = hdr->unix_last_modified_stamp;
+        }
+    }
+}
+
 static void
 add_one(fp, nafp, hdr)
     FILE           *fp, *nafp;
@@ -25,6 +47,12 @@ add_one(fp, nafp, hdr)
     reading_filename = hdr->name;
     writing_filename = temporary_name;
 
+    if (!((hdr->unix_mode & UNIX_FILE_SYMLINK) == UNIX_FILE_SYMLINK ||
+          (hdr->unix_mode & UNIX_FILE_DIRECTORY) == UNIX_FILE_DIRECTORY)) {
+        if (most_recent < hdr->unix_last_modified_stamp)
+            most_recent = hdr->unix_last_modified_stamp;
+    }
+
     if (!fp && generic_format)  /* [generic] doesn't need directory info. */
         return;
     header_pos = ftello(nafp);
@@ -206,9 +234,6 @@ 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 */
@@ -361,7 +386,6 @@ set_archive_file_mode()
 {
     int             umask_value;
     struct stat     stbuf;
-    struct utimbuf  utimebuf;
 
     if (archive_file_gid < 0) {
         umask(umask_value = umask(0));
@@ -374,8 +398,9 @@ set_archive_file_mode()
 
     chmod(new_archive_name, archive_file_mode);
 
-    if (timestamping) {
-        utimebuf.actime = utimebuf.modtime = file_time_stamp;
+    if (timestamp_archive && most_recent) {
+        struct utimbuf  utimebuf;
+        utimebuf.actime = utimebuf.modtime = most_recent;
         utime(new_archive_name, &utimebuf);
     }
 }
@@ -534,6 +559,7 @@ cmd_add()
                 goto next;
         }
 
+        most_recent = 0;
         oafp = append_it(cmd_filev[i], oafp, nafp);
     next:
         ;
@@ -582,10 +608,10 @@ cmd_add()
 
             temporary_to_new_archive_file(new_archive_size);
         }
-    }
 
-    /* set new archive file mode/group */
-    set_archive_file_mode();
+        /* set new archive file mode/group */
+        set_archive_file_mode();
+    }
 
     /* remove archived files */
     if (delete_after_append)
@@ -601,6 +627,8 @@ cmd_delete()
     FILE *oafp, *nafp;
     off_t new_archive_size;
 
+    most_recent = 0;
+
     /* open old archive if exist */
     if ((oafp = open_old_archive()) == NULL)
         fatal_error("Cannot open archive file \"%s\"", archive_name);
@@ -667,10 +695,10 @@ cmd_delete()
     if (!noexec) {
         if (rename(temporary_name, new_archive_name) < 0)
             temporary_to_new_archive_file(new_archive_size);
-    }
 
-    /* set new archive file mode/group */
-    set_archive_file_mode();
+        /* set new archive file mode/group */
+        set_archive_file_mode();
+    }
 
     return;
 }
index cf9fe61..ffac66a 100644 (file)
@@ -64,13 +64,12 @@ init_variable()     /* Added N.Watazaki */
     verbose         = 0;
     noexec          = FALSE;    /* debugging option */
     force           = FALSE;
-    timestamping    = FALSE;
+    timestamp_archive = 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;
@@ -127,12 +126,13 @@ print_tiny_usage()
     fprintf(stdout, "\
 usage: lha [-]<commands>[<options>] [-<options> ...] archive_file [file...]\n\
   commands:  [axelvudmcpt]\n\
-  options:   [q[012]vnfto[567]dizg012s%s%s[w=<dir>|x=<pattern>]]\n\
+  options:   [q[012]vnfto[567]dizg012%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\
                 --convert-filename-case\n\
-               --ignore-mac-files\n\
+                --ignore-mac-files\n\
+                --timestamp-archive\n\
                 --traditional\n\
                 --help\n\
                 --version\n"
@@ -199,7 +199,6 @@ 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\
 ");
@@ -234,12 +233,13 @@ parse_suboption(int argc, char **argv)
         {"convert-filename-case", no_argument, &convertcase, TRUE},
         {"traditional", no_argument, 0, TRADITIONAL_BEHAVIOR},
         {"ignore-mac-files", no_argument, 0, IGNORE_MAC_FILES},
+        {"timestamp-archive", no_argument, &timestamp_archive, 1},
         {"debug", required_argument, 0, DEBUG_OPTION},
         {0, 0, 0, 0}
     };
     int i;
 
-    char short_options[256] = "q[012]vnfto[567]dizg012esw:x:";
+    char short_options[256] = "q[012]vnfto[567]dizg012ew:x:";
     /* "[...]" means optional 1 byte argument (original extention) */
 
 #if HAVE_LIBAPPLEFILE
@@ -311,9 +311,6 @@ parse_suboption(int argc, char **argv)
             decode_macbinary_contents = TRUE;
             break;
 #endif
-        case 's':
-            timestamping = TRUE;
-            break;
         case 'n':
             noexec = TRUE;
             break;
@@ -1454,21 +1451,6 @@ write_archive_tail(nafp)
 }
 
 /* ------------------------------------------------------------------------ */
-void
-copy_old_one(oafp, nafp, hdr)
-    FILE           *oafp, *nafp;
-    LzHeader       *hdr;
-{
-    if (noexec) {
-        fseeko(oafp, hdr->header_size + hdr->packed_size, SEEK_CUR);
-    }
-    else {
-        reading_filename = archive_name;
-        writing_filename = temporary_name;
-        copyfile(oafp, nafp, hdr->header_size + hdr->packed_size, 0, 0);
-    }
-}
-
 #undef exit
 
 void
index 8297f7b..3cebc7e 100644 (file)
@@ -95,7 +95,6 @@ FILE *xfopen P_((char *name, char *mode));
 FILE *open_old_archive P_((void));
 int inquire P_((char *msg, char *name, char *selective));
 void write_archive_tail P_((FILE *nafp));
-void copy_old_one P_((FILE *oafp, FILE *nafp, LzHeader *hdr));
 void lha_exit P_((int status));
 /* lhext.c */
 void cmd_extract P_((void));