Skip to content

Commit

Permalink
packages: remove old versions of tarball dependencies
Browse files Browse the repository at this point in the history
Fixes GH-41.
  • Loading branch information
dunn committed May 29, 2017
1 parent 8e6a0b3 commit f31e9ca
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
35 changes: 35 additions & 0 deletions src/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ of the information we need to get it."))
(defmethod install-dependency ((dep http-dependency))
(let ((loc (dependency-url dep)))
(download-tarball loc dep)
;; This needs to be run after `download-tarball', since that's
;; where `dependency-sys-path' is set
(remove-old-versions dep)

(make-dependency-available dep)
(install-transitive-dependencies dep)))

Expand All @@ -162,6 +166,10 @@ of the information we need to get it."))
(url (dependency-url dep)))
(cond ((eq :tarball strat)
(download-tarball url dep)
;; This needs to be run after `download-tarball', since
;; that's where `dependency-sys-path' is set
(remove-old-versions dep)

;; The dependency must be made available before it is
;; installed so ASDF can determine its dependencies in turn
(make-dependency-available dep)
Expand Down Expand Up @@ -221,6 +229,33 @@ of the information we need to get it."))
(t (error (format t "~%---X Cannot resolve dependency type")))))


(defun remove-old-versions (dep)
"Walk the dependencies directory and remove versions of DEP that aren't current."
(let* ((dependency-prefix (concatenate 'string (dependency-name dep) "-"))
(old-versions
(remove-if
;; don't delete the latest version, or tarballs for other dependencies
(lambda (x) (or
(and (pathname-match-p (dependency-sys-path dep) x)
;; if the version is "latest", delete it
;; since that means we weren't able to
;; determine the real version; otherwise
;; keep it
(not (string= "latest" (dependency-version dep))))
;; keep it if it doesn't start with `dependency-prefix'
(not (eql (length dependency-prefix)
(string> (first (last (pathname-directory x)))
dependency-prefix)))))
(uiop/filesystem:subdirectories (qi.paths:package-dir)))))

(loop for dir in old-versions
do (progn
(format t "~%.... Deleting outdated ~A" dir)
(uiop:run-program (concatenate 'string "rm -r " (namestring dir))
:wait t
:output :lines)))))


(defun download-tarball (url dep)
"Downloads tarball from <url>, and updates <dep> with the local src-path
and sys-path."
Expand Down
4 changes: 2 additions & 2 deletions t/qi_test.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ run from the command-line."
(reset-metadata)

;; For some reason `sed -i` isn't working
(uiop:run-program "sed 's/0\.0\.1/0.0.2/' qi.yaml >> qwop.yaml"
(uiop:run-program "sed 's/0\.0\.1/0.0.2/g' qi.yaml >> qwop.yaml"
:directory #P"t/resources/project/"
:wait t)
(uiop:run-program "mv qwop.yaml qi.yaml"
Expand All @@ -39,7 +39,7 @@ run from the command-line."
(reset-metadata)

;; Revert
(uiop:run-program "sed 's/0\.0\.2/0.0.1/' qi.yaml >> qwop.yaml"
(uiop:run-program "sed 's/0\.0\.2/0.0.1/g' qi.yaml >> qwop.yaml"
:directory #P"t/resources/project/"
:wait t)
(uiop:run-program "mv qwop.yaml qi.yaml"
Expand Down
1 change: 1 addition & 0 deletions t/resources/project/qi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ packages:
- name: yason
- name: cl-test-1
url: 'https://gitlab.com/welp/cl-test-1/repository/archive.tar.gz?ref=0.0.1'
version: 0.0.1

0 comments on commit f31e9ca

Please sign in to comment.