[bug#35176,3/5] profiles: Add 'generation-profile'.

Message ID 20190406213123.27164-3-ludo@gnu.org
State Accepted
Headers show
Series 'guix gc --delete-generations' and '--list-roots' | expand

Checks

Context Check Description
cbaines/applying patch fail Apply failed

Commit Message

Ludovic Courtès April 6, 2019, 9:31 p.m. UTC
* guix/profiles.scm (%profile-generation-rx): New variable.
(generation-profile): New procedure.
---
 guix/profiles.scm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Patch

diff --git a/guix/profiles.scm b/guix/profiles.scm
index 6564526aee..dfc9ba1ca0 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -118,6 +118,7 @@ 
             profile-search-paths
 
             generation-number
+            generation-profile
             generation-numbers
             profile-generations
             relative-generation-spec->number
@@ -1552,6 +1553,20 @@  already effective."
              (compose string->number (cut match:substring <> 1)))
       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)
   "Return the sorted list of generation numbers of PROFILE, or '(0) if no
 former profiles were found."