performCleanup method

  1. @override
Future<void> performCleanup()
override

Performs cleanup of orphaned files

Implementation

@override
Future<void> performCleanup() async {
  await _ensureInitialized();

  debugPrint('UnifiedModelManager: Performing cleanup');

  try {
    // 1. Get protected files from ModelRepository
    final protectedFiles = await _getAllProtectedFiles();

    // 2. Enhanced file system cleanup
    await ModelFileSystemManager.cleanupOrphanedFiles(
      protectedFiles: protectedFiles,
      enableResumeDetection: true,
    );

    // 3. Background_downloader cleanup
    final downloader = FileDownloader();
    await downloader.reset(group: 'flutter_gemma_downloads');

    debugPrint('UnifiedModelManager: Cleanup completed');
  } catch (e) {
    debugPrint('UnifiedModelManager: Cleanup failed: $e');
    // Don't rethrow - cleanup failures should not break the app
  }
}