pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/pkgtools/rpm2pkg



Module Name:    pkgsrc
Committed By:   rin
Date:           Sat Nov 30 23:31:30 UTC 2019

Modified Files:
        pkgsrc/pkgtools/rpm2pkg: Makefile
        pkgsrc/pkgtools/rpm2pkg/files: Makefile fileio.h parse-rpm.c
Added Files:
        pkgsrc/pkgtools/rpm2pkg/files: fileio-zstd.c

Log Message:
Support RPMs compressed by Zstd, found in Fedora 31.
Bump version.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 pkgsrc/pkgtools/rpm2pkg/Makefile
cvs rdiff -u -r1.4 -r1.5 pkgsrc/pkgtools/rpm2pkg/files/Makefile
cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/rpm2pkg/files/fileio-zstd.c
cvs rdiff -u -r1.1 -r1.2 pkgsrc/pkgtools/rpm2pkg/files/fileio.h \
    pkgsrc/pkgtools/rpm2pkg/files/parse-rpm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/rpm2pkg/Makefile
diff -u pkgsrc/pkgtools/rpm2pkg/Makefile:1.69 pkgsrc/pkgtools/rpm2pkg/Makefile:1.70
--- pkgsrc/pkgtools/rpm2pkg/Makefile:1.69       Mon Oct 29 14:41:56 2018
+++ pkgsrc/pkgtools/rpm2pkg/Makefile    Sat Nov 30 23:31:30 2019
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.69 2018/10/29 14:41:56 abs Exp $
+# $NetBSD: Makefile,v 1.70 2019/11/30 23:31:30 rin Exp $
 
-PKGNAME=       rpm2pkg-3.2.3
+PKGNAME=       rpm2pkg-3.3.0
 CATEGORIES=    pkgtools
 NO_CHECKSUM=   yes
 
@@ -45,5 +45,6 @@ do-install:
 
 .include "../../archivers/bzip2/buildlink3.mk"
 .include "../../archivers/xz/buildlink3.mk"
+.include "../../archivers/zstd/buildlink3.mk"
 .include "../../devel/zlib/buildlink3.mk"
 .include "../../mk/bsd.pkg.mk"

Index: pkgsrc/pkgtools/rpm2pkg/files/Makefile
diff -u pkgsrc/pkgtools/rpm2pkg/files/Makefile:1.4 pkgsrc/pkgtools/rpm2pkg/files/Makefile:1.5
--- pkgsrc/pkgtools/rpm2pkg/files/Makefile:1.4  Tue Apr 12 22:36:11 2011
+++ pkgsrc/pkgtools/rpm2pkg/files/Makefile      Sat Nov 30 23:31:30 2019
@@ -1,12 +1,14 @@
-#      $NetBSD: Makefile,v 1.4 2011/04/12 22:36:11 tron Exp $
+#      $NetBSD: Makefile,v 1.5 2019/11/30 23:31:30 rin Exp $
 
 PROG=          rpm2pkg
 SRCS=          fileio.c package-list.c parse-rpm.c rpm2pkg.c
 SRCS+=         fileio-bzlib.c fileio-lzma.c fileio-plain.c fileio-zlib.c
+SRCS+=         fileio-zstd.c
 MAN=
 
 BINDIR=                ${PREFIX}/sbin
 LDADD=         -lbz2 -llzma -lz
+LDADD+=                -lzstd
 #WARNS=                4
 
 #CFLAGS+=      -g

