Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep previous behavior for persistent binded paths #1984

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions pkg/action/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,14 @@ func MountBindPath(cfg *v1.RunConfig, sysroot, overlayDir, path string) error {
pathName := strings.ReplaceAll(trimmed, "/", "-") + ".bind"
stateDir := fmt.Sprintf("%s/%s", overlayDir, pathName)

// Only sync data once, otherwise it could modify persistent data from a previous boot
if ok, _ := utils.Exists(cfg.Fs, stateDir); !ok {
if err := utils.MkdirAll(cfg.Fs, stateDir, constants.DirPerm); err != nil {
cfg.Logger.Errorf("Error creating upperdir %s: %s", stateDir, err.Error())
return err
}
if err := utils.MkdirAll(cfg.Fs, stateDir, constants.DirPerm); err != nil {
cfg.Logger.Errorf("Error creating upperdir %s: %s", stateDir, err.Error())
return err
}

if err := utils.SyncData(cfg.Logger, cfg.Runner, cfg.Fs, base, stateDir); err != nil {
cfg.Logger.Errorf("Error shuffling data: %s", err.Error())
return err
}
if err := utils.SyncData(cfg.Logger, cfg.Runner, cfg.Fs, base, stateDir); err != nil {
cfg.Logger.Errorf("Error shuffling data: %s", err.Error())
return err
}

if err := cfg.Mounter.Mount(stateDir, base, "none", []string{"defaults", "bind"}); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/elemental/elemental.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func DumpSource(c v1.Config, target string, imgSrc *v1.ImageSource) error { // n
imgSrc.SetDigest(digest)
} else if imgSrc.IsDir() {
excludes := cnst.GetDefaultSystemExcludes()
err = utils.SyncData(c.Logger, c.Runner, c.Fs, imgSrc.Value(), target, excludes...)
err = utils.MirrorData(c.Logger, c.Runner, c.Fs, imgSrc.Value(), target, excludes...)
if err != nil {
return err
}
Expand All @@ -512,7 +512,7 @@ func DumpSource(c v1.Config, target string, imgSrc *v1.ImageSource) error { // n
return err
}
defer UnmountFileSystemImage(c, img) // nolint:errcheck
err = utils.SyncData(c.Logger, c.Runner, c.Fs, cnst.ImgSrcDir, target)
err = utils.MirrorData(c.Logger, c.Runner, c.Fs, cnst.ImgSrcDir, target)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/snapshotter/btrfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (b *Btrfs) CloseTransaction(snapshot *v1.Snapshot) (err error) {
}

if !b.installing {
err = utils.SyncData(b.cfg.Logger, b.cfg.Runner, b.cfg.Fs, snapshot.WorkDir, snapshot.Path)
err = utils.MirrorData(b.cfg.Logger, b.cfg.Runner, b.cfg.Fs, snapshot.WorkDir, snapshot.Path)
if err != nil {
b.cfg.Logger.Errorf("failed syncing working directory with snapshot directory")
return err
Expand Down
27 changes: 21 additions & 6 deletions pkg/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ func CreateDirStructure(fs v1.FS, target string) error {
// SyncData rsync's source folder contents to a target folder content,
// both are expected to exist before hand.
func SyncData(log v1.Logger, runner v1.Runner, fs v1.FS, source string, target string, excludes ...string) error {
flags := []string{"--progress", "--partial", "--human-readable", "--archive", "--xattrs", "--acls"}
for _, e := range excludes {
flags = append(flags, fmt.Sprintf("--exclude=%s", e))
}

return rsyncWrapper(log, runner, fs, source, target, flags)
}

// MirrorData rsync's source folder contents to a target folder content, in contrast, to SyncData this
// method includes the --delete flag which forces the deletion of files in target that are missing in source.
func MirrorData(log v1.Logger, runner v1.Runner, fs v1.FS, source string, target string, excludes ...string) error {
flags := []string{"--progress", "--partial", "--human-readable", "--archive", "--xattrs", "--acls", "--delete"}
for _, e := range excludes {
flags = append(flags, fmt.Sprintf("--exclude=%s", e))
}

return rsyncWrapper(log, runner, fs, source, target, flags)
}

func rsyncWrapper(log v1.Logger, runner v1.Runner, fs v1.FS, source string, target string, flags []string) error {
if fs != nil {
if s, err := fs.RawPath(source); err == nil {
source = s
Expand All @@ -175,12 +195,7 @@ func SyncData(log v1.Logger, runner v1.Runner, fs v1.FS, source string, target s

log.Infof("Starting rsync...")

args := []string{"--progress", "--partial", "--human-readable", "--archive", "--xattrs", "--acls", "--delete"}
for _, e := range excludes {
args = append(args, fmt.Sprintf("--exclude=%s", e))
}

args = append(args, source, target)
args := append(flags, source, target)

done := displayProgress(log, 5*time.Second, "Syncing data...")

Expand Down
Loading