mirror of
https://github.com/restic/restic.git
synced 2026-11-21 13:02:42 +00:00
fs: fall back to numeric ids when --ownership-by-name lookup fails (#22185)
Signed-off-by: Dean Chen <862469039@qq.com>
This commit is contained in:
1 parent
2126756613
commit
5cda063cbb
5 files changed
+89
-27
No files matched your search
@@ -3,19 +3,32 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/restic/restic/internal/data"
|
||||
)
|
||||
|
||||
func lchown(name string, node *data.Node, lookupByName bool) error {
|
||||
var uid, gid uint32
|
||||
func lchown(name string, node *data.Node, lookupByName bool, warn func(msg string)) error {
|
||||
uid := node.UID
|
||||
gid := node.GID
|
||||
if lookupByName {
|
||||
uid = lookupUid(node.User)
|
||||
gid = lookupGid(node.Group)
|
||||
} else {
|
||||
uid = node.UID
|
||||
gid = node.GID
|
||||
// Fall back to the numeric ids stored in the snapshot if a name is
|
||||
// missing or cannot be resolved on this host.
|
||||
if node.User != "" {
|
||||
if id, ok := lookupUid(node.User); ok {
|
||||
uid = id
|
||||
} else if warn != nil {
|
||||
warn(fmt.Sprintf("cannot resolve user %q for %v, using uid %d", node.User, name, uid))
|
||||
}
|
||||
}
|
||||
if node.Group != "" {
|
||||
if id, ok := lookupGid(node.Group); ok {
|
||||
gid = id
|
||||
} else if warn != nil {
|
||||
warn(fmt.Sprintf("cannot resolve group %q for %v, using gid %d", node.Group, name, gid))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return os.Lchown(name, int(uid), int(gid))
|
||||
|
||||
Reference in new issue
Block a user