From patchwork Thu Jan 4 16:48:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 58354 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 94EBE27BBE2; Thu, 4 Jan 2024 16:51:21 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 63EDA27BBE9 for ; Thu, 4 Jan 2024 16:51:20 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLQvy-0003WN-W1; Thu, 04 Jan 2024 11:51:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLQvx-0003Ue-7n for guix-patches@gnu.org; Thu, 04 Jan 2024 11:51:05 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLQvv-0001Tf-FV; Thu, 04 Jan 2024 11:51:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rLQvw-0005Wt-BZ; Thu, 04 Jan 2024 11:51:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68242] [PATCH 5/5] man-db: Add support for zstd compressed man pages. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Thu, 04 Jan 2024 16:51:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68242 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68242@debbugs.gnu.org Cc: Maxim Cournoyer , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 68242-submit@debbugs.gnu.org id=B68242.170438700921154 (code B ref 68242); Thu, 04 Jan 2024 16:51:04 +0000 Received: (at 68242) by debbugs.gnu.org; 4 Jan 2024 16:50:09 +0000 Received: from localhost ([127.0.0.1]:55556 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rLQv2-0005V4-Rg for submit@debbugs.gnu.org; Thu, 04 Jan 2024 11:50:09 -0500 Received: from mail-qt1-x82c.google.com ([2607:f8b0:4864:20::82c]:61552) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rLQv0-0005To-5S for 68242@debbugs.gnu.org; Thu, 04 Jan 2024 11:50:07 -0500 Received: by mail-qt1-x82c.google.com with SMTP id d75a77b69052e-4280e3ab14fso4219031cf.2 for <68242@debbugs.gnu.org>; Thu, 04 Jan 2024 08:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704386996; x=1704991796; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U1VUaYj9q2fqTmycjhUiIHy5KObjtlKMu8Eo6Cz5gUc=; b=kQpjiRTnPEMMP3HLCbu/ZqmTQUHa3TjNzNwNLrp21/S9CyFKrh2Cra48lrzmeH39rz k/oouXMO9HlNPKpoCVwhxHWOo4r8GlurTI2RZKC/ZH4C7bnLpe+Hjawo/b5XqLBn3aV0 Mn3sx1/5uQ7bWfllzoSUAAZ+Wogl+8HB6OzFo+g8qIazxu/ke/Z7thUyqy5LixVC8Afa 4/F0FuLTAAOywZSeVsvAlrXThB1wibuUoUh1/SFy2K4h5Itk1DNp9w1pOKM0O7KbMgnE n/Ix3J3IZMtafSQR20f55Pk59jWtahtyuAT6a3nJfZJJrOcI1OpCi+Ox8p+INLkqfmGI OZ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704386996; x=1704991796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U1VUaYj9q2fqTmycjhUiIHy5KObjtlKMu8Eo6Cz5gUc=; b=mWOqMntJw/KD87lNwM3nAmladlcy3tt1eT0VTXCTthdQ9B0LiKV3peQ3h2vzdIepJa LSeQyEVbBg0q+Nonol4IAjOGDgXaplQ1ta2r7gpj7eViSY8YEssyBuRKEKLUnTVkgW+o 4XFMaHloeAInULFuMMPergjX5hHGvlvX0CqCab0SvbbQe7ZGYswecnoyIjxSMl6U2L0H Bk1Iz+SdRbK8IWPiuNXtSVQIKCo/9MQ2knL4urMjs7T/uCumfqfYfxPrw2Vte3I/r54S RbOjNEV9cHuuIzE6HAi5exbJ/dJ2ZsIzOzEyEcO1aQ1fI9CYzF2tLWpZsiSIJqAPc5f7 TS8w== X-Gm-Message-State: AOJu0YyonF9InIXhn+cxTj+aSADqoTif3wUEBVU5horpgKHVm8G+YRU6 UbAqmLPVXaFliNRZp0Jvsk64ys4vMQIqDw== X-Google-Smtp-Source: AGHT+IF93doo9qXtuKzVZPx1eBU1ULGpuSqMPliUYCZG3gPA/Dex6NQ9C/hQHzmfqVzG6EdITS1UPA== X-Received: by 2002:a05:6214:262f:b0:680:d30a:d599 with SMTP id gv15-20020a056214262f00b00680d30ad599mr955397qvb.69.1704386996381; Thu, 04 Jan 2024 08:49:56 -0800 (PST) Received: from localhost.localdomain (dsl-10-135-125.b2b2c.ca. [72.10.135.125]) by smtp.gmail.com with ESMTPSA id o2-20020a0cecc2000000b0067aab230ed9sm11854706qvq.21.2024.01.04.08.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:49:56 -0800 (PST) From: Maxim Cournoyer Date: Thu, 4 Jan 2024 11:48:21 -0500 Message-ID: <44d6f0f8471ad290a78c102228352481a131f60f.1704386901.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/man-db.scm (): Adjust comment. (abbreviate-file-name): Adjust regexp. (gz-compressed?, zstd-compressed?): New predicates. (entry->string): Use them. (man-page->entry): Adjust doc. Use input port reader appropriate to the compression type, if any. (man-files): Adjust regexp. (mandb-entries): Adjust link resolving predicate. * guix/profiles.scm (manual-database): Add guile-zlib extension. Change-Id: I6336e46e2d324c520a7d15d6cafd12bbf43c5b09 --- guix/man-db.scm | 45 +++++++++++++++++++++++++++++++++++---------- guix/profiles.scm | 8 ++++++-- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/guix/man-db.scm b/guix/man-db.scm index 7d9707a592..12887ce400 100644 --- a/guix/man-db.scm +++ b/guix/man-db.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017, 2018 Ludovic Courtès +;;; Copyright © 2022, 2024 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -18,6 +19,7 @@ (define-module (guix man-db) #:use-module (zlib) + #:use-module (zstd) #:use-module ((guix build utils) #:select (find-files)) #:use-module (gdbm) ;gdbm-ffi #:use-module (srfi srfi-9) @@ -48,7 +50,7 @@ (define-module (guix man-db) (define-record-type (mandb-entry file-name name section synopsis kind) mandb-entry? - (file-name mandb-entry-file-name) ;e.g., "../abiword.1.gz" + (file-name mandb-entry-file-name) ;e.g., "../abiword.1.zst" (name mandb-entry-name) ;e.g., "ABIWORD" (section mandb-entry-section) ;number (synopsis mandb-entry-synopsis) ;string @@ -63,7 +65,7 @@ (define (mandb-entrystring entry) "Return the wire format for ENTRY as a string." (match entry @@ -92,7 +102,11 @@ (define (entry->string entry) "\t-\t-\t" - (if (string-suffix? ".gz" file) "gz" "") + (cond + ((gzip-compressed? file) "gz") + ((zstd-compressed? file) "zst") + (else "")) + "\t" synopsis "\x00")))) @@ -148,7 +162,8 @@ (define (read-synopsis port) (loop (cons line lines)))))) (define* (man-page->entry file #:optional (resolve identity)) - "Parse FILE, a gzipped man page, and return a for it." + "Parse FILE, a gzip or zstd compressed man page, and return a +for it." (define (string->number* str) (if (and (string-prefix? "\"" str) (> (string-length str) 1) @@ -156,8 +171,13 @@ (define* (man-page->entry file #:optional (resolve identity)) (string->number (string-drop (string-drop-right str 1) 1)) (string->number str))) - ;; Note: This works for both gzipped and uncompressed files. - (call-with-gzip-input-port (open-file file "r0") + (define call-with-input-port* + (cond + ((gzip-compressed? file) call-with-gzip-input-port) + ((zstd-compressed? file) call-with-zstd-input-port) + (else call-with-port))) + + (call-with-input-port* (open-file file "r0") (lambda (port) (let loop ((name #f) (section #f) @@ -191,14 +211,19 @@ (define* (man-page->entry file #:optional (resolve identity)) (define (man-files directory) "Return the list of man pages found under DIRECTORY, recursively." ;; Filter the list to ensure that broken symlinks are excluded. - (filter file-exists? (find-files directory "\\.[0-9][a-z]?(\\.gz)?$"))) + (filter file-exists? + (find-files directory "\\.[0-9][a-z]?(\\.(gz|zst))?$"))) (define (mandb-entries directory) "Return mandb entries for the man pages found under DIRECTORY, recursively." (map (lambda (file) (man-page->entry file (lambda (link) - (let ((file (string-append directory "/" link - ".gz"))) - (and (file-exists? file) file))))) + (let ((file-gz (string-append directory "/" link + ".gz")) + (file-zst (string-append directory "/" link + ".zst"))) + (and (or (file-exists? file-gz) + (file-exists? file-zst) file) + file))))) (man-files directory))) diff --git a/guix/profiles.scm b/guix/profiles.scm index da7790d819..7fa5dab62a 100644 --- a/guix/profiles.scm +++ b/guix/profiles.scm @@ -7,7 +7,7 @@ ;;; Copyright © 2016, 2017, 2018, 2019, 2021, 2022 Ricardo Wurmus ;;; Copyright © 2016 Chris Marusich ;;; Copyright © 2017 Huang Ying -;;; Copyright © 2017, 2021 Maxim Cournoyer +;;; Copyright © 2017, 2021, 2024 Maxim Cournoyer ;;; Copyright © 2019 Kyle Meyer ;;; Copyright © 2019 Mathieu Othacehe ;;; Copyright © 2020 Danny Milosavljevic @@ -1701,6 +1701,9 @@ (define* (manual-database manifest #:optional system) (define guile-zlib (module-ref (resolve-interface '(gnu packages guile)) 'guile-zlib)) + (define guile-zstd + (module-ref (resolve-interface '(gnu packages guile)) 'guile-zstd)) + (define modules (delete '(guix config) (source-module-closure `((guix build utils) @@ -1709,7 +1712,8 @@ (define* (manual-database manifest #:optional system) (define build (with-imported-modules modules (with-extensions (list gdbm-ffi ;for (guix man-db) - guile-zlib) + guile-zlib + guile-zstd) #~(begin (use-modules (guix man-db) (guix build utils)