Skip to content

Commit

Permalink
Merge pull request #1948 from giuseppe/use-escaped-name-for-check
Browse files Browse the repository at this point in the history
dump: use the sanitized path for root check
  • Loading branch information
openshift-merge-bot[bot] authored Jun 4, 2024
2 parents 7857557 + 06a03bd commit c923593
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/chunked/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 19 additions & 2 deletions pkg/chunked/dump/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit c923593

Please sign in to comment.