raco pkg {install,update}: guard against ill-formed arguments

Parsing a package source/name for scope inference should
report errors in the source/name syntax.

Closes PR 14026
This commit is contained in:
Matthew Flatt 2013-09-17 09:50:02 -06:00
parent 53a9a4f6fc
commit 7016d3ab58
4 changed files with 19 additions and 2 deletions

View File

@ -22,6 +22,12 @@
(shelly-case "remove of not installed package fails"
$ "raco pkg show -u -a" =stdout> " [none]\n"
$ "raco pkg remove not-there" =exit> 1)
(shelly-case "remove of bad name"
$ "raco pkg remove bad/" =exit> 1
=stderr> #rx"disallowed")
(shelly-case "remove of bad name"
$ "raco pkg remove bad#2" =exit> 1
=stderr> #rx"disallowed")
(shelly-install "remove test"
"test-pkgs/pkg-test1.zip")
(shelly-install "remove test with immediately redundant package name"

View File

@ -19,6 +19,9 @@
(shelly-case
"update"
(shelly-case "update of bad name"
$ "raco pkg update bad#2" =exit> 1
=stderr> #rx"disallowed")
(shelly-install "local packages can't be updated (file)"
"test-pkgs/pkg-test1.zip"
$ "raco pkg update pkg-test1" =exit> 1)

View File

@ -86,7 +86,7 @@
(λ ()
(delete-directory/files tmp-dir))))
(define-syntax-rule (with-fake-root e ...)
(with-fake-installation* (λ () e ...)))
(with-fake-root* (λ () e ...)))
(define (with-thread start-thread thunk)
(define thread-id (thread start-thread))

View File

@ -59,7 +59,15 @@
(with-pkg-lock/read-only
(define-values (pkg scope)
(for/fold ([prev-pkg #f] [prev-scope #f]) ([pkg (in-list pkgs)])
(define pkg-name (package-source->name pkg pkgs-type))
(define-values (pkg-name pkg-type)
(package-source->name+type pkg pkgs-type
#:must-infer-name? #t
#:complain
(lambda (s msg)
((current-pkg-error)
(~a "~a\n"
" given: ~a")
msg s))))
(define scope (find-pkg-installation-scope pkg-name))
(cond
[(not prev-pkg) (values pkg scope)]