GNU bug report logs - #36976
[PATCH 1/1] download: Map file-name characters not allowed in store.

Previous Next

Package: guix-patches;

Reported by: Hartmut Goebel <h.goebel <at> crazy-compilers.com>

Date: Thu, 8 Aug 2019 14:46:02 UTC

Severity: normal

Tags: patch

Done: Hartmut Goebel <h.goebel <at> crazy-compilers.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Hartmut Goebel <h.goebel <at> crazy-compilers.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#36976: closed ([PATCH 1/1] download: Map file-name characters
 not allowed in store.)
Date: Thu, 26 Sep 2019 15:52:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Thu, 26 Sep 2019 17:50:57 +0200
with message-id <f4abf27e-444f-7b2c-6156-8622ea917047 <at> crazy-compilers.com>
and subject line Re: [bug#36976] [PATCH 1/1] download: Map file-name characters not allowed in store.
has caused the debbugs.gnu.org bug report #36976,
regarding [PATCH 1/1] download: Map file-name characters not allowed in store.
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
36976: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=36976
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Hartmut Goebel <h.goebel <at> crazy-compilers.com>
To: guix-patches <at> gnu.org
Subject: [PATCH 1/1] download: Map file-name characters not allowed in store.
Date: Thu,  8 Aug 2019 16:44:48 +0200
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 <http://issues.guix.gnu.org/issue/26175>

* 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 © 2016 David Craven <david <at> craven.ch>
 ;;; Copyright © 2017 Tobias Geerinckx-Rice <me <at> tobias.gr>
 ;;; Copyright © 2019 Guy Fleury Iteriteka <hoonandon <at> gmail.com>
+;;; Copyright © 2019 Hartmut Goeel <h.goebel <at> crazy-compilers.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -563,13 +564,27 @@ own.  This helper makes it easier to deal with \"zip bombs\"."
                       #:graft? #f
                       #:local-build? #t)))
 
-(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" "+-._?=")))
+  (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? determines
-whether or not to validate HTTPS server certificates."
+  "Download from URL to STORE, either under NAME. If NAME is omitted, URL's
+basename with invalid characters replaced is used.  Write progress reports to
+LOG.  RECURSIVE? has the same effect as the same-named parameter of
+'add-to-store'.  VERIFY-CERTIFICATE? determines whether or not to validate
+HTTPS server certificates."
   (define uri
     (string->uri url))
 
-- 
2.21.0



[Message part 3 (message/rfc822, inline)]
From: Hartmut Goebel <h.goebel <at> crazy-compilers.com>
To: 36976-close <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: Re: [bug#36976] [PATCH 1/1] download: Map file-name characters not
 allowed in store.
Date: Thu, 26 Sep 2019 17:50:57 +0200
Committed as dec845606d2d184da31065fa26cd951b84b3ce2d

Thank for the review.

-- 
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goebel <at> crazy-compilers.com               |
| www.crazy-compilers.com | compilers which you thought are impossible |



This bug report was last modified 5 years and 242 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.