A Transparent and Verifiable Way to Sync the AT Protocol's PLC Directory

update

+31 -12
+24 -8
bundle/manager.go
··· 120 120 121 121 config.Logger.Printf("Using %d workers for parallel scan", workers) 122 122 123 - // Create progress callback wrapper 124 - var progressCallback func(current, total int) 123 + // Create progress callback wrapper with new signature 124 + var progressCallback func(current, total int, bytesProcessed int64) 125 125 if config.RebuildProgress != nil { 126 - progressCallback = config.RebuildProgress 126 + // Wrap the old-style callback to work with new signature 127 + oldCallback := config.RebuildProgress 128 + progressCallback = func(current, total int, bytesProcessed int64) { 129 + oldCallback(current, total) 130 + } 131 + } else { 132 + // Default: log every 100 bundles 133 + progressCallback = func(current, total int, bytesProcessed int64) { 134 + if current%100 == 0 || current == total { 135 + mbProcessed := float64(bytesProcessed) / (1024 * 1024) 136 + config.Logger.Printf("Rebuild progress: %d/%d bundles (%.1f%%), %.1f MB processed", 137 + current, total, float64(current)/float64(total)*100, mbProcessed) 138 + } 139 + } 127 140 } 128 141 129 142 start := time.Now() ··· 808 821 } 809 822 810 823 // ScanDirectoryParallel scans the bundle directory in parallel and rebuilds the index 811 - func (m *Manager) ScanDirectoryParallel(workers int, progressCallback func(current, total int)) (*DirectoryScanResult, error) { 824 + func (m *Manager) ScanDirectoryParallel(workers int, progressCallback func(current, total int, bytesProcessed int64)) (*DirectoryScanResult, error) { 812 825 result := &DirectoryScanResult{ 813 826 BundleDir: m.config.BundleDir, 814 827 } ··· 915 928 close(results) 916 929 }() 917 930 931 + // Collect results (in a map first, then sort) 918 932 metadataMap := make(map[int]*BundleMetadata) 919 933 var totalSize int64 920 934 var totalUncompressed int64 ··· 923 937 for result := range results { 924 938 processed++ 925 939 926 - // Update progress with bytes 940 + // Update progress WITH bytes 927 941 if progressCallback != nil { 928 - progressCallback(processed, len(bundleNumbers)) 942 + if result.meta != nil { 943 + totalUncompressed += result.meta.UncompressedSize 944 + } 945 + progressCallback(processed, len(bundleNumbers), totalUncompressed) 929 946 } 930 947 931 948 if result.err != nil { ··· 934 951 } 935 952 metadataMap[result.index] = result.meta 936 953 totalSize += result.meta.CompressedSize 937 - totalUncompressed += result.meta.UncompressedSize 938 954 } 939 955 940 956 // Build ordered metadata slice and calculate chain hashes ··· 961 977 } 962 978 963 979 result.TotalSize = totalSize 964 - result.TotalUncompressed = totalUncompressed // NEW 980 + result.TotalUncompressed = totalUncompressed 965 981 966 982 // Rebuild index 967 983 m.index.Rebuild(newMetadata)
+7 -4
cmd/plcbundle/main.go
··· 304 304 305 305 // Create progress bar 306 306 var progress *ProgressBar 307 - var progressCallback func(int, int) 307 + var progressCallback func(int, int, int64) 308 308 309 309 if !*noProgress { 310 + fmt.Println("Processing bundles:") 310 311 progress = NewProgressBar(len(files)) 311 - progressCallback = func(current, total int) { 312 - progress.Set(current) 312 + progress.showBytes = true // Enable byte tracking 313 + 314 + progressCallback = func(current, total int, bytesProcessed int64) { 315 + progress.SetWithBytes(current, bytesProcessed) 313 316 } 314 - fmt.Println("Processing bundles:") 315 317 } 316 318 317 319 // Use parallel scan 318 320 result, err := mgr.ScanDirectoryParallel(*workers, progressCallback) 321 + 319 322 if err != nil { 320 323 if progress != nil { 321 324 progress.Finish()