summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-04-06 20:02:22 +0200
committerLudovic Courtès <ludo@gnu.org>2015-04-06 20:02:29 +0200
commit65d428d8f4bd6bf05dde428ce51a3ce04bd3aad3 (patch)
treea9624f13b766da91c01d1b4f5653047edc5113bc
parentd507b277ebe69d218d2f2106bdeef8c082c04dbe (diff)
guix package: Move generation deletion to its own procedure.
* guix/scripts/package.scm (delete-matching-generations): New procedure, with code formerly found... (guix-package)[process-actions]: ... here. Use it. Remove 'current-generation-number'.
-rw-r--r--guix/scripts/package.scm56
1 files changed, 29 insertions, 27 deletions
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 3cc7ae760f5..7074243ed90 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -232,6 +232,34 @@ DURATION-RELATION with the current time."
232 filter-by-duration) 232 filter-by-duration)
233 (else #f))) 233 (else #f)))
234 234
235(define (delete-matching-generations store profile pattern)
236 "Delete from PROFILE all the generations matching PATTERN. PATTERN must be
237a string denoting a set of generations: the empty list means \"all generations
238but the current one\", a number designates a generation, and other patterns
239denote ranges as interpreted by 'matching-derivations'."
240 (let ((current (generation-number profile)))
241 (cond ((not (file-exists? profile)) ; XXX: race condition
242 (raise (condition (&profile-not-found-error
243 (profile profile)))))
244 ((string-null? pattern)
245 (delete-generations (%store) profile
246 (delv current (profile-generations profile))))
247 ;; Do not delete the zeroth generation.
248 ((equal? 0 (string->number pattern))
249 (exit 0))
250
251 ;; If PATTERN is a duration, match generations that are
252 ;; older than the specified duration.
253 ((matching-generations pattern profile
254 #:duration-relation >)
255 =>
256 (lambda (numbers)
257 (if (null-list? numbers)
258 (exit 1)
259 (delete-generations (%store) profile numbers))))
260 (else
261 (leave (_ "invalid syntax: ~a~%") pattern)))))
262
235 263
236;;; 264;;;
237;;; Package specifications. 265;;; Package specifications.
@@ -751,9 +779,6 @@ more information.~%"))
751 (define dry-run? (assoc-ref opts 'dry-run?)) 779 (define dry-run? (assoc-ref opts 'dry-run?))
752 (define profile (assoc-ref opts 'profile)) 780 (define profile (assoc-ref opts 'profile))
753 781
754 (define current-generation-number
755 (generation-number profile))
756
757 ;; First roll back if asked to. 782 ;; First roll back if asked to.
758 (cond ((and (assoc-ref opts 'roll-back?) 783 (cond ((and (assoc-ref opts 'roll-back?)
759 (not dry-run?)) 784 (not dry-run?))
@@ -782,30 +807,7 @@ more information.~%"))
782 (for-each 807 (for-each
783 (match-lambda 808 (match-lambda
784 (('delete-generations . pattern) 809 (('delete-generations . pattern)
785 (cond ((not (file-exists? profile)) ; XXX: race condition 810 (delete-matching-generations (%store) profile pattern)
786 (raise (condition (&profile-not-found-error
787 (profile profile)))))
788 ((string-null? pattern)
789 (delete-generations
790 (%store) profile
791 (delete current-generation-number
792 (profile-generations profile))))
793 ;; Do not delete the zeroth generation.
794 ((equal? 0 (string->number pattern))
795 (exit 0))
796
797 ;; If PATTERN is a duration, match generations that are
798 ;; older than the specified duration.
799 ((matching-generations pattern profile
800 #:duration-relation >)
801 =>
802 (lambda (numbers)
803 (if (null-list? numbers)
804 (exit 1)
805 (delete-generations (%store) profile numbers))))
806 (else
807 (leave (_ "invalid syntax: ~a~%")
808 pattern)))
809 811
810 (process-actions 812 (process-actions
811 (alist-delete 'delete-generations opts))) 813 (alist-delete 'delete-generations opts)))