Skip to content
Snippets Groups Projects
Unverified Commit 65f224dc authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

syscalls: Provide 'free-disk-space'.

* guix/build/syscalls.scm (free-disk-space): New procedure.
* guix/scripts/gc.scm (guix-gc)[ensure-free-space]: Use it instead of
'statfs'.
parent d9bad2f0
No related branches found
No related tags found
No related merge requests found
...@@ -62,6 +62,7 @@ (define-module (guix build syscalls) ...@@ -62,6 +62,7 @@ (define-module (guix build syscalls)
file-system-fragment-size file-system-fragment-size
file-system-mount-flags file-system-mount-flags
statfs statfs
free-disk-space
processes processes
mkdtemp! mkdtemp!
...@@ -697,6 +698,12 @@ (define statfs ...@@ -697,6 +698,12 @@ (define statfs
(list file (strerror err)) (list file (strerror err))
(list err))))))) (list err)))))))
(define (free-disk-space file)
"Return the free disk space, in bytes, on the file system that hosts FILE."
(let ((fs (statfs file)))
(* (file-system-block-size fs)
(file-system-blocks-available fs))))
;;; ;;;
;;; Containers. ;;; Containers.
......
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2015, 2016 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2012, 2013, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
...@@ -20,7 +20,7 @@ (define-module (guix scripts gc) ...@@ -20,7 +20,7 @@ (define-module (guix scripts gc)
#:use-module (guix ui) #:use-module (guix ui)
#:use-module (guix scripts) #:use-module (guix scripts)
#:use-module (guix store) #:use-module (guix store)
#:autoload (guix build syscalls) (statfs) #:autoload (guix build syscalls) (free-disk-space)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (ice-9 regex) #:use-module (ice-9 regex)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
...@@ -184,9 +184,7 @@ (define (store-directory file) ...@@ -184,9 +184,7 @@ (define (store-directory file)
(define (ensure-free-space store space) (define (ensure-free-space store space)
;; Attempt to have at least SPACE bytes available in STORE. ;; Attempt to have at least SPACE bytes available in STORE.
(let* ((fs (statfs (%store-prefix))) (let ((free (free-disk-space (%store-prefix))))
(free (* (file-system-block-size fs)
(file-system-blocks-available fs))))
(if (> free space) (if (> free space)
(info (G_ "already ~h bytes available on ~a, nothing to do~%") (info (G_ "already ~h bytes available on ~a, nothing to do~%")
free (%store-prefix)) free (%store-prefix))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment