forked from TrueCloudLab/restic
Introduce UserID, GroupID for snapshot
Use the fields UID and GID for Unix user and group ID, and the fields UserID and GroupID for Windows user and group strings.
This commit is contained in:
parent
d1fee28ae5
commit
bb777d9a58
4 changed files with 77 additions and 16 deletions
17
snapshot.go
17
snapshot.go
|
@ -3,9 +3,7 @@ package restic
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/backend"
|
||||
|
@ -20,6 +18,8 @@ type Snapshot struct {
|
|||
Username string `json:"username,omitempty"`
|
||||
UID uint32 `json:"uid,omitempty"`
|
||||
GID uint32 `json:"gid,omitempty"`
|
||||
UserID string `json:"userid,omitempty"`
|
||||
GroupID string `json:"groupid,omitempty"`
|
||||
|
||||
id backend.ID // plaintext ID, used during restore
|
||||
}
|
||||
|
@ -40,21 +40,10 @@ func NewSnapshot(dir string) (*Snapshot, error) {
|
|||
sn.Hostname = hn
|
||||
}
|
||||
|
||||
usr, err := user.Current()
|
||||
if err == nil {
|
||||
sn.Username = usr.Username
|
||||
uid, err := strconv.ParseInt(usr.Uid, 10, 32)
|
||||
err = sn.fillUserInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sn.UID = uint32(uid)
|
||||
|
||||
gid, err := strconv.ParseInt(usr.Gid, 10, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sn.GID = uint32(gid)
|
||||
}
|
||||
|
||||
return sn, nil
|
||||
}
|
||||
|
|
28
snapshot_darwin.go
Normal file
28
snapshot_darwin.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package restic
|
||||
|
||||
import (
|
||||
"os/user"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (sn *Snapshot) fillUserInfo() error {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sn.Username = usr.Username
|
||||
uid, err := strconv.ParseInt(usr.Uid, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sn.UID = uint32(uid)
|
||||
|
||||
gid, err := strconv.ParseInt(usr.Gid, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sn.GID = uint32(gid)
|
||||
|
||||
return nil
|
||||
}
|
28
snapshot_linux.go
Normal file
28
snapshot_linux.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package restic
|
||||
|
||||
import (
|
||||
"os/user"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (sn *Snapshot) fillUserInfo() error {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sn.Username = usr.Username
|
||||
uid, err := strconv.ParseInt(usr.Uid, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sn.UID = uint32(uid)
|
||||
|
||||
gid, err := strconv.ParseInt(usr.Gid, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sn.GID = uint32(gid)
|
||||
|
||||
return nil
|
||||
}
|
16
snapshot_windows.go
Normal file
16
snapshot_windows.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package restic
|
||||
|
||||
import "os/user"
|
||||
|
||||
func (sn *Snapshot) fillUserInfo() error {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sn.Username = usr.Username
|
||||
sn.UserID = usr.Uid
|
||||
sn.GroupID = usr.Gid
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in a new issue