From b1b593896a9f84a1dadd4612ace094beabf4686f Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Sun, 28 Jun 2026 14:33:41 +0200 Subject: [PATCH] keep original file info in file-walker and make sure changed files are processed properly --- audio-manager.rkt | 27 ++++++++++++++------------- info.rkt | 3 ++- private/file-walker.rkt | 12 ++++++++---- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/audio-manager.rkt b/audio-manager.rkt index 6d679aa..a65eb70 100644 --- a/audio-manager.rkt +++ b/audio-manager.rkt @@ -59,7 +59,7 @@ (eq? state 'changed) (eq? state 'new))))) - (define (needs-copying? info) + (define (needs-copying? path info) (let ((state (hash-ref info 'file-db #f))) (and (eq? (hash-ref info 'type #f) 'file) (not (eq? state 'deleted)) @@ -99,12 +99,13 @@ (eq? (hash-ref info 'ext) 'flac))) (define (flac? path info) - (when (presumed-flac? info) + (if (presumed-flac? info) (let ((s (hash-ref info 'sniffed #f))) (when (eq? s #f) (set! s (audio-sniff-format path)) (hash-set! info 'sniffed s)) - (eq? s 'flac)))) + (eq? s 'flac)) + #f)) (define (rep-id3 path) (set! report-flacs-with-id3 @@ -136,7 +137,10 @@ (define (flac-with-id3 base-path path info) (if (or (needs-processing? path info) - (eq? (hash-ref info 'sniffed #f) #f)) + (and + (eq? (hash-ref info 'type #f) 'file) + (eq? (hash-ref info 'sniffed #f) #f) + (not (deleted? info)))) (let ((ext (hash-ref info 'ext))) (when (memq ext known-audio-exts) (let ((sniffed (audio-sniff-format path))) @@ -152,12 +156,9 @@ (define (flac-khz-bits base-path path info) (when (and (needs-processing? path info) (flac? path info)) - (when (or (eq? (hash-ref info 'khz #f) #f) - (eq? (hash-ref info 'bits #f) #f)) - (let-values (((khz bits) (determine-flac-khz-and-bits path))) - (hash-set! info 'khz khz) - (hash-set! info 'bits bits) - ) + (let-values (((khz bits) (determine-flac-khz-and-bits path))) + (hash-set! info 'khz khz) + (hash-set! info 'bits bits) ) ) (values base-path path info) @@ -254,7 +255,7 @@ ;; Kopieer bestanden rechtstreeks indien nodig en geen flac (define (copy-other base-path path info) - (when (and (needs-copying? info) + (when (and (needs-copying? path info) (not (flac? path info))) (with-handlers ([exn? (λ (e) (set! failed-copies (+ failed-copies 1)) @@ -275,7 +276,7 @@ (let ((path-part (get-path-part info))) (unless (eq? path-part #f) (let ((rm-path (build-path opus-path - (if (presumed-flac? path info) + (if (presumed-flac? info) (path-replace-extension path-part #".opus") path-part)))) (delete-directory/files rm-path #:must-exist? #f) @@ -371,7 +372,7 @@ (sl-set-log-level log-level) (let ((fw (make-file-admin music-path file-db-hash))) - ;; Enrichement phase + ;; Enrichment phase (set! fw (fw-add-step fw adjust-ext)) (set! fw (fw-add-step fw flac-with-id3)) (set! fw (fw-add-step fw flac-khz-bits)) diff --git a/info.rkt b/info.rkt index f932b90..0e0b40f 100644 --- a/info.rkt +++ b/info.rkt @@ -5,9 +5,10 @@ "racket-audio" "simple-ini" "simple-log" + "net-lib" )) (define scribblings '(("scribblings/audio-library-manager.scrbl" ()))) (define build-deps '("rackunit-lib" "scribble-lib" "racket-doc")) (define pkg-desc "Audio library maintenance tools for FLAC and Opus trees") -(define version "0.2.4") +(define version "0.2.6") (define pkg-authors '(hans-dijkema)) diff --git a/private/file-walker.rkt b/private/file-walker.rkt index 4f4ce95..cd1ae63 100644 --- a/private/file-walker.rkt +++ b/private/file-walker.rkt @@ -85,15 +85,19 @@ ((eq? in-db #f) (hash-set! info 'file-db 'new) (hash-set! db-hash normalized-sub-path info) + (values base-path path info) ) (else (if (file-info-equal? info in-db) - (hash-set! info 'file-db 'unchanged) - (hash-set! info 'file-db 'changed)) - (hash-set! db-hash normalized-sub-path info) + (hash-set! in-db 'file-db 'unchanged) + (begin + (hash-set! in-db 'file-db 'changed) + (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) + (values base-path path in-db) ) ) - (values base-path path info) )) (define (init-db-sweep)