[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#36976] [PATCH 1/1] download: Map file-name characters not allowed i
From: |
Ludovic Courtès |
Subject: |
[bug#36976] [PATCH 1/1] download: Map file-name characters not allowed in store. |
Date: |
Fri, 23 Aug 2019 23:08:29 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) |
Hello,
Hartmut Goebel <address@hidden> skribis:
> 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.
What about moving this automatic renaming feature to (guix scripts
download)? I’d rather not do it in the core APIs.
> +(define (safe-name name)
> + "Replace any character not allowed in a stroe name by an underscore."
^^
Typo.
I’d call it ‘ensure-valid-store-file-name’ or similar, WDYT?
> + (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))
Instead of a list, please use a SRFI-14 “character set”, like this:
(define valid
(string->char-set …))
(string-map (lambda (c)
(if (char-set-contains? valid c) …))
name)
Thanks,
Ludo’.