mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 19:38:57 +00:00
Backup and restore setuid/setgid/sticky bits
A user discovered that restic does not restore setuid/setgid/sticky file attributes. This commit fixes that. The mode is stored in the Go format as an uint32: https://golang.org/pkg/os/#FileMode
This commit is contained in:
parent
55d9c5f80c
commit
f49cb62812
3
node.go
3
node.go
@ -67,10 +67,11 @@ func (node Node) Tree() *Tree {
|
||||
|
||||
// NodeFromFileInfo returns a new node from the given path and FileInfo.
|
||||
func NodeFromFileInfo(path string, fi os.FileInfo) (*Node, error) {
|
||||
mask := os.ModePerm | os.ModeType | os.ModeSetuid | os.ModeSetgid | os.ModeSticky
|
||||
node := &Node{
|
||||
path: path,
|
||||
Name: fi.Name(),
|
||||
Mode: fi.Mode() & (os.ModePerm | os.ModeType),
|
||||
Mode: fi.Mode() & mask,
|
||||
ModTime: fi.ModTime(),
|
||||
}
|
||||
|
||||
|
39
node_test.go
39
node_test.go
@ -83,13 +83,46 @@ var nodeTests = []restic.Node{
|
||||
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||
},
|
||||
restic.Node{
|
||||
Name: "testSuidFile",
|
||||
Type: "file",
|
||||
Content: []backend.ID{},
|
||||
UID: uint32(os.Getuid()),
|
||||
GID: uint32(os.Getgid()),
|
||||
Mode: 0755 | os.ModeSetuid,
|
||||
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
||||
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||
},
|
||||
restic.Node{
|
||||
Name: "testSuidFile2",
|
||||
Type: "file",
|
||||
Content: []backend.ID{},
|
||||
UID: uint32(os.Getuid()),
|
||||
GID: uint32(os.Getgid()),
|
||||
Mode: 0755 | os.ModeSetgid,
|
||||
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
||||
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||
},
|
||||
restic.Node{
|
||||
Name: "testSticky",
|
||||
Type: "file",
|
||||
Content: []backend.ID{},
|
||||
UID: uint32(os.Getuid()),
|
||||
GID: uint32(os.Getgid()),
|
||||
Mode: 0755 | os.ModeSticky,
|
||||
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
||||
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||
},
|
||||
restic.Node{
|
||||
Name: "testDir",
|
||||
Type: "dir",
|
||||
Subtree: nil,
|
||||
UID: uint32(os.Getuid()),
|
||||
GID: uint32(os.Getgid()),
|
||||
Mode: 020000000750,
|
||||
Mode: 0750 | os.ModeDir,
|
||||
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
||||
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||
@ -100,7 +133,7 @@ var nodeTests = []restic.Node{
|
||||
LinkTarget: "invalid",
|
||||
UID: uint32(os.Getuid()),
|
||||
GID: uint32(os.Getgid()),
|
||||
Mode: 01000000777,
|
||||
Mode: 0777 | os.ModeSymlink,
|
||||
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
||||
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||
@ -150,7 +183,7 @@ func TestNodeRestoreAt(t *testing.T) {
|
||||
"%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
|
||||
if test.Type != "symlink" {
|
||||
Assert(t, test.Mode == n2.Mode,
|
||||
"%v: mode doesn't match (%v != %v)", test.Type, test.Mode, n2.Mode)
|
||||
"%v: mode doesn't match (0%o != 0%o)", test.Type, test.Mode, n2.Mode)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user