From bb777d9a58baf844a0e868a1fe6ddbc1b0dee14d Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Tue, 3 Feb 2015 22:04:09 +0100 Subject: [PATCH] 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. --- snapshot.go | 21 +++++---------------- snapshot_darwin.go | 28 ++++++++++++++++++++++++++++ snapshot_linux.go | 28 ++++++++++++++++++++++++++++ snapshot_windows.go | 16 ++++++++++++++++ 4 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 snapshot_darwin.go create mode 100644 snapshot_linux.go create mode 100644 snapshot_windows.go 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 +}