all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Hartmut Goebel <h.goebel@crazy-compilers.com>
To: 36976@debbugs.gnu.org
Subject: [bug#36976] [Patch v2] guix download: Ensure destination file-name is valid in the store.
Date: Tue,  3 Sep 2019 18:20:28 +0200	[thread overview]
Message-ID: <20190903162028.5373-1-h.goebel@crazy-compilers.com> (raw)
In-Reply-To: <20190808144448.25147-1-h.goebel@crazy-compilers.com>

Avoid invalid store-file-name by explicitly passing the destination
name, replacing any character not allowed in the store-file-name by an
underscore.

Fixes <http://issues.guix.gnu.org/issue/26175>

* guix/scripts/download.scm (safe-naensure-valid-store-file-nameme):
  New function. (download-to-store*): Use it to generate a "safe"
  basename of URL.
---
 guix/scripts/download.scm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/guix/scripts/download.scm b/guix/scripts/download.scm
index d8fe71ce12..22cd75ea0b 100644
--- a/guix/scripts/download.scm
+++ b/guix/scripts/download.scm
@@ -33,6 +33,7 @@
   #:use-module (web uri)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-14)
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-37)
   #:use-module (rnrs bytevectors)
@@ -54,9 +55,23 @@
        (url-fetch url file #:mirrors %mirrors)))
     file))
 
+(define (ensure-valid-store-file-name name)
+  "Replace any character not allowed in a stror name by an underscore."
+
+  (define valid
+    ;; according to nix/libstore/store-api.cc
+    (string->char-set (string-append "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                                     "abcdefghijklmnopqrstuvwxyz"
+                                     "0123456789" "+-._?=")))
+  (string-map (lambda (c)
+                (if (char-set-contains? valid c) c #\_))
+              name))
+
+
 (define* (download-to-store* url #:key (verify-certificate? #t))
   (with-store store
     (download-to-store store url
+                       (ensure-valid-store-file-name (basename url))
                        #:verify-certificate? verify-certificate?)))
 
 (define %default-options
-- 
2.21.0

      parent reply	other threads:[~2019-09-03 16:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08 14:44 [bug#36976] [PATCH 1/1] download: Map file-name characters not allowed in store Hartmut Goebel
2019-08-23 21:08 ` Ludovic Courtès
2019-08-27  7:53   ` Hartmut Goebel
2019-09-01 19:39     ` Ludovic Courtès
2019-09-03 14:39       ` bug#26175: " Hartmut Goebel
2019-09-04 10:32         ` Ludovic Courtès
2019-09-08 18:50           ` Hartmut Goebel
2019-09-08 20:07             ` Ludovic Courtès
2019-09-26 15:53         ` Hartmut Goebel
2019-09-26 15:50       ` bug#36976: " Hartmut Goebel
2019-09-03 16:20 ` Hartmut Goebel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190903162028.5373-1-h.goebel@crazy-compilers.com \
    --to=h.goebel@crazy-compilers.com \
    --cc=36976@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.