Skip to content

Commit

Permalink
cmd/sync: execute chmod after chown to avoid setuid setgid failure (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro authored Feb 23, 2024
1 parent 1a2b6d4 commit 41eb6f6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down

0 comments on commit 41eb6f6

Please sign in to comment.