mirror of
https://github.com/octoleo/restic.git
synced 2024-11-25 14:17:42 +00:00
dump: test proper permissions and directory name
This commit is contained in:
parent
1e3c9a2c11
commit
fe09e6f865
@ -9,6 +9,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -68,6 +69,14 @@ func TestWriteTar(t *testing.T) {
|
||||
},
|
||||
target: "/",
|
||||
},
|
||||
{
|
||||
name: "file and symlink in root",
|
||||
args: archiver.TestDir{
|
||||
"file1": archiver.TestFile{Content: "string"},
|
||||
"file2": archiver.TestSymlink{Target: "file1"},
|
||||
},
|
||||
target: "/",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@ -128,7 +137,7 @@ func checkTar(t *testing.T, testDir string, srcTar *bytes.Buffer) error {
|
||||
}
|
||||
|
||||
matchPath := filepath.Join(testDir, hdr.Name)
|
||||
match, err := os.Stat(matchPath)
|
||||
match, err := os.Lstat(matchPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -140,6 +149,10 @@ func checkTar(t *testing.T, testDir string, srcTar *bytes.Buffer) error {
|
||||
return fmt.Errorf("modTime does not match, got: %s, want: %s", fileTime, tarTime)
|
||||
}
|
||||
|
||||
if os.FileMode(hdr.Mode).Perm() != match.Mode().Perm() || os.FileMode(hdr.Mode)&^os.ModePerm != 0 {
|
||||
return fmt.Errorf("mode does not match, got: %v, want: %v", os.FileMode(hdr.Mode), match.Mode())
|
||||
}
|
||||
|
||||
if hdr.Typeflag == tar.TypeDir {
|
||||
// this is a folder
|
||||
if hdr.Name == "." {
|
||||
@ -151,7 +164,17 @@ func checkTar(t *testing.T, testDir string, srcTar *bytes.Buffer) error {
|
||||
if filepath.Base(hdr.Name) != filebase {
|
||||
return fmt.Errorf("foldernames don't match got %v want %v", filepath.Base(hdr.Name), filebase)
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(hdr.Name, "/") {
|
||||
return fmt.Errorf("foldernames must end with separator got %v", hdr.Name)
|
||||
}
|
||||
} else if hdr.Typeflag == tar.TypeSymlink {
|
||||
target, err := fs.Readlink(matchPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if target != hdr.Linkname {
|
||||
return fmt.Errorf("symlink target does not match, got %s want %s", target, hdr.Linkname)
|
||||
}
|
||||
} else {
|
||||
if match.Size() != hdr.Size {
|
||||
return fmt.Errorf("size does not match got %v want %v", hdr.Size, match.Size())
|
||||
|
Loading…
Reference in New Issue
Block a user