MCPcopy Index your code
hub / github.com/containerd/containerd / wrapUserFile

Function wrapUserFile

pkg/oci/spec_opts.go:1893–1911  ·  view source on GitHub ↗

wrapUserFile rejects non-regular sources and returns an fs.File that errors out if more than maxUserFileBytes are read from it.

(f fs.File, name string)

Source from the content-addressed store, hash-verified

1891// wrapUserFile rejects non-regular sources and returns an fs.File that
1892// errors out if more than maxUserFileBytes are read from it.
1893func wrapUserFile(f fs.File, name string) (fs.File, error) {
1894 info, err := f.Stat()
1895 if err != nil {
1896 f.Close()
1897 return nil, fmt.Errorf("stat %s: %w", name, err)
1898 }
1899 if !info.Mode().IsRegular() {
1900 f.Close()
1901 return nil, fmt.Errorf("%s is not a regular file", name)
1902 }
1903 return &limitedFile{
1904 File: f,
1905 // Allow one byte past the cap so an overflow surfaces as an
1906 // error rather than a silent EOF that the parser would treat as
1907 // a clean end-of-file (and miss any entries past the cap).
1908 r: &io.LimitedReader{R: f, N: maxUserFileBytes + 1},
1909 name: name,
1910 }, nil
1911}
1912
1913// limitedFile is an fs.File whose Read returns an error once more than
1914// maxUserFileBytes have been read.

Callers 1

openUserFileFunction · 0.85

Calls 3

StatMethod · 0.65
CloseMethod · 0.65
ModeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…