Blob Blame History Raw
diff --git a/fileio.c b/fileio.c
index 5a47b0a..a2fd008 100644
--- a/fileio.c
+++ b/fileio.c
@@ -957,6 +957,22 @@ int seek_zipf(__G__ abs_offset)
   zoff_t bufstart;
 
   request = abs_offset + G.extra_bytes;
+  int sgmnt_movement = G.ecrec.number_this_disk - G.sgmnt_nr - 1;
+  /* If request < 0, then we will move between segment files if
+   * archive is segmented and in that case we need start always
+   * from last file. So set right movement against actual segment.
+   * !! Do not set G.sgmnt_ns variable directly !! Now it could be done
+   * safely if request < 0 and it's more effective solution for loop,
+   * however it's not clean and it can be source of troubles in future,
+   * when code will be modified again.
+   * if(request < 0)
+   *   G.sgmnt_nr = G.ecrec.number_this_disk;
+   * .....
+   * .. in loop ..
+   * if ((G.sgmnt_nr == 0) || open_infile_sgmnt( __G__ -1))
+   * ....
+   * */
+
 
 #if 0 /* Pre-segment-support. */
   if (request < 0)
@@ -969,50 +985,26 @@ int seek_zipf(__G__ abs_offset)
 
   while (request < 0)
   {
-    if (G.sgmnt_size == 0)
+    if ((G.sgmnt_nr == 0) || open_infile_sgmnt( __G__ sgmnt_movement))
     {
-      if ((G.sgmnt_nr == 0) || open_infile_sgmnt( __G__ -1))
-      {
-        Info(slide, 1, ((char *)slide, LoadFarStringSmall(SeekMsg),
-         G.zipfn, 12, LoadFarString(ReportMsg)));
-        return PK_BADERR;
-      }
-      /* Get the new segment size, and calculate the new offset.
-       * This is where G.sgmnt_size gets a real (non-zero) value.
-       */
+      Info(slide, 1, ((char *)slide, LoadFarStringSmall(SeekMsg),
+       G.zipfn, 12, LoadFarString(ReportMsg)));
+      return PK_BADERR;
+    }
 #ifdef USE_STRM_INPUT
-      zfseeko(G.zipfd, 0, SEEK_END);
-      G.sgmnt_size = zftello(G.zipfd);
+    zfseeko(G.zipfd, 0, SEEK_END);
+    request += zftello(G.zipfd);
 #else /* !USE_STRM_INPUT */
-      G.sgmnt_size = zlseek(G.zipfd, 0, SEEK_END);
+    request += zlseek(G.zipfd, 0, SEEK_END);
 #endif /* USE_STRM_INPUT */
-      request += G.sgmnt_size;
-    }
-    else
-    {
-      /* SMSd.  Can we trust that all segments have the same size? */
-      /* We know segment size(s?), so we can calculate against
-       * abs_offset and sgmnt_nr, and open the segment file which we
-       * actually need.
-       */
-      unsigned int tmp_disk = G.ecrec.number_this_disk;
+    /* now it should be always -1
+     * Not all segmented files have same size! So we must go file by file
+     * and work with real sizes.
+     */
+    sgmnt_movement = -1;
 
-      while (request < 0)
-      {
-        tmp_disk--;
-        request += G.sgmnt_size;
-      }
-      /* for same as actual disk (movement == 0) return 0  */
-      if (open_infile_sgmnt( __G__ (tmp_disk- G.sgmnt_nr)))
-      {
-          Info(slide, 1, ((char *)slide, LoadFarStringSmall(SeekMsg),
-           G.zipfn, 13, LoadFarString(ReportMsg)));
-          return PK_BADERR;
-      }
-    }
-    /* In both cases we need to refill buffer, so set
-     * G.cur_zipfile_bufstart negative (so that bufstart !=
-     * G.cur_zipfile_bufstart, below).
+    /* We need to refill buffer, so set G.cur_zipfile_bufstart to negative
+     * value (so that bufstart != G.cur_zipfile_bufstart, below).
      */
     G.cur_zipfile_bufstart = -1;
   }
diff --git a/globals.h b/globals.h
index 0a84432..efa3d52 100644
--- a/globals.h
+++ b/globals.h
@@ -247,7 +247,6 @@ typedef struct Globals {
     char      *zipfn_sgmnt;         /* zipfile segment path/name */
     int       zipfn_sgmnt_size;     /* zipfile segment path/name size */
     zuvl_t    sgmnt_nr;             /* zipfile segment number */
-    zoff_t    sgmnt_size;           /* zipfile segment size */
     zipfd_t   zipfd;                /* zipfile primary file descr/pointer */
     zipfd_t   zipfd_sgmnt;          /* zipfile segment file descr/pointer */
     zoff_t    ziplen;
diff --git a/process.c b/process.c
index 76652a9..218d09d 100644
--- a/process.c
+++ b/process.c
@@ -757,7 +757,6 @@ static int do_seekable(__G__ lastchance)        /* return PK-type error code */
 
     G.cur_zipfile_bufstart = 0;
     G.inptr = G.inbuf;
-    G.sgmnt_size = 0;   /* Init before ECREC for each archive in the list. */
 
 #if ((!defined(WINDLL) && !defined(SFX)) || !defined(NO_ZIPINFO))
 # if (!defined(WINDLL) && !defined(SFX))
@@ -819,8 +818,6 @@ static int do_seekable(__G__ lastchance)        /* return PK-type error code */
 #ifdef NO_MULTIPART
     error = !uO.zipinfo_mode && (G.ecrec.number_this_disk == 1) &&
             (G.ecrec.num_disk_start_cdir == 1);
-#else
-    error = !uO.zipinfo_mode && (G.ecrec.number_this_disk != 0);
 #endif
 
 #ifndef SFX
@@ -858,7 +855,7 @@ static int do_seekable(__G__ lastchance)        /* return PK-type error code */
         }
 #endif /* !SFX */
         if ((G.extra_bytes = G.real_ecrec_offset-G.expect_ecrec_offset) <
-            (zoff_t)0)
+            (zoff_t)0 && G.ecrec.number_this_disk == 0)
         {
             Info(slide, 0x401, ((char *)slide, LoadFarString(MissingBytes),
               G.zipfn, FmZofft((-G.extra_bytes), NULL, NULL)));