mirror of
https://github.com/octoleo/restic.git
synced 2024-11-25 06:07:44 +00:00
Save UID and GID as integer in Snapshot
This commit is contained in:
parent
2fd29dd5f6
commit
5eaa427e80
@ -513,7 +513,11 @@ func (arch *Archiver) Snapshot(dir string, t *Tree, parentSnapshot backend.ID) (
|
|||||||
// reset global stats
|
// reset global stats
|
||||||
arch.updateStats = Stats{}
|
arch.updateStats = Stats{}
|
||||||
|
|
||||||
sn := NewSnapshot(dir)
|
sn, err := NewSnapshot(dir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
sn.Parent = parentSnapshot
|
sn.Parent = parentSnapshot
|
||||||
|
|
||||||
blob, err := arch.saveTree(t)
|
blob, err := arch.saveTree(t)
|
||||||
|
22
snapshot.go
22
snapshot.go
@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
@ -18,14 +19,14 @@ type Snapshot struct {
|
|||||||
Dir string `json:"dir"`
|
Dir string `json:"dir"`
|
||||||
Hostname string `json:"hostname,omitempty"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
UID string `json:"uid,omitempty"`
|
UID uint32 `json:"uid,omitempty"`
|
||||||
GID string `json:"gid,omitempty"`
|
GID uint32 `json:"gid,omitempty"`
|
||||||
|
|
||||||
id backend.ID // plaintext ID, used during restore
|
id backend.ID // plaintext ID, used during restore
|
||||||
bl *BlobList
|
bl *BlobList
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSnapshot(dir string) *Snapshot {
|
func NewSnapshot(dir string) (*Snapshot, error) {
|
||||||
d, err := filepath.Abs(dir)
|
d, err := filepath.Abs(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d = dir
|
d = dir
|
||||||
@ -44,11 +45,20 @@ func NewSnapshot(dir string) *Snapshot {
|
|||||||
usr, err := user.Current()
|
usr, err := user.Current()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
sn.Username = usr.Username
|
sn.Username = usr.Username
|
||||||
sn.UID = usr.Uid
|
uid, err := strconv.ParseInt(usr.Uid, 10, 32)
|
||||||
sn.GID = usr.Gid
|
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) {
|
func LoadSnapshot(ch *ContentHandler, id backend.ID) (*Snapshot, error) {
|
||||||
|
@ -10,7 +10,8 @@ import (
|
|||||||
|
|
||||||
func testSnapshot(t *testing.T, be backend.Server) {
|
func testSnapshot(t *testing.T, be backend.Server) {
|
||||||
var err error
|
var err error
|
||||||
sn := restic.NewSnapshot("/home/foobar")
|
sn, err := restic.NewSnapshot("/home/foobar")
|
||||||
|
ok(t, err)
|
||||||
sn.Tree, err = backend.ParseID("c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2")
|
sn.Tree, err = backend.ParseID("c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2")
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
sn.Time, err = time.Parse(time.RFC3339Nano, "2014-08-03T17:49:05.378595539+02:00")
|
sn.Time, err = time.Parse(time.RFC3339Nano, "2014-08-03T17:49:05.378595539+02:00")
|
||||||
|
Loading…
Reference in New Issue
Block a user