Index: common.scm ================================================================== --- common.scm +++ common.scm @@ -268,10 +268,11 @@ ;; E X I T H A N D L I N G ;;====================================================================== (define (common:legacy-sync-recommended) (or (args:get-arg "-runtests") + (args:get-arg "-run") (args:get-arg "-server") (args:get-arg "-set-run-status") (args:get-arg "-remove-runs") (args:get-arg "-get-run-status") )) @@ -278,12 +279,19 @@ (define (common:legacy-sync-required) (configf:lookup *configdat* "setup" "megatest-db")) (define (std-exit-procedure) - (let ((no-hurry (if *time-to-exit* ;; hurry up - #f + ;; (let ((dbpath (db:dbfile-path run-id)) + ;; (lockf (conc dbpath "/." run-id ".lck"))) + ;; (common:simple-file-lock lockf) + ;; (db:multi-db-sync (list run-id) 'new2old) + ;; (common:simple-file-release-lock lockf)) + (let* ((dbpath (db:dbfile-path run-id)) + (lockf (conc dbpath "/." run-id ".lck")) + (no-hurry (if *time-to-exit* ;; hurry up + #f (begin (set! *time-to-exit* #t) #t)))) (debug:print-info 4 "starting exit process, finalizing databases.") (if (and no-hurry (debug:debug-mode 18)) @@ -290,11 +298,16 @@ (rmt:print-db-stats)) (let ((th1 (make-thread (lambda () ;; thread for cleaning up, give it five seconds (let ((run-ids (hash-table-keys *db-local-sync*))) (if (and (not (null? run-ids)) (configf:lookup *configdat* "setup" "megatest-db")) - (if no-hurry (db:multi-db-sync run-ids 'new2old)))) + ;; was if no-hurry but I always want it sync'd I think ... + ;; (if no-hurry (db:multi-db-sync run-ids 'new2old)))) + (begin + (common:simple-file-lock lockf) + (db:multi-db-sync run-ids 'new2old) + (common:simple-file-release-lock lockf)))) (if *dbstruct-db* (db:close-all *dbstruct-db*)) (if *inmemdb* (db:close-all *inmemdb*)) (if (and *megatest-db* (sqlite3:database? *megatest-db*)) (begin Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -138,12 +138,19 @@ ;; NB// #f => return dbdir only ;; (was planned to be; zeroth db with name=main.db) ;; (define (db:dbfile-path run-id) - (let* ((dbdir (or (configf:lookup *configdat* "setup" "dbdir") - (conc (configf:lookup *configdat* "setup" "linktree") "/.db"))) + (let* ((dbdirs (filter string? + (list (configf:lookup *configdat* "setup" "dbdir") + (conc *toppath* "/.db") + (conc (configf:lookup *configdat* "setup" "linktree") "/.db")))) + (existing-dirs (filter file-exists? dbdirs)) + (dbdir (if (null? existing-dirs) + (or (configf:lookup *configdat* "setup" "dbdir") + (conc *toppath* "/.db")) + (car existing-dirs))) (fname (if run-id (if (eq? run-id 0) "main.db" (conc run-id ".db")) #f))) (handle-exceptions exn