From d72da59026b9e25502f33eb634ae02c0a53f74dc Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 6 Feb 2023 12:22:43 +0100 Subject: Add some basic functionality to check the size of the stored files --- scripts/nar-herder.in | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'scripts') diff --git a/scripts/nar-herder.in b/scripts/nar-herder.in index 19ed332..1493d0b 100644 --- a/scripts/nar-herder.in +++ b/scripts/nar-herder.in @@ -247,6 +247,12 @@ (recent-changes-limit . 32768))) +(define %check-options + (list)) + +(define %check-option-defaults + '()) + (define (parse-options options defaults args) (args-fold args options @@ -359,6 +365,44 @@ (database-remove-narinfo database store-path)) (assq-ref opts 'arguments)))) + (("check" rest ...) + (let* ((opts (parse-options (append %base-options + %check-options) + (append %base-option-defaults + %check-option-defaults) + rest)) + (lgr (make )) + (port-log (make + #:port (current-output-port) + #:formatter + (lambda (lvl time str) + (format #f "~a (~5a): ~a~%" + (strftime "%F %H:%M:%S" (localtime time)) + lvl + str)))) + (metrics-registry (make-metrics-registry + #:namespace + "narherder"))) + + (add-handler! lgr port-log) + (open-log! lgr) + (set-default-logger! lgr) + + (let ((log-level (assq-ref opts 'log-level))) + (let loop ((levels %valid-log-levels)) + (when (and (not (null? levels)) + (not (eq? (car levels) log-level))) + (disable-log-level! lgr (car levels)) + (loop (cdr levels))))) + + (let* ((database (setup-database (assq-ref opts 'database) + metrics-registry)) + (canonical-storage (and=> (assq-ref opts 'storage) + canonicalize-path))) + + (check-storage database + canonical-storage + metrics-registry)))) (("run-server" rest ...) (simple-format (current-error-port) "locale is ~A\n" (check-locale!)) -- cgit v1.2.3