From a2e75d1ff26280eae18a5005c2b07ff708becd18 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 14 Oct 2013 18:15:38 -0600 Subject: [PATCH] {copy/delete}-directory/files: raise "not dir or file" as exn:fail:filesystem When a bad path is encountered, the problem should count as a filesystem exception so that it can be caught with other filesystem exceptions. --- .../racket-doc/pkg/scribblings/path.scrbl | 26 +++++++++++++------ racket/collects/racket/file.rkt | 16 +++++++----- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/pkgs/racket-pkgs/racket-doc/pkg/scribblings/path.scrbl b/pkgs/racket-pkgs/racket-doc/pkg/scribblings/path.scrbl index 6cbe6e2d0e..321704d364 100644 --- a/pkgs/racket-pkgs/racket-doc/pkg/scribblings/path.scrbl +++ b/pkgs/racket-pkgs/racket-doc/pkg/scribblings/path.scrbl @@ -15,22 +15,32 @@ utilities for working with package paths and installed-package databases.} -@defstruct[pkg-info ([orig-pkg (or/c (list/c 'catalog string?) - (list/c 'url string?) - (list/c 'link string?) - (list/c 'static-link string?))] - [checksum (or/c #f string?)] - [auto? boolean?]) - #:prefab]{ +@defstruct*[pkg-info ([orig-pkg (or/c (list/c 'catalog string?) + (list/c 'url string?) + (list/c 'link string?) + (list/c 'static-link string?))] + [checksum (or/c #f string?)] + [auto? boolean?]) + #:prefab]{ A structure type that is used to report installed-package information.} -@defstruct[(sc-pkg-info pkg-info) ()]{ +@defstruct*[(sc-pkg-info pkg-info) ()]{ A structure subtype that represents a package that is installed as single-collection.} +@deftogether[( +@defstruct*[(pkg-info/alt pkg-info) ([dir-name string?])] +@defstruct*[(sc-pkg-info/alt sc-pkg-info) ([dir-name string?])] +)]{ + +Structure subtypes that are used when the installation directory for a +package does not match the package name, but is instead +@racket[dir-name]. The directory name always includes a @litchar{+} +(which is disallowed in a package name).} + @defproc[(path->pkg [path path-string?] [#:cache cache (or/c #f (and/c hash? (not/c immutable?)))]) diff --git a/racket/collects/racket/file.rkt b/racket/collects/racket/file.rkt index 0cadc8ce8e..e3a5b23449 100644 --- a/racket/collects/racket/file.rkt +++ b/racket/collects/racket/file.rkt @@ -66,9 +66,15 @@ (delete-directory path)] [else (when must-exist? - (error 'delete-directory/files - "encountered ~a, neither a file nor a directory" - path))]))) + (raise-not-a-file-or-directory 'delete-directory/files path))]))) + +(define (raise-not-a-file-or-directory who path) + (raise + (make-exn:fail:filesystem + (format "~a: encountered ~a, neither a file nor a directory" + who + path) + (current-continuation-marks)))) (define (copy-directory/files src dest #:keep-modify-seconds? [keep-modify-seconds? #f]) @@ -85,9 +91,7 @@ (loop (build-path src e) (build-path dest e))) (sorted-dirlist src))] - [else (error 'copy-directory/files - "encountered ~a, neither a file nor a directory" - src)]))) + [else (raise-not-a-file-or-directory 'copy-directory/files src)]))) (define (make-directory* dir) (let-values ([(base name dir?) (split-path dir)])