* updated ktuberling (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / archiver / mine / any-archiver.patch
blob777c669731b8e711d25c8e48c521691e13a3a441
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../mine/any-archiver.patch
5 # Copyright (C) 2004 - 2016 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 This fixes a few bugs like crashing on non-existing file and reading the
18 package database before checking for the file.
20 Implements using any compressed tar package as archiver and not use the
21 bzip2 copy but the systen compressors.
23 (This is just a quick gap filler until we get rid of the whole mine mess.)
25 - Rene Rebe <rene@exactcode.de>
27 Index: install.c
28 ===================================================================
29 --- ./install.c (revision 3)
30 +++ ./install.c (revision 13)
31 @@ -1,6 +1,7 @@
33 * GEM MINE - The ROCK Linux Package Manager
34 * Copyright (C) 2002-2005 Clifford Wolf
35 + * Copyright (C) 2005-2010 René Rebe
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 @@ -29,7 +30,6 @@
40 #include <fnmatch.h>
42 #include "cdb.h"
43 -#include "bzlib.h"
44 #include "libtar.h"
46 #include "mine.h"
47 @@ -60,70 +60,117 @@
48 int pos, len;
49 int rc;
51 - char *filename;
52 + char *filename = 0;
53 + char *decompressor = 0;
54 char buffer[1024];
55 char buffer2[1024];
56 char buffer3[1024];
57 TAR *t = NULL;
58 - BZFILE *b = NULL;
60 - if ( ! mode_force )
61 - md5sum_initdb(root, mode_verbose);
62 + errno = 0;
64 - if ( (gem_fd = open(package, O_RDONLY)) < 0 ) goto error_errno;
65 - cdb_init(&c, gem_fd);
66 + decompressor = strstr (package, ".tar");
67 + if (decompressor) {
68 + /* strip .tar. */
69 + decompressor += 4;
70 + /* some substitution, other, e.g. lzma are used as it */
71 + if (!*decompressor)
72 + decompressor = "cat";
73 + else if (strcmp (decompressor, ".bz2") == 0)
74 + decompressor = "bzip2";
75 + else if (strcmp (decompressor, ".gz") == 0)
76 + decompressor = "gzip";
77 + else if (strcmp (decompressor, ".lzo") == 0)
78 + decompressor = "lzop";
79 + else if (strcmp (decompressor, ".lzma") == 0)
80 + decompressor = "lzma";
81 + else if (strcmp (decompressor, ".xz") == 0)
82 + decompressor = "xz";
83 + else if (strcmp (decompressor, ".zst") == 0)
84 + decompressor = "zstd";
85 + else
86 + ++decompressor; /* skip over leading dot (.) */
87 + }
89 - rc = cdb_find(&c, "pkg_name", 8);
90 - if ( rc <= 0 ) goto error;
91 - pos = cdb_datapos(&c); len = cdb_datalen(&c);
92 - pname = malloc(len+1); pname[len] = 0;
93 - if (cdb_read(&c, pname, len, pos) == -1) goto error;
95 pipe(gem2bunzip);
96 - pipe(bunzip2tar);
98 - /*
99 - * Extract tar.bz2 from GEM file
100 - */
101 - if (!fork()) {
102 - close(gem2bunzip[0]);
103 - close(bunzip2tar[0]);
104 - close(bunzip2tar[1]);
105 + if (!decompressor) {
106 + decompressor = "bzip2"; /* let the generic code decompress it */
108 - rc = cdb_find(&c, "pkg_tarbz2", 10);
109 - if ( rc <= 0 ) exit(1);
110 + if ( (gem_fd = open(package, O_RDONLY)) < 0 ) goto error_errno;
111 + cdb_init(&c, gem_fd);
113 - pos = cdb_datapos(&c);
114 - len = cdb_datalen(&c);
115 - if (len <= 0) exit(1);
116 + rc = cdb_find(&c, "pkg_name", 8);
117 + if ( rc <= 0 ) goto error;
118 + pos = cdb_datapos(&c); len = cdb_datalen(&c);
119 + pname = malloc(len+1); pname[len] = 0;
120 + if (cdb_read(&c, pname, len, pos) == -1) goto error;
122 - while (len > 0) {
123 - if ( cdb_read(&c, buffer, len>512 ? 512 : len,
124 - pos) == -1 ) goto error;
125 - write(gem2bunzip[1], buffer, len > 512 ? 512 : len);
126 - pos += len > 512 ? 512 : len;
127 - len -= 512;
128 + /*
129 + * Extract tar.bz2 from GEM file
130 + */
131 + if (!fork()) {
132 + close(gem2bunzip[0]);
134 + rc = cdb_find(&c, "pkg_tarbz2", 10);
135 + if ( rc <= 0 ) exit(1);
137 + pos = cdb_datapos(&c);
138 + len = cdb_datalen(&c);
139 + if (len <= 0) exit(1);
141 + while (len > 0) {
142 + if ( cdb_read(&c, buffer, len>512 ? 512 : len,
143 + pos) == -1 ) goto error;
144 + write(gem2bunzip[1], buffer, len > 512 ? 512 : len);
145 + pos += len > 512 ? 512 : len;
146 + len -= 512;
149 + cdb_free(&c);
150 + close(gem_fd);
152 + exit(0);
155 + else /* vanilla tar flavour */
157 + if (!fork()) {
158 + close(gem2bunzip[0]);
160 - cdb_free(&c);
161 - close(gem_fd);
162 + int fd = open (package, O_RDONLY);
163 + if (fd < 0) goto error_errno;
164 + int len;
165 + do {
166 + len = read(fd, buffer, sizeof(buffer));
167 + if (len < 0) goto error;
168 + write(gem2bunzip[1], buffer, len);
170 - exit(0);
171 + } while (len > 0);
173 + close(fd);
174 + exit(0);
178 + pipe(bunzip2tar);
181 - * Bunzip tar.bz2 file
182 + * decompress
184 if (!fork()) {
185 close(gem2bunzip[1]);
186 close(bunzip2tar[0]);
188 - b = BZ2_bzdopen(gem2bunzip[0], "r");
189 - while ( (rc=BZ2_bzread(b, buffer, 512)) > 0 )
190 - write(bunzip2tar[1], buffer, rc);
191 - BZ2_bzclose(b);
193 - exit(0);
194 + dup2 (gem2bunzip[0], 0);
195 + dup2 (bunzip2tar[1], 1);
196 + close (gem2bunzip[0]);
197 + close (bunzip2tar[1]);
198 + if (strcmp (decompressor, "cat") == 0)
199 + execlp (decompressor, decompressor, NULL);
200 + else
201 + execlp (decompressor, decompressor, "-d", "-c", NULL);
202 + goto error_errno;
206 @@ -133,6 +177,9 @@
207 close(gem2bunzip[1]);
208 close(bunzip2tar[1]);
210 + if ( ! mode_force )
211 + md5sum_initdb(root, mode_verbose);
213 if (tar_fdopen(&t, bunzip2tar[0], "pipe", NULL,
214 O_RDONLY, 0, 0) == -1) goto error_errno;
215 if ( mode_test && mode_verbose ) printf("-- %s --\n", pname);
216 @@ -225,7 +272,9 @@
218 error_errno:
219 fprintf(stderr, "While installing GEM file %s%s%s%s: %s\n", package,
220 - filename?" (":"", filename?filename:"", filename?"(":"",
221 + filename ? " (" : "",
222 + filename ? filename : "",
223 + filename ? ")" : "",
224 errno ? strerror(errno) : "Unknown error");
225 if ( t != NULL) tar_close(t);
226 if ( gem_fd != -1 ) { cdb_free(&c); close(gem_fd); }
227 Index: Makefile
228 ===================================================================
229 --- ./Makefile (revision 3)
230 +++ ./Makefile (revision 13)
231 @@ -6,12 +6,6 @@
232 CDB_OBJ = $(CDB_DIR)/cdb.a $(CDB_DIR)/alloc.a $(CDB_DIR)/buffer.a
233 CDB_OBJ += $(CDB_DIR)/byte.a $(CDB_DIR)/unix.a
235 -# LibBzip2 Sub-Package
237 -BZIP2_VER = 1.0.2
238 -BZIP2_DIR = bzip2-$(BZIP2_VER)
239 -BZIP2_OBJ = $(BZIP2_DIR)/libbz2.a
241 # LibTar Sub-Package
243 LIBTAR_VER = 1.2.11
244 @@ -43,11 +37,11 @@
246 # The usual list of build targets
248 -MINE_ALL_OBJS = $(MINE_OBJ) $(CDB_OBJ) $(BZIP2_OBJ) $(LIBTAR_OBJ)
249 +MINE_ALL_OBJS = $(MINE_OBJ) $(CDB_OBJ) $(LIBTAR_OBJ)
251 # Set and configure the c-compiler
253 -CFLAGS = -I$(CDB_DIR) -I$(BZIP2_DIR) -I$(LIBTAR_DIR)/lib -I. -Wall -Os
254 +CFLAGS = -I$(CDB_DIR) -I/usr/include -I$(LIBTAR_DIR)/lib -I. -Wall -Os
255 CFLAGS += -I$(LIBTAR_DIR)/listhash -DMINE_VERSION=\"$(MINE_VER)\" -ggdb
256 CFLAGS += -DGEMCACHE=\"/var/cache/gem\" -DMINECURLOPT=\"/etc/mine.curlopt\"
257 ifeq ($(USE_AVL), 1)
258 @@ -86,7 +80,7 @@
259 $(CC) $(MINE_ALL_OBJS) -o mine
261 mine.static:
262 - $(CC) $(MINE_ALL_OBJS) -static -o mine.static
263 + $(CC) -static $(MINE_ALL_OBJS) $(MINE_ALL_LIBS) -o mine.static
265 gasgui: $(GAS_OBJ)
266 $(CC) $(GAS_OBJ) -ldialog -lcurses -lm -o gasgui
267 @@ -100,22 +94,18 @@
268 endif
269 [ -f $(sysprefix)/etc/rocket.conf ] || cp rocket.conf $(sysprefix)/etc/
271 -$(MINE_OBJ): $(CDB_OBJ) $(BZIP2_OBJ) $(LIBTAR_OBJ)
272 +$(MINE_OBJ): $(CDB_OBJ) $(LIBTAR_OBJ)
274 $(CDB_OBJ):
275 $(BUILDCC) -o $(CDB_DIR)/auto-str $(CDB_DIR)/auto-str.c
276 $(MAKE) 'AR=$(AR)' 'RANLIB=$(RANLIB)' -C $(CDB_DIR)
278 -$(BZIP2_OBJ):
279 - $(MAKE) -C $(BZIP2_DIR) libbz2.a
281 $(LIBTAR_OBJ):
282 cd $(LIBTAR_DIR) && ./configure --without-zlib $(CONFOPT)
283 $(MAKE) -C $(LIBTAR_DIR)
285 patchfiles:
286 sh xdiff.sh $(CDB_DIR)/ > $(CDB_DIR).patch
287 -# sh xdiff.sh (BZIP2_DIR)/ > $(BZIP2_DIR).patch
288 sh xdiff.sh $(LIBTAR_DIR)/ > $(LIBTAR_DIR).patch
290 clean:
291 @@ -124,7 +114,6 @@
292 grep -qx "$${x#$(CDB_DIR)/}" $(CDB_DIR)/FILES || rm -v $$x ; \
293 done
294 @rm -vf *.o mine mine.static gasgui core
295 - -@make -C $(BZIP2_DIR) distclean
296 -@make -C $(LIBTAR_DIR) distclean
297 echo "GEM MINE $(MINE_VER)" > VERSION
299 --- ./readdb.c 2005-03-23 09:51:06.000000000 +0100
300 +++ ./readdb.c 2006-06-05 14:55:33.817538500 +0200
301 @@ -1,6 +1,7 @@
303 * GEM MINE - The ROCK Linux Package Manager
304 * Copyright (C) 2002-2005 Clifford Wolf
305 + * Copyright (C) 2006 René Rebe
307 * This program is free software; you can redistribute it and/or modify
308 * it under the terms of the GNU General Public License as published by
309 @@ -215,11 +216,12 @@
311 if ( !dbf ) fclose(f);
313 - snprintf(line, 1024, "%s/pkgs/%s-%s.gem", config, p->name, p->version);
314 + /* without extension, it is cut off above */
315 + snprintf(line, 1024, "%s/pkgs/%s-%s", config, p->name, p->version);
316 if ( memdb_get(&files_on_disks, line) ) {
317 p->disk_number = atoi(memdb_search_result);
318 } else {
319 - snprintf(line, 1024, "%s/pkgs/%s.gem", config, p->name);
320 + snprintf(line, 1024, "%s/pkgs/%s", config, p->name);
321 if ( memdb_get(&files_on_disks, line) )
322 p->disk_number = atoi(memdb_search_result);
324 @@ -420,7 +423,12 @@
325 snprintf(pkgdir, 200, "%s/pkgs/", config);
327 while ( fgets(line, 160, f) != NULL ) {
328 + char* s;
329 sscanf(line, "disk%s %s", disk, filename);
330 + /* cut the extension */
331 + s = strstr (filename, ".tar.");
332 + if ( !s ) s = strstr (filename, ".gem");
333 + if ( s ) *s = 0;
334 if ( !strncmp(filename, pkgdir, strlen(pkgdir)) )
335 memdb_put(&files_on_disks, filename, disk);
336 if ( atoi(disk) > max_disk_number )