From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:37344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hCsv0-0006VR-KJ for guix-patches@gnu.org; Sat, 06 Apr 2019 17:32:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hCsuy-0004he-SX for guix-patches@gnu.org; Sat, 06 Apr 2019 17:32:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:33987) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hCsux-0004gP-Mn for guix-patches@gnu.org; Sat, 06 Apr 2019 17:32:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hCsux-0005EZ-Hj for guix-patches@gnu.org; Sat, 06 Apr 2019 17:32:03 -0400 Subject: [bug#35176] [PATCH 3/5] profiles: Add 'generation-profile'. Resent-Message-ID: From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Sat, 6 Apr 2019 23:31:21 +0200 Message-Id: <20190406213123.27164-3-ludo@gnu.org> In-Reply-To: <20190406213123.27164-1-ludo@gnu.org> References: <20190406213123.27164-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 35176@debbugs.gnu.org * guix/profiles.scm (%profile-generation-rx): New variable. (generation-profile): New procedure. --- guix/profiles.scm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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." -- 2.21.0