Skip to content

Commit

Permalink
archive: honor ignoreChownErrors with ForceMode
Browse files Browse the repository at this point in the history
when ignore_chown_errors is set, ignore also failures from setting the
override mode xattr.

Closes: containers#2174

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Nov 19, 2024
1 parent 6803f17 commit ee411dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,10 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
Mode: hdrInfo.Mode() & 0o7777,
}
if err := idtools.SetContainersOverrideXattr(path, value); err != nil {
return err
if !ignoreChownErrors {
return err
}
logrus.Warnf("Setting override extended attribute failed for %q. Ignoring due to ignoreChownErrors flag: %v", path, err)
}
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,3 +1247,20 @@ func readFileFromArchive(t *testing.T, archive io.ReadCloser, name string, expec
assert.NoError(t, err)
return string(content)
}

func TestCreateFifo(t *testing.T) {
hdr := tar.Header{Typeflag: tar.TypeFifo}
tmpDir := t.TempDir()
buffer := make([]byte, 1<<20)
err := createTarFile(filepath.Join(tmpDir, "fifo1"), tmpDir, &hdr, nil, true, nil, false, false, nil, buffer)
assert.NoError(t, err)

forceMask := os.FileMode(0o755)
err = createTarFile(filepath.Join(tmpDir, "fifo2"), tmpDir, &hdr, nil, true, nil, false, false, &forceMask, buffer)
// expect an error to chown a fifo
assert.Error(t, err)

err = createTarFile(filepath.Join(tmpDir, "fifo3"), tmpDir, &hdr, nil, true, nil, false, true, &forceMask, buffer)
// expect no error as honors ignoreChownErrors
assert.NoError(t, err)
}

0 comments on commit ee411dd

Please sign in to comment.