profiles: Add 'generation-profile'.

* guix/profiles.scm (%profile-generation-rx): New variable.
(generation-profile): New procedure.
This commit is contained in:
Ludovic Courtès 2019-04-06 23:05:27 +02:00
parent bacf980c76
commit c872b952c5
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -118,6 +118,7 @@ (define-module (guix profiles)
profile-search-paths profile-search-paths
generation-number generation-number
generation-profile
generation-numbers generation-numbers
profile-generations profile-generations
relative-generation-spec->number relative-generation-spec->number
@ -1552,6 +1553,20 @@ (define (generation-number profile)
(compose string->number (cut match:substring <> 1))) (compose string->number (cut match:substring <> 1)))
0)) 0))
(define %profile-generation-rx
;; Regexp that matches profile generation.
(make-regexp "(.*)-([0-9]+)-link$"))
(define (generation-profile file)
"If FILE is a profile generation GC root such as \"guix-profile-42-link\",
return its corresponding profile---e.g., \"guix-profile\". Otherwise return
#f."
(match (regexp-exec %profile-generation-rx file)
(#f #f)
(m (let ((profile (match:substring m 1)))
(and (file-exists? (string-append profile "/manifest"))
profile)))))
(define (generation-numbers profile) (define (generation-numbers profile)
"Return the sorted list of generation numbers of PROFILE, or '(0) if no "Return the sorted list of generation numbers of PROFILE, or '(0) if no
former profiles were found." former profiles were found."