diff --git a/oml/item/scan.py b/oml/item/scan.py index 395e6d1..fb2cc35 100644 --- a/oml/item/scan.py +++ b/oml/item/scan.py @@ -126,12 +126,12 @@ def run_scan(): remove_missing(books) added = 0 - for f in ox.sorted_strings(books): - if state.shutdown: - return - if os.path.exists(f): - id = media.get_id(f) - with db.session(): + with db.session(): + for f in ox.sorted_strings(books): + if state.shutdown: + break + if os.path.exists(f): + id = media.get_id(f) file = File.get(id) if not file: file = add_file(id, f, prefix, f)