administration

This commit is contained in:
2026-06-29 10:42:56 +02:00
parent e538e8b180
commit 1caad21d73
5 changed files with 235 additions and 31 deletions
+59 -19
View File
@@ -4,6 +4,8 @@
racket/generator
racket/string
racket/path
"store.rkt"
"log.rkt"
file/glob)
(provide make-file-walker
@@ -64,7 +66,7 @@
)
)
(define (make-file-admin base-path db-hash)
(define (make-file-admin base-path db-store)
(define (file-info-equal? i1 i2)
(if (eq? (hash-ref i1 'type) (hash-ref i2 'type))
@@ -79,12 +81,12 @@
(define (file-admin base-path path info)
(let* ((normalized-sub-path (hash-ref info 'path))
(in-db (hash-ref db-hash normalized-sub-path #f))
(in-db (store-ref db-store normalized-sub-path #f))
)
(cond
((eq? in-db #f)
(hash-set! info 'file-db 'new)
(hash-set! db-hash normalized-sub-path info)
(store-set! db-store normalized-sub-path info)
(values base-path path info)
)
(else
@@ -96,31 +98,69 @@
(when (eq? (hash-ref info 'type #f) 'file)
(hash-set! in-db 'size (hash-ref info 'size))
(hash-set! in-db 'mtime (hash-ref info 'mtime)))))
(hash-set! db-hash normalized-sub-path in-db)
(store-set! db-store normalized-sub-path in-db)
(values base-path path in-db)
)
)
))
(define (init-db-sweep)
(hash-for-each db-hash
(λ (key value)
(if (eq? (hash-ref value 'file-db #f) 'deleted)
(hash-remove! db-hash key)
(hash-set! value 'file-db 'unknown)))))
(store-transaction db-store
(let ((count (store-count db-store))
(k 0)
(last-perc 0))
(store-for-each db-store
(λ (key value)
(set! k (+ k 1))
(let ((perc (quotient (* k 100) count)))
(when (and (= (remainder perc 10) 0) (> perc last-perc))
(set! last-perc perc)
(info-am "init-db-sweep: ~a%, k=~a" perc k)))
(if (eq? (hash-ref value 'file-db #f) 'deleted)
(store-remove! db-store key)
(begin
(hash-set! value 'file-db 'unknown)
(store-set! db-store key value))
)
)
)
)
)
)
(define (get-deleted)
(let ((keys (hash-keys db-hash)))
(map (λ (key)
(let ((info (hash-ref db-hash key)))
(hash-set! info 'file-db 'deleted)
info))
(filter (λ (key)
(let ((v (hash-ref db-hash key)))
(eq? (hash-ref v 'file-db) 'unknown)))
keys))))
(let ((count (store-count db-store))
(k 0))
(let ((keys (store-keys db-store)))
(map (λ (key)
(let ((info (store-ref db-store key)))
(hash-set! info 'file-db 'deleted)
info))
(filter (λ (key)
(set! k (+ k 1))
(let ((perc (quotient (* k 100) count)))
(when (= (remainder perc 10) 0)
(info-am "get-deleteed: ~a%" perc)))
(let ((v (store-ref db-store key)))
(eq? (hash-ref v 'file-db) 'unknown)))
keys))))
)
(let* ((fw (make-file-walker base-path "*" file-admin))
(let* ((walker-count 0)
(fw (make-file-walker base-path "*"
(λ (base-path path info)
(cond
((= walker-count 0)
(store-begin db-store))
((= (remainder walker-count 250) 0)
(store-commit db-store)
(store-begin db-store))
)
(set! walker-count (+ walker-count 1))
(let-values (((base-path* path* info*) (file-admin base-path path info)))
(when (eq? info* #f)
(store-commit db-store))
(values base-path* path* info*)))))
(deleted #f))
(init-db-sweep)
(letrec ((f (λ ()