44import signal
55import sys
66import time
7+ from datetime import datetime
78from pathlib import Path
89
910import click
@@ -65,9 +66,21 @@ def index(paths: list[Path], pattern: str, persist_dir: Path):
6566 for doc in existing_docs :
6667 if "source" in doc .metadata :
6768 abs_path = os .path .abspath (doc .metadata ["source" ])
68- mtime = doc .metadata .get ("mtime" , 0 )
69- existing_files [abs_path ] = mtime
70- logger .debug ("Existing file: %s (mtime: %s)" , abs_path , mtime )
69+ last_modified = doc .metadata .get ("last_modified" )
70+ if last_modified :
71+ try :
72+ # Parse ISO format timestamp to float
73+ existing_files [abs_path ] = datetime .fromisoformat (
74+ last_modified
75+ ).timestamp ()
76+ except ValueError :
77+ logger .warning (
78+ "Invalid last_modified format: %s" , last_modified
79+ )
80+ existing_files [abs_path ] = 0
81+ else :
82+ existing_files [abs_path ] = 0
83+ # logger.debug("Existing file: %s", abs_path) # Too spammy
7184
7285 logger .debug ("Loaded %d existing files from index" , len (existing_files ))
7386
@@ -91,13 +104,15 @@ def index(paths: list[Path], pattern: str, persist_dir: Path):
91104 abs_source = os .path .abspath (source )
92105 doc .metadata ["source" ] = abs_source
93106 current_mtime = os .path .getmtime (abs_source )
94- doc .metadata ["mtime" ] = current_mtime
95107
96108 # Include if file is new or modified
97109 if abs_source not in existing_files :
98110 logger .debug ("New file: %s" , abs_source )
99111 filtered_documents .append (doc )
100- elif current_mtime > existing_files [abs_source ]:
112+ # Round to microseconds (6 decimal places) for comparison
113+ elif round (current_mtime , 6 ) > round (
114+ existing_files [abs_source ], 6
115+ ):
101116 logger .debug (
102117 "Modified file: %s (current: %s, stored: %s)" ,
103118 abs_source ,
0 commit comments