raco pkg install: fix tmp-directory clean-up
Fix when installing from a non-directory in `--source` or `--binary` mode, and fix clean up of a GitHub-generated archive when using a path within the archive.
This commit is contained in:
parent
02d53d29fb
commit
0ed142b78f
|
@ -1079,12 +1079,12 @@
|
||||||
['github
|
['github
|
||||||
(unless checksum
|
(unless checksum
|
||||||
(pkg-error
|
(pkg-error
|
||||||
(~a "could not find checksum for github package source, which implies it doesn't exist\n"
|
(~a "could not find checksum for GitHub package source, which implies it doesn't exist\n"
|
||||||
" source: ~a")
|
" source: ~a")
|
||||||
pkg))
|
pkg))
|
||||||
(when (equal? checksum "")
|
(when (equal? checksum "")
|
||||||
(pkg-error
|
(pkg-error
|
||||||
(~a "cannot use empty checksum for github package source\n"
|
(~a "cannot use empty checksum for GitHub package source\n"
|
||||||
" source: ~a")
|
" source: ~a")
|
||||||
pkg))
|
pkg))
|
||||||
(match-define (list* user repo branch path)
|
(match-define (list* user repo branch path)
|
||||||
|
@ -1108,8 +1108,6 @@
|
||||||
"~a-"
|
"~a-"
|
||||||
(format "~a.~a" repo branch))
|
(format "~a.~a" repo branch))
|
||||||
'directory))
|
'directory))
|
||||||
(define package-path
|
|
||||||
(apply build-path tmp-dir path))
|
|
||||||
|
|
||||||
(dynamic-wind
|
(dynamic-wind
|
||||||
void
|
void
|
||||||
|
@ -1122,8 +1120,17 @@
|
||||||
void
|
void
|
||||||
(λ ()
|
(λ ()
|
||||||
(untar tmp.tgz tmp-dir #:strip-components 1)
|
(untar tmp.tgz tmp-dir #:strip-components 1)
|
||||||
|
|
||||||
|
(unless (null? path)
|
||||||
|
(unless (directory-exists? (apply build-path tmp-dir path))
|
||||||
|
(pkg-error
|
||||||
|
(~a "specified directory is not in GitHub respository archive\n"
|
||||||
|
" path: ~a"
|
||||||
|
(apply build-path path))))
|
||||||
|
(lift-directory-content tmp-dir path))
|
||||||
|
|
||||||
(begin0
|
(begin0
|
||||||
(stage-package/info (path->string package-path)
|
(stage-package/info tmp-dir
|
||||||
'dir
|
'dir
|
||||||
pkg-name
|
pkg-name
|
||||||
#:given-checksum checksum
|
#:given-checksum checksum
|
||||||
|
@ -1133,13 +1140,13 @@
|
||||||
download-printf
|
download-printf
|
||||||
metadata-ns
|
metadata-ns
|
||||||
#:strip strip-mode
|
#:strip strip-mode
|
||||||
#:in-place? (not strip-mode)
|
#:in-place? #t
|
||||||
#:in-place-clean? #t)
|
#:in-place-clean? #t)
|
||||||
(set! staged? #t)))
|
(set! staged? #t)))
|
||||||
(λ ()
|
(λ ()
|
||||||
(when (and use-cache? (not staged?))
|
(when (and use-cache? (not staged?))
|
||||||
(clean-cache new-url checksum))
|
(clean-cache new-url checksum))
|
||||||
(unless (and staged? (not strip-mode))
|
(unless staged?
|
||||||
(delete-directory/files tmp-dir)))))
|
(delete-directory/files tmp-dir)))))
|
||||||
(λ ()
|
(λ ()
|
||||||
(delete-directory/files tmp.tgz)))]
|
(delete-directory/files tmp.tgz)))]
|
||||||
|
@ -1269,7 +1276,7 @@
|
||||||
(define pkg-dir
|
(define pkg-dir
|
||||||
(make-temporary-file (string-append "~a-" pkg-name)
|
(make-temporary-file (string-append "~a-" pkg-name)
|
||||||
'directory))
|
'directory))
|
||||||
(define staged? #t)
|
(define staged? #f)
|
||||||
(dynamic-wind
|
(dynamic-wind
|
||||||
void
|
void
|
||||||
(λ ()
|
(λ ()
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
racket/match
|
racket/match
|
||||||
racket/format
|
racket/format
|
||||||
racket/string
|
racket/string
|
||||||
|
racket/set
|
||||||
net/url
|
net/url
|
||||||
json)
|
json)
|
||||||
|
|
||||||
|
@ -163,4 +164,35 @@
|
||||||
(failure bytes))))
|
(failure bytes))))
|
||||||
(lambda () (failure #f)))))
|
(lambda () (failure #f)))))
|
||||||
|
|
||||||
|
(define (lift-directory-content pkg-dir path)
|
||||||
|
(define orig-sub (let ([s (car path)])
|
||||||
|
(if (string? s)
|
||||||
|
(string->path s)
|
||||||
|
s)))
|
||||||
|
;; Delete everything except `orig-sub`:
|
||||||
|
(for ([f (in-list (directory-list pkg-dir))])
|
||||||
|
(unless (equal? f orig-sub)
|
||||||
|
(delete-directory/files (build-path pkg-dir f))))
|
||||||
|
;; Get list of files and directories to move:
|
||||||
|
(define sub-l (directory-list (apply build-path pkg-dir path)))
|
||||||
|
;; Make sure `sub` doesn't match a name we want to move here:
|
||||||
|
(define sub
|
||||||
|
(let loop ([sub orig-sub] [i 0])
|
||||||
|
(cond
|
||||||
|
[(member sub sub-l)
|
||||||
|
;; pick a new name:
|
||||||
|
(loop (string->path (format "sub~a" i)) (add1 i))]
|
||||||
|
[(not (equal? sub orig-sub))
|
||||||
|
(rename-file-or-directory (build-path pkg-dir orig-sub)
|
||||||
|
(build-path pkg-dir sub))
|
||||||
|
sub]
|
||||||
|
[else sub])))
|
||||||
|
;; Move content of `sub` out:
|
||||||
|
(define sub-path (apply build-path (cons sub (cdr path))))
|
||||||
|
(for ([f (in-list sub-l)])
|
||||||
|
(rename-file-or-directory (build-path pkg-dir sub-path f)
|
||||||
|
(build-path pkg-dir f)))
|
||||||
|
;; Remove directory that we moved files out of:
|
||||||
|
(delete-directory/files (build-path pkg-dir sub)))
|
||||||
|
|
||||||
(provide (all-defined-out))
|
(provide (all-defined-out))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user