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