Index: pkgsrc/pkgtools/rpm2pkg/files/fileio.h
diff -u pkgsrc/pkgtools/rpm2pkg/files/fileio.h:1.1 pkgsrc/pkgtools/rpm2pkg/files/fileio.h:1.2
--- pkgsrc/pkgtools/rpm2pkg/files/fileio.h:1.1  Wed Jan 12 00:26:33 2011
+++ pkgsrc/pkgtools/rpm2pkg/files/fileio.h      Sat Nov 30 23:31:30 2019
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * Copyright (c) 2011, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -43,6 +43,7 @@ extern FileHandle *FileHandleBZLib(int *
 extern FileHandle *FileHandleLZMA(int *);
 extern FileHandle *FileHandlePlain(int *);
 extern FileHandle *FileHandleZLib(int *);
+extern FileHandle *FileHandleZstd(int *);
 
 #ifdef FILEIO_INTERNAL
 
Index: pkgsrc/pkgtools/rpm2pkg/files/parse-rpm.c
diff -u pkgsrc/pkgtools/rpm2pkg/files/parse-rpm.c:1.1 pkgsrc/pkgtools/rpm2pkg/files/parse-rpm.c:1.2
--- pkgsrc/pkgtools/rpm2pkg/files/parse-rpm.c:1.1       Wed Jan 12 00:26:33 2011
+++ pkgsrc/pkgtools/rpm2pkg/files/parse-rpm.c   Sat Nov 30 23:31:30 2019
@@ -1,7 +1,7 @@
-/*     $NetBSD: parse-rpm.c,v 1.1 2011/01/12 00:26:33 tron Exp $       */
+/*     $NetBSD: parse-rpm.c,v 1.2 2019/11/30 23:31:30 rin Exp $        */
 
 /*-
- * Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
+ * Copyright (c) 2001-2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -69,9 +69,10 @@ typedef struct RPMHeader_s {
 
 static const uint8_t RPMHeaderMagic[] = { 0x8e, 0xad, 0xe8 };
 
-/* Magic bytes for "bzip2" and "gzip" compressed files. */
+/* Magic bytes for "bzip2", "gzip", and "zstd" compressed files. */
 static const unsigned char BZipMagic[] = { 'B', 'Z', 'h' };
 static const unsigned char GZipMagic[] = { 0x1f, 0x8b, 0x08 };
+static const unsigned char ZstdMagic[] = { 0x28, 0xb5, 0x2f, 0xfd };
 
 /* Magic bytes for a cpio(1) archive. */
 static const unsigned char CPIOMagic[] = {'0','7','0','7','0','1'};
@@ -156,6 +157,9 @@ OpenRPM(int *fd_p)
        } else if (memcmp(buffer, GZipMagic, sizeof(GZipMagic)) == 0) {
                /* gzip archive */
                fh = FileHandleZLib(fd_p);
+       } else if (memcmp(buffer, ZstdMagic, sizeof(ZstdMagic)) == 0) {
+               /* zstd archive */
+               fh = FileHandleZstd(fd_p);
        } else {
                /* lzma ... hopefully */
                fh = FileHandleLZMA(fd_p);

Added files:

Index: pkgsrc/pkgtools/rpm2pkg/files/fileio-zstd.c
diff -u /dev/null pkgsrc/pkgtools/rpm2pkg/files/fileio-zstd.c:1.1
--- /dev/null   Sat Nov 30 23:31:30 2019
+++ pkgsrc/pkgtools/rpm2pkg/files/fileio-zstd.c Sat Nov 30 23:31:30 2019
@@ -0,0 +1,120 @@
+/*-
+ * Copyright (c) 2011, 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matthias Scheler and Rin Okuyama.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define        FILEIO_INTERNAL /**/
+
+#include "fileio.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <zstd.h>
+
+typedef struct {
+       FILE            *id_File;
+       ZSTD_DStream    *id_Stream;
+       ZSTD_inBuffer   id_zib;
+       void            *id_Buf;
+       size_t          id_BufSize;
+} InstData;
+
+static void
+ZstdCloseFunc(FileHandle *fh)
+{
+       InstData *id;
+
+       id = fh->fh_InstData;
+
+       if (id->id_Buf != NULL)
+               free(id->id_Buf);
+
+       if (id->id_Stream != NULL)
+               (void)ZSTD_freeDStream(id->id_Stream);
+
+       if (id->id_File != NULL)
+               (void)fclose(id->id_File);
+}
+
+static ssize_t
+ZstdReadFunc(FileHandle *fh, void *buffer, size_t bytes)
+{
+       InstData *id;
+       ZSTD_outBuffer zob;
+       size_t code;
+
+       id = fh->fh_InstData;
+       zob.dst = buffer;
+       zob.size = bytes;
+       zob.pos = 0;
+
+       while (zob.pos < zob.size) {
+               if (id->id_zib.pos >= id->id_zib.size) {
+                       id->id_zib.size = fread(id->id_Buf, 1, id->id_BufSize,
+                           id->id_File);
+                       if (id->id_zib.size == 0)
+                               break;
+                       id->id_zib.src = id->id_Buf;
+                       id->id_zib.pos = 0;
+               }
+               code = ZSTD_decompressStream(id->id_Stream, &zob, &id->id_zib);
+               if (ZSTD_isError(code))
+                       return -1;
+       }
+
+       return zob.pos;
+}
+
+FileHandle *
+FileHandleZstd(int *fd_p)
+{
+       FileHandle *fh;
+       InstData *id;
+
+       fh = FileHandleCreate(ZstdCloseFunc, ZstdReadFunc, sizeof(*id));
+       if (fh == NULL)
+               return NULL;
+       id = fh->fh_InstData;
+
+       if ((id->id_File = fdopen(*fd_p, "rb")) == NULL) {
+               FileHandleClose(fh);
+               return NULL;
+       }
+       *fd_p = -1;
+
+       id->id_Stream = ZSTD_createDStream();
+       if (id->id_Stream == NULL ||
+           ZSTD_isError(ZSTD_initDStream(id->id_Stream)))
+               return NULL;
+
+       id->id_BufSize = ZSTD_DStreamOutSize();
+       id->id_Buf = malloc(id->id_BufSize);
+       if (id->id_Buf == NULL)
+               return NULL;
+
+       return fh;
+}



Home | Main Index | Thread Index | Old Index