From 0700c32400bab0bfa79743c3396f31a307367ca1 Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 24 Dec 2021 00:02:00 +0100 Subject: [PATCH] Fix calculating path for copying ownership --- pkg/util/fs_util.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 5a6be2f099..6fbe84baa3 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -905,7 +905,7 @@ func CopyFileOrSymlink(src string, destDir string, root string) error { if err != nil { return errors.Wrap(err, "copying file") } - err = CopyOwnership(src, destDir) + err = CopyOwnership(src, destDir, root) if err != nil { return errors.Wrap(err, "copying ownership") } @@ -913,7 +913,7 @@ func CopyFileOrSymlink(src string, destDir string, root string) error { } // CopyOwnership copies the file or directory ownership recursively at src to dest -func CopyOwnership(src string, destDir string) error { +func CopyOwnership(src string, destDir string, root string) error { return filepath.Walk(src, func(path string, info os.FileInfo, err error) error { if err != nil { return err @@ -921,7 +921,7 @@ func CopyOwnership(src string, destDir string) error { if IsSymlink(info) { return nil } - relPath, err := filepath.Rel(filepath.Dir(src), path) + relPath, err := filepath.Rel(root, src) if err != nil { return err } @@ -955,9 +955,7 @@ func CopyOwnership(src string, destDir string) error { return errors.Wrap(err, "reading ownership") } stat := info.Sys().(*syscall.Stat_t) - err = os.Chown(destPath, int(stat.Uid), int(stat.Gid)) - - return nil + return os.Chown(destPath, int(stat.Uid), int(stat.Gid)) }) }