MCPcopy Index your code
hub / github.com/moby/moby / Stat

Method Stat

daemon/containerfs_linux.go:275–301  ·  view source on GitHub ↗

Stat returns the metadata for path, relative to the current working directory of vw inside the container filesystem view.

(ctx context.Context, path string)

Source from the content-addressed store, hash-verified

273// Stat returns the metadata for path, relative to the current working directory
274// of vw inside the container filesystem view.
275func (vw *containerFSView) Stat(ctx context.Context, path string) (*containertypes.PathStat, error) {
276 var stat *containertypes.PathStat
277 err := vw.RunInFS(ctx, func() error {
278 lstat, err := os.Lstat(path)
279 if err != nil {
280 return err
281 }
282 var target string
283 if lstat.Mode()&os.ModeSymlink != 0 {
284 // Fully evaluate symlinks along path to the ultimate
285 // target, or as much as possible with broken links.
286 target, err = symlink.FollowSymlinkInScope(path, "/")
287 if err != nil {
288 return err
289 }
290 }
291 stat = &containertypes.PathStat{
292 Name: filepath.Base(path),
293 Size: lstat.Size(),
294 Mode: lstat.Mode(),
295 Mtime: lstat.ModTime(),
296 LinkTarget: target,
297 }
298 return nil
299 })
300 return stat, err
301}
302
303// createIfNotExists creates a file or a directory only if it does not already exist.
304// The path is scoped to root using [os.Root] to prevent symlink escape attacks.

Callers 15

TestEtcCDIFunction · 0.45
blkioTestDeviceFunction · 0.45
ensurePluginFunction · 0.45
ensurePluginFunction · 0.45
TestPluginsWithRuntimesFunction · 0.45
TestSaveOCIFunction · 0.45
CgroupNamespacesEnabledFunction · 0.45
stickFunction · 0.45
apparmorSupportedFunction · 0.45
cgroupnsSupportedFunction · 0.45

Calls 2

RunInFSMethod · 0.95
SizeMethod · 0.65

Tested by 15

TestEtcCDIFunction · 0.36
blkioTestDeviceFunction · 0.36
ensurePluginFunction · 0.36
ensurePluginFunction · 0.36
TestPluginsWithRuntimesFunction · 0.36
TestSaveOCIFunction · 0.36
TestCreateIfNotExistsFunction · 0.36
TestRootMountCleanupFunction · 0.36