pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/rpm2pkg Support RPMs compressed by Zstd, foun...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/bcd0912956eb
branches:  trunk
changeset: 405544:bcd0912956eb
user:      rin <rin%pkgsrc.org@localhost>
date:      Sat Nov 30 23:31:30 2019 +0000

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

diffstat:

 pkgtools/rpm2pkg/Makefile            |    5 +-
 pkgtools/rpm2pkg/files/Makefile      |    4 +-
 pkgtools/rpm2pkg/files/fileio-zstd.c |  120 +++++++++++++++++++++++++++++++++++
 pkgtools/rpm2pkg/files/fileio.h      |    3 +-
 pkgtools/rpm2pkg/files/parse-rpm.c   |   10 ++-
 5 files changed, 135 insertions(+), 7 deletions(-)

diffs (215 lines):

diff -r e1c1a03036e5 -r bcd0912956eb pkgtools/rpm2pkg/Makefile
--- a/pkgtools/rpm2pkg/Makefile Sat Nov 30 22:15:29 2019 +0000
+++ b/pkgtools/rpm2pkg/Makefile Sat Nov 30 23:31:30 2019 +0000
@@ -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 @@
 
 .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"
diff -r e1c1a03036e5 -r bcd0912956eb pkgtools/rpm2pkg/files/Makefile
--- a/pkgtools/rpm2pkg/files/Makefile   Sat Nov 30 22:15:29 2019 +0000
+++ b/pkgtools/rpm2pkg/files/Makefile   Sat Nov 30 23:31:30 2019 +0000
@@ -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
diff -r e1c1a03036e5 -r bcd0912956eb pkgtools/rpm2pkg/files/fileio-zstd.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/rpm2pkg/files/fileio-zstd.c      Sat Nov 30 23:31:30 2019 +0000
@@ -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;
+}
diff -r e1c1a03036e5 -r bcd0912956eb pkgtools/rpm2pkg/files/fileio.h
--- a/pkgtools/rpm2pkg/files/fileio.h   Sat Nov 30 22:15:29 2019 +0000
+++ b/pkgtools/rpm2pkg/files/fileio.h   Sat Nov 30 23:31:30 2019 +0000
@@ -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 *FileHandleLZMA(int *);
 extern FileHandle *FileHandlePlain(int *);
 extern FileHandle *FileHandleZLib(int *);
+extern FileHandle *FileHandleZstd(int *);
 
 #ifdef FILEIO_INTERNAL
 
diff -r e1c1a03036e5 -r bcd0912956eb pkgtools/rpm2pkg/files/parse-rpm.c
--- a/pkgtools/rpm2pkg/files/parse-rpm.c        Sat Nov 30 22:15:29 2019 +0000
+++ b/pkgtools/rpm2pkg/files/parse-rpm.c        Sat Nov 30 23:31:30 2019 +0000
@@ -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 @@
 
 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 @@
        } 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);



Home | Main Index | Thread Index | Old Index