From e82ff83a5f37108cc4f17bb49d6ee498e435442f Mon Sep 17 00:00:00 2001 From: gahusb Date: Fri, 24 Apr 2026 09:05:12 +0900 Subject: [PATCH] =?UTF-8?q?fix(travel-proxy):=20indexer.py=20stat()=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=ED=95=B8=EB=93=A4=EB=A7=81=20+=20updated?= =?UTF-8?q?=20=EC=B9=B4=EC=9A=B4=ED=84=B0=20+=20=EB=A1=9C=EA=B9=85=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- travel-proxy/app/indexer.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/travel-proxy/app/indexer.py b/travel-proxy/app/indexer.py index ec116fd..a7cfb41 100644 --- a/travel-proxy/app/indexer.py +++ b/travel-proxy/app/indexer.py @@ -23,9 +23,14 @@ def _scan_folder(folder: Path) -> List[Dict[str, Any]]: with os.scandir(folder) as entries: for entry in entries: if entry.is_file() and Path(entry.name).suffix.lower() in IMAGE_EXT: + try: + mtime = entry.stat().st_mtime + except OSError as e: + logger.warning("Cannot stat %s: %s", entry.path, e) + continue items.append({ "filename": entry.name, - "mtime": entry.stat().st_mtime, + "mtime": mtime, }) return items @@ -73,8 +78,12 @@ def sync( start = time.time() # 1. region_map.json에서 전체 앨범 폴더 수집 - with open(region_map_path, "r", encoding="utf-8") as f: - region_map = json.load(f) + try: + with open(region_map_path, "r", encoding="utf-8") as f: + region_map = json.load(f) + except (FileNotFoundError, json.JSONDecodeError) as e: + logger.error("Failed to load region_map: %s", e) + raise all_albums: Set[str] = set() for v in region_map.values(): @@ -85,6 +94,7 @@ def sync( # 2. 각 앨범 폴더 스캔 → DB 동기화 added = 0 + updated = 0 removed = 0 for album in sorted(all_albums): @@ -97,6 +107,8 @@ def sync( result = db.upsert_photo(album, item["filename"], item["mtime"]) if result == "added": added += 1 + elif result == "updated": + updated += 1 removed += db.remove_missing_photos(album, existing_filenames) @@ -113,12 +125,13 @@ def sync( duration = round(time.time() - start, 2) logger.info( - "Sync complete: added=%d removed=%d thumbs=%d duration=%.2fs", - added, removed, thumbs_generated, duration, + "Sync complete: added=%d updated=%d removed=%d thumbs=%d duration=%.2fs", + added, updated, removed, thumbs_generated, duration, ) return { "added": added, + "updated": updated, "removed": removed, "thumbs_generated": thumbs_generated, "duration_sec": duration,