Keep temp-directory assets visible while their files exist (#15510) · code/app-python-comfyui@cc0fc21 · GitHub
Skip to content

Commit cc0fc21

Browse files
authored
Keep temp-directory assets visible while their files exist (Comfy-Org#15510)
* Keep temp-directory assets visible while their files exist Assets written to the temp directory were flagged as missing and dropped from GET /api/assets, even with the file sitting on disk. One list of directories was answering two different questions -- where the scanner looks for new files, and which files ComfyUI considers its own -- and temp belongs only in the second, so every temp reference was disowned by the prune that runs at startup and on POST /api/assets/prune. Ownership now covers temp. Discovery still does not: the temp directory is wiped before the scan runs, and assets written there are already registered with a hash, mime type and dimensions, so walking it would find nothing. Temp references are instead reconciled against the filesystem directly, so a temp file that really is gone is still retired rather than lingering as a broken entry. get_prefixes_for_root becomes get_scan_prefixes_for_root so the two questions are told apart by name rather than by comment. * Cover the unhashed temp asset in the reconciliation tests The existing temp tests all registered hashed assets, so they never exercised the path an unhashed asset takes when its file is gone: the orphaned rows are removed rather than kept as missing, exactly as under any other root.
1 parent e5a38e3 commit cc0fc21

6 files changed

Lines changed: 268 additions & 33 deletions

File tree

‎app/assets/scanner.py‎

Lines changed: 38 additions & 9 deletions

‎app/assets/seeder.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
build_asset_specs,
1616
collect_paths_for_roots,
1717
enrich_assets_batch,
18-
get_all_known_prefixes,
19-
get_prefixes_for_root,
18+
get_owned_prefixes,
19+
get_scan_prefixes_for_root,
2020
get_unenriched_assets_for_roots,
2121
insert_asset_specs,
2222
mark_missing_outside_prefixes_safely,
2323
sync_root_safely,
24+
sync_temp_references_safely,
2425
)
2526
from app.database.db import dependencies_available
2627

@@ -413,7 +414,7 @@ def mark_missing_outside_prefixes(self) -> int:
413414
)
414415
return 0
415416

416-
all_prefixes = get_all_known_prefixes()
417+
all_prefixes = get_owned_prefixes()
417418
marked = mark_missing_outside_prefixes_safely(all_prefixes)
418419
if marked > 0:
419420
logging.info("Marked %d references as missing", marked)
@@ -523,7 +524,7 @@ def _log_scan_config(self, roots: tuple[RootType, ...]) -> None:
523524
os.path.abspath(folder_paths.models_dir),
524525
)
525526
else:
526-
prefixes = get_prefixes_for_root(root)
527+
prefixes = get_scan_prefixes_for_root(root)
527528
if prefixes:
528529
logging.info("Asset scan [%s] directories: %s", root, prefixes)
529530

@@ -548,10 +549,11 @@ def _run_scan(self) -> None:
548549
return
549550

550551
if self._prune_first:
551-
all_prefixes = get_all_known_prefixes()
552+
all_prefixes = get_owned_prefixes()
552553
marked = mark_missing_outside_prefixes_safely(all_prefixes)
553554
if marked > 0:
554555
logging.info("Marked %d refs as missing before scan", marked)
556+
sync_temp_references_safely()
555557

556558
if self._check_pause_and_cancel():
557559
logging.info("Asset scan cancelled after pruning phase")

‎tests-unit/assets_test/test_sync_references.py‎

Lines changed: 14 additions & 14 deletions

0 commit comments

Comments
 (0)