Skip to content

Commit 7375200

Browse files
committed
Route delta bundle entries using same rules as base bundle
Delta extraction was sending all entries to GradleUserHome, but configuration-cache/ entries need to go to projectDir/.gradle/.
1 parent 5c6247c commit 7375200

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

gradlecache/restore.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ func Restore(ctx context.Context, cfg RestoreConfig) error {
490490
"speed_mbps", fmt.Sprintf("%.1f", float64(dr.n)/dlElapsed.Seconds()/1e6))
491491
}
492492
applyStart := time.Now()
493-
if err := extractTarZstd(ctx, dr.tmpFile, cfg.GradleUserHome); err != nil {
493+
if err := extractDeltaTarZstdRouted(dr.tmpFile, rules, projectDir); err != nil {
494494
return errors.Wrap(err, "extract delta bundle")
495495
}
496496
log.Info("applied delta bundle", "branch", cfg.Branch,
@@ -780,6 +780,32 @@ func extractBundleZstdMultiFrame(ctx context.Context, br *bufio.Reader, dlTiming
780780
}, nil
781781
}
782782

783+
// extractDeltaTarZstdRouted decompresses a delta bundle and extracts it using
784+
// the same routing rules as the base bundle, ensuring delta files land in the
785+
// correct directories (e.g. configuration-cache/ goes to projectDir/.gradle/).
786+
func extractDeltaTarZstdRouted(r io.Reader, rules []extractRule, defaultDir string) error {
787+
br := bufio.NewReaderSize(r, 8<<20)
788+
dec, err := zstd.NewReader(br, zstd.WithDecoderConcurrency(runtime.GOMAXPROCS(0)))
789+
if err != nil {
790+
return errors.Wrap(err, "create zstd decoder")
791+
}
792+
defer dec.Close()
793+
794+
targetFn := func(name string) string {
795+
for _, rule := range rules {
796+
if strings.HasPrefix(name, rule.prefix) {
797+
return filepath.Join(rule.baseDir, name)
798+
}
799+
}
800+
return filepath.Join(defaultDir, name)
801+
}
802+
803+
if err := extractTarPlatformRouted(dec, targetFn, false); err != nil {
804+
return err
805+
}
806+
return drainCompressedReader(br)
807+
}
808+
783809
func extractTarZstd(_ context.Context, r io.Reader, dir string) error {
784810
br := bufio.NewReaderSize(r, 8<<20)
785811
dec, err := zstd.NewReader(br, zstd.WithDecoderConcurrency(runtime.GOMAXPROCS(0)))

0 commit comments

Comments
 (0)