66 "os/exec"
77 "path/filepath"
88
9- log "github.com/sirupsen/logrus"
9+ log "github.com/sirupsen/logrus"
1010)
1111
1212// Mirror creates a writable mirror of srcDir in a temp directory.
@@ -15,7 +15,7 @@ import (
1515//
1616// Note: this requires the "rsync" binary to be installed and in PATH.
1717func Mirror (srcDir string ) (mirrorDir string , cleanup func () error , err error ) {
18- log .Infof ("Mirror: creating temp dir for %q" , srcDir )
18+ log .Infof ("Mirror: creating temp dir for %q" , srcDir )
1919
2020 mp , err := os .MkdirTemp ("" , "rsync-mirror-" )
2121 if err != nil {
@@ -27,12 +27,29 @@ func Mirror(srcDir string) (mirrorDir string, cleanup func() error, err error) {
2727 mirrorPath := filepath .Clean (mp ) + string (os .PathSeparator )
2828 log .Infof ("Mirror: rsync from %s to %s (no squash/)" , srcPath , mirrorPath )
2929
30- // Setup mirror but skip squash/ dir
31- cmd := exec .Command ("rsync" ,
32- "-a" ,
33- "--exclude=squash/" ,
34- srcPath , mirrorPath ,
35- )
30+ // Define PodmanOverlay file and directory patterns for mirror
31+ allowedPatterns := []string {
32+ "overlay/***" ,
33+ "overlay-containers/***" ,
34+ "overlay-images/***" ,
35+ "overlay-layers/***" ,
36+ "storage.lock" ,
37+ "userns.lock" ,
38+ }
39+
40+ includePatterns := []string {}
41+ for _ , pattern := range allowedPatterns {
42+ includePatterns = append (includePatterns , fmt .Sprintf ("--include=%s" , pattern ))
43+ }
44+
45+ rsyncArgs := append ([]string {"-a" }, includePatterns ... )
46+ rsyncArgs = append (rsyncArgs , "--exclude=*" , "--delete" )
47+
48+ log .Infof ("Mirror setup: rsync from %s to %s" , srcPath , mirrorPath )
49+ rsyncCmd := append (rsyncArgs , srcPath , mirrorPath )
50+ log .Infof (" rsync args %v" , rsyncCmd )
51+ cmd := exec .Command ("rsync" , rsyncCmd ... )
52+
3653 if out , err2 := cmd .CombinedOutput (); err2 != nil {
3754 os .RemoveAll (mp )
3855 return "" , nil , fmt .Errorf ("Initial rsync failed: %v\n %s" , err2 , out )
@@ -57,13 +74,10 @@ func Mirror(srcDir string) (mirrorDir string, cleanup func() error, err error) {
5774 return fmt .Errorf ("Failed to remove squash symlink: %w" , err )
5875 }
5976
60- log .Infof ("Mirror-cleanup: rsync back from %s to %s (excluding squash/)" , mirrorPath , srcPath )
61- cmdBack := exec .Command ("rsync" ,
62- "-a" ,
63- "--exclude=squash/" ,
64- "--delete" ,
65- mirrorPath , srcPath ,
66- )
77+ log .Infof ("Mirror-cleanup: rsync back from %s to %s" , mirrorPath , srcPath )
78+ rsyncCmd = append (rsyncArgs , mirrorPath , srcPath )
79+ cmdBack := exec .Command ("rsync" , rsyncCmd ... )
80+
6781 if out , err2 := cmdBack .CombinedOutput (); err2 != nil {
6882 return fmt .Errorf ("rsync back failed: %v\n %s" , err2 , out )
6983 }
0 commit comments