diff --git a/archiver.go b/archiver.go index 06037183c..caa66e5a8 100644 --- a/archiver.go +++ b/archiver.go @@ -513,7 +513,11 @@ func (arch *Archiver) Snapshot(dir string, t *Tree, parentSnapshot backend.ID) ( // reset global stats arch.updateStats = Stats{} - sn := NewSnapshot(dir) + sn, err := NewSnapshot(dir) + if err != nil { + return nil, nil, err + } + sn.Parent = parentSnapshot blob, err := arch.saveTree(t) diff --git a/snapshot.go b/snapshot.go index ddda498b4..9548d616e 100644 --- a/snapshot.go +++ b/snapshot.go @@ -5,6 +5,7 @@ import ( "os" "os/user" "path/filepath" + "strconv" "time" "github.com/restic/restic/backend" @@ -18,14 +19,14 @@ type Snapshot struct { Dir string `json:"dir"` Hostname string `json:"hostname,omitempty"` Username string `json:"username,omitempty"` - UID string `json:"uid,omitempty"` - GID string `json:"gid,omitempty"` + UID uint32 `json:"uid,omitempty"` + GID uint32 `json:"gid,omitempty"` id backend.ID // plaintext ID, used during restore bl *BlobList } -func NewSnapshot(dir string) *Snapshot { +func NewSnapshot(dir string) (*Snapshot, error) { d, err := filepath.Abs(dir) if err != nil { d = dir @@ -44,11 +45,20 @@ func NewSnapshot(dir string) *Snapshot { usr, err := user.Current() if err == nil { sn.Username = usr.Username - sn.UID = usr.Uid - sn.GID = usr.Gid + 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) } - return sn + return sn, nil } func LoadSnapshot(ch *ContentHandler, id backend.ID) (*Snapshot, error) { diff --git a/snapshot_test.go b/snapshot_test.go index a2c0d0958..fd441d0a7 100644 --- a/snapshot_test.go +++ b/snapshot_test.go @@ -10,7 +10,8 @@ import ( func testSnapshot(t *testing.T, be backend.Server) { var err error - sn := restic.NewSnapshot("/home/foobar") + sn, err := restic.NewSnapshot("/home/foobar") + ok(t, err) sn.Tree, err = backend.ParseID("c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2") ok(t, err) sn.Time, err = time.Parse(time.RFC3339Nano, "2014-08-03T17:49:05.378595539+02:00")