Merge pull request #1948 from giuseppe/use-escaped-name-for-check
dump: use the sanitized path for root check
This commit is contained in:
commit
c923593d5d
|
|
@ -113,7 +113,7 @@ func dumpNode(out io.Writer, added map[string]struct{}, links map[string]int, ve
|
|||
path := sanitizeName(entry.Name)
|
||||
|
||||
parent := filepath.Dir(path)
|
||||
if _, found := added[parent]; !found && entry.Name != "/" {
|
||||
if _, found := added[parent]; !found && path != "/" {
|
||||
parentEntry := &internal.FileMetadata{
|
||||
Name: parent,
|
||||
Type: internal.TypeDir,
|
||||
|
|
|
|||
|
|
@ -62,6 +62,12 @@ func TestDumpNode(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
rootEntry := &internal.FileMetadata{
|
||||
Name: "./",
|
||||
Type: internal.TypeDir,
|
||||
ModTime: &modTime,
|
||||
}
|
||||
|
||||
directoryEntry := &internal.FileMetadata{
|
||||
Name: "mydir",
|
||||
Type: internal.TypeDir,
|
||||
|
|
@ -94,11 +100,16 @@ func TestDumpNode(t *testing.T) {
|
|||
ModTime: &modTime,
|
||||
}
|
||||
|
||||
var bufRegularFile, bufDirectory, bufSymlink, bufHardlink, bufMissingParent bytes.Buffer
|
||||
var bufRootEntry, bufRegularFile, bufDirectory, bufSymlink, bufHardlink, bufMissingParent bytes.Buffer
|
||||
|
||||
added := map[string]struct{}{"/": {}}
|
||||
|
||||
err := dumpNode(&bufRegularFile, added, map[string]int{}, map[string]string{}, regularFileEntry)
|
||||
err := dumpNode(&bufRootEntry, map[string]struct{}{}, map[string]int{}, map[string]string{}, rootEntry)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error for root entry: %v", err)
|
||||
}
|
||||
|
||||
err = dumpNode(&bufRegularFile, added, map[string]int{}, map[string]string{}, regularFileEntry)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error for regular file: %v", err)
|
||||
}
|
||||
|
|
@ -123,18 +134,24 @@ func TestDumpNode(t *testing.T) {
|
|||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
expectedRootEntry := "/ 0 40000 1 0 0 0 1672531200.0 - - -\n"
|
||||
expectedRegularFile := "/example.txt 100 100000 1 1000 1000 0 1672531200.0 ab/cdef1234567890 - - user.key1=value1\n"
|
||||
expectedDirectory := "/mydir 0 40000 1 1000 1000 0 1672531200.0 - - - user.key2=value2\n"
|
||||
expectedSymlink := "/mysymlink 0 120000 1 0 0 0 1672531200.0 targetfile - -\n"
|
||||
expectedHardlink := "/myhardlink 0 @100000 1 0 0 0 1672531200.0 /existingfile - -\n"
|
||||
expectedActualMissingParent := "/foo 0 40755 1 0 0 0 0.0 - - -\n/foo/bar 0 40755 1 0 0 0 0.0 - - -\n/foo/bar/baz 0 40755 1 0 0 0 0.0 - - -\n/foo/bar/baz/entry 0 100000 1 0 0 0 1672531200.0 - - -\n"
|
||||
|
||||
actualRootEntry := bufRootEntry.String()
|
||||
actualRegularFile := bufRegularFile.String()
|
||||
actualDirectory := bufDirectory.String()
|
||||
actualSymlink := bufSymlink.String()
|
||||
actualHardlink := bufHardlink.String()
|
||||
actualMissingParent := bufMissingParent.String()
|
||||
|
||||
if actualRootEntry != expectedRootEntry {
|
||||
t.Errorf("for root entry, got %q, want %q", actualRootEntry, expectedRootEntry)
|
||||
}
|
||||
|
||||
if actualRegularFile != expectedRegularFile {
|
||||
t.Errorf("for regular file, got %q, want %q", actualRegularFile, expectedRegularFile)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue