From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:58720) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvjg4-0003Cf-5f for guix-patches@gnu.org; Thu, 08 Aug 2019 10:46:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvjg2-0003ZN-Rq for guix-patches@gnu.org; Thu, 08 Aug 2019 10:46:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:60983) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hvjg2-0003ZH-Ok for guix-patches@gnu.org; Thu, 08 Aug 2019 10:46:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hvjg2-0002pc-Ka for guix-patches@gnu.org; Thu, 08 Aug 2019 10:46:02 -0400 Subject: [bug#36976] [PATCH 1/1] download: Map file-name characters not allowed in store. Resent-Message-ID: Received: from eggs.gnu.org ([2001:470:142:3::10]:58355) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvjey-0002Ik-IR for guix-patches@gnu.org; Thu, 08 Aug 2019 10:44:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvjev-0002F9-68 for guix-patches@gnu.org; Thu, 08 Aug 2019 10:44:56 -0400 Received: from mail-out.m-online.net ([212.18.0.9]:41662) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvjeu-00029h-SG for guix-patches@gnu.org; Thu, 08 Aug 2019 10:44:53 -0400 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 464B3l0ZXVz1rKXK for ; Thu, 8 Aug 2019 16:44:50 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 464B3k6yHDz1qqkD for ; Thu, 8 Aug 2019 16:44:50 +0200 (CEST) Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id A9H_pyzXdR0Y for ; Thu, 8 Aug 2019 16:44:49 +0200 (CEST) Received: from hermia.goebel-consult.de (ppp-188-174-62-181.dynamic.mnet-online.de [188.174.62.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS for ; Thu, 8 Aug 2019 16:44:49 +0200 (CEST) Received: from lenashee.goebel-consult.de (lenashee.goebel-consult.de [192.168.110.2]) by hermia.goebel-consult.de (Postfix) with ESMTP id 916B4601CC for ; Thu, 8 Aug 2019 16:45:43 +0200 (CEST) From: Hartmut Goebel Date: Thu, 8 Aug 2019 16:44:48 +0200 Message-Id: <20190808144448.25147-1-h.goebel@crazy-compilers.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 36976@debbugs.gnu.org In the file-name to be used for storing into the store, replace any character not allowed in the store-file-name by an underscore. This is only done when NAME is not given and thus defaults to toe URL's basename. If NAME is given, this is used unchanged, allowing for more control by other functions. Fixes * guix/download.scm (safe-name): New function. (download-to-store): NAME defaults to the "safe" basename of URL. --- guix/download.scm | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/guix/download.scm b/guix/download.scm index b24aaa0a86..249f612237 100644 --- a/guix/download.scm +++ b/guix/download.scm @@ -6,6 +6,7 @@ ;;; Copyright =C2=A9 2016 David Craven ;;; Copyright =C2=A9 2017 Tobias Geerinckx-Rice ;;; Copyright =C2=A9 2019 Guy Fleury Iteriteka +;;; Copyright =C2=A9 2019 Hartmut Goeel ;;; ;;; This file is part of GNU Guix. ;;; @@ -563,13 +564,27 @@ own. This helper makes it easier to deal with \"zi= p bombs\"." #:graft? #f #:local-build? #t))) =20 -(define* (download-to-store store url #:optional (name (basename url)) +(define (safe-name name) + "Replace any character not allowed in a stroe name by an underscore." + + (define valid-characters + ;; according to nix/libstore/store-api.cc + (string->list (string-append "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789" "+-._?=3D"))) + (string-map (lambda (c) + (if (member c valid-characters) c #\_)) + name)) + +(define* (download-to-store store url + #:optional (name (safe-name (basename url))) #:key (log (current-error-port)) recursive? (verify-certificate? #t)) - "Download from URL to STORE, either under NAME or URL's basename if -omitted. Write progress reports to LOG. RECURSIVE? has the same effect= as -the same-named parameter of 'add-to-store'. VERIFY-CERTIFICATE? determi= nes -whether or not to validate HTTPS server certificates." + "Download from URL to STORE, either under NAME. If NAME is omitted, UR= L's +basename with invalid characters replaced is used. Write progress repor= ts to +LOG. RECURSIVE? has the same effect as the same-named parameter of +'add-to-store'. VERIFY-CERTIFICATE? determines whether or not to valida= te +HTTPS server certificates." (define uri (string->uri url)) =20 --=20 2.21.0