diff --git a/pkg/sync/sync.go b/pkg/sync/sync.go index c0c676f66491..d48751a9a186 100644 --- a/pkg/sync/sync.go +++ b/pkg/sync/sync.go @@ -223,14 +223,15 @@ func copyPerms(dst object.ObjectStorage, obj object.Object, config *Config) { start := time.Now() key := obj.Key() fi := obj.(object.File) + // chmod needs to be executed after chown, because chown will change setuid setgid to be invalid. + if err := dst.(object.FileSystem).Chown(key, fi.Owner(), fi.Group()); err != nil { + logger.Warnf("Chown %s to (%s,%s): %s", key, fi.Owner(), fi.Group(), err) + } if !fi.IsSymlink() || !config.Links { if err := dst.(object.FileSystem).Chmod(key, fi.Mode()); err != nil { logger.Warnf("Chmod %s to %o: %s", key, fi.Mode(), err) } } - if err := dst.(object.FileSystem).Chown(key, fi.Owner(), fi.Group()); err != nil { - logger.Warnf("Chown %s to (%s,%s): %s", key, fi.Owner(), fi.Group(), err) - } logger.Debugf("Copied permissions (%s:%s:%s) for %s in %s", fi.Owner(), fi.Group(), fi.Mode(), key, time.Since(start)) }