diff --git a/snapshot.go b/snapshot.go index 838303ff8..87c9ae176 100644 --- a/snapshot.go +++ b/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,20 +40,9 @@ 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) - 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) + err = sn.fillUserInfo() + if err != nil { + return nil, err } return sn, nil diff --git a/snapshot_darwin.go b/snapshot_darwin.go new file mode 100644 index 000000000..ae1eaa3b9 --- /dev/null +++ b/snapshot_darwin.go @@ -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 +} diff --git a/snapshot_linux.go b/snapshot_linux.go new file mode 100644 index 000000000..ae1eaa3b9 --- /dev/null +++ b/snapshot_linux.go @@ -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 +} diff --git a/snapshot_windows.go b/snapshot_windows.go new file mode 100644 index 000000000..8c0068808 --- /dev/null +++ b/snapshot_windows.go @@ -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 +}