2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-28 15:56:37 +00:00

Save UID and GID as integer in Snapshot

This commit is contained in:
Alexander Neumann 2014-12-21 17:20:49 +01:00
parent 2fd29dd5f6
commit 5eaa427e80
3 changed files with 23 additions and 8 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -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")