cs: fix resolve-path to preserve directory separator

Closes #3212
This commit is contained in:
Matthew Flatt 2020-05-24 13:48:35 -06:00
parent f0c79b6b16
commit 406a67def6
4 changed files with 21 additions and 12 deletions

View File

@ -2338,6 +2338,10 @@
resolve-path
"C://testing-root////testing-dir\\\\testing-file")]))
(unless (link-exists? (current-directory))
;; Make sure directoryness is preserved
(test (current-directory) resolve-path (current-directory)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Make sure `write-byte` and `write-char` don't try to test
;; a non-supplied argument:

View File

@ -105,7 +105,12 @@
;; ----------------------------------------
;; normalize-path needs tests
;; normalize-path needs more tests
(unless (directory-exists? "no-such-dir-here")
(err/rt-test (normalize-path (build-path "no-such-dir-here" 'up 'up))
exn:fail?
#rx"element within the input path is not a directory"))
;; ----------------------------------------

View File

@ -344,9 +344,10 @@
(define (do-resolve-path p who)
(check who path-string? p)
(define host-path (->host (path->path-without-trailing-separator (->path p)) who '(exists)))
(define host-path (->host p who '(exists)))
(define host-path/no-sep (host-path->host-path-without-trailing-separator host-path))
(start-atomic)
(define r0 (rktio_readlink rktio host-path))
(define r0 (rktio_readlink rktio host-path/no-sep))
(define r (if (rktio-error? r0)
r0
(begin0

View File

@ -7,7 +7,7 @@
(provide directory-path?
path->directory-path
path->path-without-trailing-separator)
host-path->host-path-without-trailing-separator)
(define/who (path->directory-path p-in)
(check-path-argument who p-in)
@ -53,16 +53,15 @@
dots-end))))]
[else (unixish-path-directory-path?)])]))
(define (path->path-without-trailing-separator p)
(define bstr (path-bytes p))
(define (host-path->host-path-without-trailing-separator bstr)
(define orig-len (bytes-length bstr))
(cond
[(= orig-len 1) p]
[(and (eq? (path-convention p) 'windows)
[(= orig-len 1) bstr]
[(and (eq? (system-path-convention-type) 'windows)
(backslash-backslash-questionmark? bstr))
;; \\?\ is more complicated. Do we need to do anything,
;; considering that the use for this function is `resolve-path`?
p]
bstr]
[else
(define len
(let loop ([len orig-len])
@ -70,9 +69,9 @@
[(zero? len) 0]
[else
(define c (bytes-ref bstr (sub1 len)))
(if (is-sep? c (path-convention p))
(if (is-sep? c (system-path-convention-type))
(loop (sub1 len))
len)])))
(cond
[(< len orig-len) (path (subbytes bstr 0 len) (path-convention p))]
[else p])]))
[(< len orig-len) (subbytes bstr 0 len)]
[else bstr])]))