]> git.pld-linux.org Git - packages/poldek.git/blob - poldek-cookie.patch
- correct patch
[packages/poldek.git] / poldek-cookie.patch
1 diff -urN poldek-0.18.8.org/pkgfl.c poldek-0.18.8/pkgfl.c
2 --- poldek-0.18.8.org/pkgfl.c   2004-12-30 13:05:22.000000000 +0100
3 +++ poldek-0.18.8/pkgfl.c       2005-04-21 22:06:58.126819592 +0200
4 @@ -530,7 +530,7 @@
5      tn_buf *nbuf;
6      tn_buf_it nbufi;
7      uint32_t size;
8 -    char *buf;
9 +    char *buf, dummy;
10      
11      if (fread(&size, sizeof(size), 1, stream) != 1)
12          return NULL;
13 @@ -548,7 +548,7 @@
14      fl = pkgfl_restore(&nbufi, dirs, include);
15      n_buf_free(nbuf);
16      
17 -    fseek(stream, 1, SEEK_CUR); /* skip final '\n' */
18 +    fread(&dummy, 1, 1, stream); /* skip final '\n' */
19  
20      return fl;
21  }
22 @@ -557,12 +557,18 @@
23  int pkgfl_skip_f(FILE *stream) 
24  {
25      uint32_t size;
26 +    char *buf;
27      
28      if (fread(&size, sizeof(size), 1, stream) != 1)
29          return 0;
30      
31      size = ntoh32(size);
32 -    fseek(stream, size + 1, SEEK_CUR);
33 +    buf = malloc(size + 1);
34 +    if (buf)
35 +       fread(buf, 1, size + 1, stream);
36 +    else
37 +       fseek(stream, size + 1, SEEK_CUR);
38 +    free(buf);
39      return 1;
40  }
41  
42 diff -urN poldek-0.18.8.org/pkgu.c poldek-0.18.8/pkgu.c
43 --- poldek-0.18.8.org/pkgu.c    2002-05-15 17:42:48.000000000 +0200
44 +++ poldek-0.18.8/pkgu.c        2005-04-21 22:47:36.188177928 +0200
45 @@ -180,11 +180,36 @@
46      void *rawhdr;
47      Header hdr;
48  
49 -    if (offset > 0)
50 -        if (fseek(stream, offset, SEEK_SET) != 0) {
51 -            logn(LOGERR, "pkguinf_restore: fseek %ld: %m", offset);
52 -            return NULL;
53 -        }
54 +    if (offset > 0) {
55 +       long currseek = ftell(stream);
56 +       char *buf = NULL;
57 +       if (currseek == -1) {
58 +           logn(LOGERR, "pkguinf_restore: ftell %ld: %m", currseek);
59 +           return NULL;
60 +       }
61 +       if (offset >= currseek) {
62 +           currseek = offset - currseek;
63 +           if (currseek) {
64 +               buf = malloc(currseek);
65 +               if (!buf) {
66 +                   logn(LOGERR, "pkguinf_restore: malloc: %m");
67 +                   return NULL;
68 +               }
69 +               if (fread(buf, 1, currseek, stream) != currseek) {
70 +                   logn(LOGERR, "pkguinf_restore: fread error currseek: at %ld %p",
71 +                          ftell(stream), stream);
72 +                   return NULL;
73 +               }
74 +               free(buf);
75 +           }
76 +       } else {
77 +
78 +           if (fseek(stream, offset, SEEK_SET) != 0) {
79 +               logn(LOGERR, "pkguinf_restore: fseek %ld: %m", offset);
80 +               return NULL;
81 +           }
82 +       }
83 +    }
84      
85      if (fread(&nlangs, sizeof(nlangs), 1, stream) != 1) {
86          logn(LOGERR, "pkguinf_restore: read error nlangs (%m) at %ld %p",
87 @@ -239,8 +264,8 @@
88  {
89      uint16_t nsize, nlangs;
90  
91 -    fseek(stream, sizeof(nlangs), SEEK_CUR);
92 -    if (fread(&nsize, sizeof(nsize), 1, stream) != 1) {
93 +    if ((fread(&nlangs, sizeof(nlangs), 1, stream) != 1) ||
94 +       (fread(&nsize, sizeof(nsize), 1, stream) != 1)) {
95          nsize = 0;
96      } else {
97          nsize = ntoh16(nsize);
98 diff -urN poldek-0.18.8.org/trurlib/nstream.c poldek-0.18.8/trurlib/nstream.c
99 --- poldek-0.18.8.org/trurlib/nstream.c 2004-05-06 09:57:45.000000000 +0200
100 +++ poldek-0.18.8/trurlib/nstream.c     2005-04-21 22:04:22.622459848 +0200
101 @@ -57,8 +57,10 @@
102      z_off_t rc, off = *offset;
103      
104      rc = gzseek(stream, off, whence);
105 -    if (rc >= 0)
106 +    if (rc >= 0) {
107 +       *offset = rc;
108          rc = 0;
109 +    }
110  #if ZLIB_TRACE
111      printf("zfseek (%p, %ld, %lld, %d) = %d\n", stream, off, *offset, whence, rc);
112  #endif    
113 @@ -281,7 +283,7 @@
114                      
115                  } else {
116                      st->stream = stream;
117 -                    fseek(st->stream, 0, SEEK_SET); /* glibc BUG (?) */
118 +                    fseek(st->stream, 0, SEEK_SET); /* XXX glibc BUG (?) */
119                      st->type = type;
120                  };
121                  break;
122 diff -urN poldek-0.18.8.org/vfile/vfile.c poldek-0.18.8/vfile/vfile.c
123 --- poldek-0.18.8.org/vfile/vfile.c     2004-02-26 19:22:28.000000000 +0100
124 +++ poldek-0.18.8/vfile/vfile.c 2005-04-21 22:04:22.630458632 +0200
125 @@ -129,8 +129,10 @@
126      z_off_t rc, off = *offset;
127      
128      rc = gzseek(stream, off, whence);
129 -    if (rc >= 0)
130 +    if (rc >= 0) {
131 +       *offset = rc;
132          rc = 0;
133 +    }
134  #if ZLIB_TRACE
135      printf("zfseek (%p, %ld, %lld, %d) = %d\n", stream, off, *offset, whence, rc);
136  #endif    
137 @@ -344,7 +346,16 @@
138                  vf->vf_stream = fopencookie(gzstream, mode, gzio_cookie);
139                  if (vf->vf_stream != NULL) {
140                      rc = 1;
141 -                    fseek(vf->vf_stream, 0, SEEK_SET); /* glibc BUG (?) */
142 +                   vf->vf_buf = malloc(128); /* use small buffer to avoid reverse gzseeks on small forward fseeks */
143 +                   if(vf->vf_buf == NULL)
144 +                       vfile_err_fn("buffer malloc failed for %s\n", CL_URL(path));
145 +                   else
146 +                       if(setvbuf(vf->vf_stream, vf->vf_buf, _IOFBF, 128) != 0) {
147 +                           vfile_err_fn("setvbuf failed for %s\n", CL_URL(path));
148 +                           free(vf->vf_buf);
149 +                           vf->vf_buf = NULL;
150 +                       }
151 +                    fseek(vf->vf_stream, 0, SEEK_SET); /* XXX glibc BUG (?) */
152                  } else
153                      vfile_err_fn("fopencookie %s: hgw error\n", CL_URL(path));
154  
155 @@ -484,6 +495,7 @@
156      vf.vf_type = vftype;
157      vf.vf_mode = vfmode;
158      vf.vf_flags = 0;
159 +    vf.vf_buf = NULL;
160      
161      urltype = vf_url_type(path);
162      opened = 0;
163 @@ -681,6 +693,8 @@
164          free(vf->vf_tmpath);
165          vf->vf_tmpath = NULL;
166      }
167 +    if (vf->vf_buf)
168 +       free(vf->vf_buf);
169      memset(vf, 0, sizeof(*vf));
170      free(vf);
171  }
172 diff -urN poldek-0.18.8.org/vfile/vfile.h poldek-0.18.8/vfile/vfile.h
173 --- poldek-0.18.8.org/vfile/vfile.h     2004-06-08 15:57:03.000000000 +0200
174 +++ poldek-0.18.8/vfile/vfile.h 2005-04-21 22:04:22.634458024 +0200
175 @@ -81,6 +81,7 @@
176  
177      char          *vf_path;
178      char          *vf_tmpath;
179 +    char          *vf_buf;
180      int16_t       _refcnt;
181  };
182  
This page took 0.087027 seconds and 3 git commands to generate.