From 97d565c786ee1a1eb920ed66384f60aad20e5cc2 Mon Sep 17 00:00:00 2001 From: Efraim Flashner Date: Wed, 19 Oct 2022 12:19:04 +0300 Subject: guix gc: Add '--vacuum-database'. * guix/scripts/gc.scm (show-help, %options): Add '--vacuum-database'. * guix/store/database.scm (vacuum-database): New procedure. * doc/guix.texi (Invoking guix gc): Document the option. --- guix/scripts/gc.scm | 11 +++++++++++ guix/store/database.scm | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'guix') diff --git a/guix/scripts/gc.scm b/guix/scripts/gc.scm index 65cd4bdf8b..5e775c5cdb 100644 --- a/guix/scripts/gc.scm +++ b/guix/scripts/gc.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2012-2013, 2015-2020, 2022 Ludovic Courtès +;;; Copyright © 2022 Efraim Flashner ;;; ;;; This file is part of GNU Guix. ;;; @@ -27,6 +28,7 @@ generation-number) #:autoload (guix scripts package) (delete-generations) #:autoload (gnu home) (home-generation-base) + #:autoload (guix store database) (vacuum-database) #:use-module (ice-9 match) #:use-module (ice-9 regex) #:use-module (srfi srfi-1) @@ -86,6 +88,10 @@ Invoke the garbage collector.\n")) (display (G_ " --clear-failures remove PATHS from the set of cached failures")) (newline) + (display (G_ " + --vacuum-database repack the sqlite database tracking the store + using less space")) + (newline) (display (G_ " -h, --help display this help and exit")) (display (G_ " @@ -131,6 +137,11 @@ current one." (lambda args (show-version-and-exit "guix gc"))) + (option '("vacuum-database") #f #f + (lambda args + (vacuum-database) + (exit 0))) + (option '(#\C "collect-garbage") #f #t (lambda (opt name arg result) (let ((result (alist-cons 'action 'collect-garbage diff --git a/guix/store/database.scm b/guix/store/database.scm index 8d08def833..e664015673 100644 --- a/guix/store/database.scm +++ b/guix/store/database.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2017, 2019 Caleb Ristvedt ;;; Copyright © 2018, 2020, 2021 Ludovic Courtès ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen +;;; Copyright © 2022 Efraim Flashner ;;; ;;; This file is part of GNU Guix. ;;; @@ -45,7 +46,8 @@ sqlite-register register-items %epoch - reset-timestamps)) + reset-timestamps + vacuum-database)) ;;; Code for working with the store database directly. @@ -438,3 +440,8 @@ typically by adding them as temp-roots." (register db item) (report)) items))))) + +(define (vacuum-database) + (let ((db (sqlite-open (store-database-file)))) + (sqlite-exec db "VACUUM;") + (sqlite-close db))) -- cgit v1.2.3