From b3ab82c5f9baf9a24d0face668eb321e223e25f3 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 30 Dec 2013 09:32:03 -0700 Subject: [PATCH] fix problem with `path->collects-relative` An internal error could be triggered by a path immediately inside the "pkgs" directory. --- pkgs/racket-pkgs/racket-test/tests/pkg/path.rkt | 6 +++++- racket/collects/pkg/path.rkt | 16 +++++++++------- racket/collects/setup/collects.rkt | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pkgs/racket-pkgs/racket-test/tests/pkg/path.rkt b/pkgs/racket-pkgs/racket-test/tests/pkg/path.rkt index aed8052477..fdd0faeedb 100644 --- a/pkgs/racket-pkgs/racket-test/tests/pkg/path.rkt +++ b/pkgs/racket-pkgs/racket-test/tests/pkg/path.rkt @@ -1,5 +1,6 @@ #lang racket/base -(require pkg/path) +(require pkg/path + setup/dirs) (module+ test (require rackunit) @@ -18,6 +19,9 @@ (check-equal? (path->pkg (find-system-path 'temp-dir)) #f) + (check-equal? (path->pkg (build-path (find-pkgs-dir) "pkgs.rktd")) + #f) + (check-equal? (call-with-values (lambda () (path->pkg+subpath+collect (collection-file-path "serve-catalog.rkt" "distro-build"))) list) diff --git a/racket/collects/pkg/path.rkt b/racket/collects/pkg/path.rkt index 41233719fc..7c0f436670 100644 --- a/racket/collects/pkg/path.rkt +++ b/racket/collects/pkg/path.rkt @@ -111,13 +111,15 @@ ;; name followed by "+") (define len (length d)) (define pkg-name (path-element->string (list-ref p len))) - (values (if (regexp-match? #rx"[+]" pkg-name) ; + used as an alternate path, sometimes - (regexp-replace #rx"[+].*$" pkg-name "") - pkg-name) - (build-path* (list-tail p (add1 len))) - (and want-collect? - (let ([i (hash-ref (read-pkg-db/cached) pkg-name #f)]) - (and i (sc-pkg-info? i) (sc-pkg-info-collect i)))))] + (if (regexp-match? #rx"pkgs[.]rktd" pkg-name) + (values #f #f #f) ; don't count the database as a package + (values (if (regexp-match? #rx"[+]" pkg-name) ; + used as an alternate path, sometimes + (regexp-replace #rx"[+].*$" pkg-name "") + pkg-name) + (build-path* (list-tail p (add1 len))) + (and want-collect? + (let ([i (hash-ref (read-pkg-db/cached) pkg-name #f)]) + (and i (sc-pkg-info? i) (sc-pkg-info-collect i))))))] [else ;; Maybe it's a linked package (define pkgs-dir (get-pkgs-dir scope)) diff --git a/racket/collects/setup/collects.rkt b/racket/collects/setup/collects.rkt index c706a7074d..39b852d642 100644 --- a/racket/collects/setup/collects.rkt +++ b/racket/collects/setup/collects.rkt @@ -21,7 +21,7 @@ (define-values (pkg subpath pkg-collect) (path->pkg+subpath+collect simple-p #:cache cache)) (cond - [pkg + [(and pkg (not (eq? 'same subpath))) (define p-l (map path-element->string (reverse (explode-path subpath)))) (define new-c-l (let ([l (reverse (cdr p-l))]) (if pkg-collect