@@ -190,31 +190,10 @@ def get_config_path(self):
190190
191191 def get_scip_index_path (self ):
192192 """Get the path to the SCIP index file"""
193- try :
194- path = os .path .join (self .settings_path , SCIP_INDEX_FILE )
195- # Ensure directory exists
196- os .makedirs (os .path .dirname (path ), exist_ok = True )
197- return path
198- except Exception :
199- # If error occurs, use file in project or home directory as fallback
200- if self .base_path and os .path .exists (self .base_path ):
201- return os .path .join (self .base_path , SCIP_INDEX_FILE )
202- else :
203- return os .path .join (os .path .expanduser ("~" ), SCIP_INDEX_FILE )
204-
205- def get_index_path (self ):
206- """Get the path to the legacy index file (for backward compatibility)"""
207- try :
208- path = os .path .join (self .settings_path , INDEX_FILE )
209- # Ensure directory exists
210- os .makedirs (os .path .dirname (path ), exist_ok = True )
211- return path
212- except Exception :
213- # If error occurs, use file in project or home directory as fallback
214- if self .base_path and os .path .exists (self .base_path ):
215- return os .path .join (self .base_path , INDEX_FILE )
216- else :
217- return os .path .join (os .path .expanduser ("~" ), INDEX_FILE )
193+ path = os .path .join (self .settings_path , SCIP_INDEX_FILE )
194+ # Ensure directory exists
195+ os .makedirs (os .path .dirname (path ), exist_ok = True )
196+ return path
218197
219198 # get_cache_path method removed - no longer needed with new indexing system
220199
@@ -471,110 +450,47 @@ def load_scip_index(self):
471450
472451 # save_cache and load_cache methods removed - no longer needed with new indexing system
473452
474- def detect_index_version (self ):
475- """Detect the version of the existing index
476-
453+ def is_latest_index (self ) -> bool :
454+ """Check if SCIP index exists and is the latest version.
455+
477456 Returns:
478- str: Version string ('legacy', '3.0', or None if no index exists)
457+ bool: True if latest SCIP index exists, False if needs rebuild
479458 """
480459 try :
481- # Check for new JSON format first
482- index_path = self .get_index_path ()
483- if os .path .exists (index_path ):
484- try :
485- with open (index_path , 'r' , encoding = 'utf-8' ) as f :
486- index_data = json .load (f )
487-
488- # Check if it has the new structure
489- if isinstance (index_data , dict ) and 'index_metadata' in index_data :
490- version = index_data .get ('index_metadata' , {}).get ('version' , '3.0' )
491- return version
492- else :
493- return 'legacy'
494- except (json .JSONDecodeError , UnicodeDecodeError ):
495- return 'legacy'
496-
497- # Check for old pickle format
498- old_pickle_path = os .path .join (self .settings_path , "file_index.pickle" )
499- if os .path .exists (old_pickle_path ):
500- return 'legacy'
501-
502- # Check fallback locations
503- if self .base_path and os .path .exists (self .base_path ):
504- fallback_json = os .path .join (self .base_path , INDEX_FILE )
505- fallback_pickle = os .path .join (self .base_path , "file_index.pickle" )
506- else :
507- fallback_json = os .path .join (os .path .expanduser ("~" ), INDEX_FILE )
508- fallback_pickle = os .path .join (os .path .expanduser ("~" ), "file_index.pickle" )
509-
510- if os .path .exists (fallback_json ):
511- try :
512- with open (fallback_json , 'r' , encoding = 'utf-8' ) as f :
513- index_data = json .load (f )
514- if isinstance (index_data , dict ) and 'index_metadata' in index_data :
515- version = index_data .get ('index_metadata' , {}).get ('version' , '3.0' )
516- return version
517- else :
518- return 'legacy'
519- except Exception :
520- return 'legacy'
521-
522- if os .path .exists (fallback_pickle ):
523- return 'legacy'
524-
525- return None
526-
460+ # Only check for SCIP index at settings_path
461+ scip_path = os .path .join (self .settings_path , SCIP_INDEX_FILE )
462+
463+ if not os .path .exists (scip_path ):
464+ return False
465+
466+ # Basic file integrity check
467+ try :
468+ with open (scip_path , 'rb' ) as f :
469+ # Check if file is readable and has content
470+ return f .read (1 ) != b''
471+ except :
472+ return False
473+
527474 except Exception :
528- return None
529-
530- def migrate_legacy_index (self ):
531- """Migrate legacy index format to new format
475+ return False
532476
533- Returns:
534- bool: True if migration was successful or not needed, False if failed
535- """
477+ def cleanup_legacy_files (self ) -> None :
478+ """Clean up any legacy index files found."""
536479 try :
537- version = self .detect_index_version ()
538-
539- if version is None :
540- return True
541-
542- if version == '3.0' or (isinstance (version , str ) and version >= '3.0' ):
543- return True
544-
545- if version == 'legacy' :
546-
547- # Clean up legacy files
548- legacy_files = [
549- os .path .join (self .settings_path , "file_index.pickle" ),
550- os .path .join (self .settings_path , "content_cache.pickle" )
551- ]
552-
553- # Add fallback locations
554- if self .base_path and os .path .exists (self .base_path ):
555- legacy_files .extend ([
556- os .path .join (self .base_path , "file_index.pickle" ),
557- os .path .join (self .base_path , "content_cache.pickle" )
558- ])
559- else :
560- legacy_files .extend ([
561- os .path .join (os .path .expanduser ("~" ), "file_index.pickle" ),
562- os .path .join (os .path .expanduser ("~" ), "content_cache.pickle" )
563- ])
564-
565- for legacy_file in legacy_files :
566- if os .path .exists (legacy_file ):
567- try :
568- os .remove (legacy_file )
569- except Exception :
570- pass
571-
572- return False # Indicate that manual rebuild is needed
573-
574- return True
575-
480+ legacy_files = [
481+ os .path .join (self .settings_path , "file_index.pickle" ),
482+ os .path .join (self .settings_path , "content_cache.pickle" ),
483+ os .path .join (self .settings_path , INDEX_FILE ) # Legacy JSON
484+ ]
485+
486+ for legacy_file in legacy_files :
487+ if os .path .exists (legacy_file ):
488+ try :
489+ os .remove (legacy_file )
490+ except Exception :
491+ pass
576492 except Exception :
577- return False
493+ pass
578494
579495 def clear (self ):
580496 """Clear config and index files"""
0 commit comments