forked from TrueCloudLab/restic
Merge pull request #1993 from rfjakob/lchown
restore: suppress lchown errors when not running as root
This commit is contained in:
commit
6bc99ce451
2 changed files with 17 additions and 1 deletions
7
changelog/unreleased/issue-1766
Normal file
7
changelog/unreleased/issue-1766
Normal file
|
@ -0,0 +1,7 @@
|
|||
Enhancement: restore: suppress lchown errors when not running as root
|
||||
|
||||
Like "cp" and "rsync" do, restic now only reports errors for changing
|
||||
the ownership of files during restore if it is run as root, on non-Windows
|
||||
operating systems. On Windows, the error is reported as usual.
|
||||
|
||||
https://github.com/restic/restic/issues/1766
|
|
@ -186,8 +186,17 @@ func (node Node) restoreMetadata(path string) error {
|
|||
var firsterr error
|
||||
|
||||
if err := lchown(path, int(node.UID), int(node.GID)); err != nil {
|
||||
// Like "cp -a" and "rsync -a" do, we only report lchown permission errors
|
||||
// if we run as root.
|
||||
// On Windows, Geteuid always returns -1, and we always report lchown
|
||||
// permission errors.
|
||||
if os.Geteuid() > 0 && os.IsPermission(err) {
|
||||
debug.Log("not running as root, ignoring lchown permission error for %v: %v",
|
||||
path, err)
|
||||
} else {
|
||||
firsterr = errors.Wrap(err, "Lchown")
|
||||
}
|
||||
}
|
||||
|
||||
if node.Type != "symlink" {
|
||||
if err := fs.Chmod(path, node.Mode); err != nil {
|
||||
|
|
Loading…
Reference in a new issue