Stat returns the metadata for path, relative to the current working directory of vw inside the container filesystem view.
(ctx context.Context, path string)
| 273 | // Stat returns the metadata for path, relative to the current working directory |
| 274 | // of vw inside the container filesystem view. |
| 275 | func (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. |