mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
list: report error when non-existent --root is specified
It is questionable whether runc list should return an empty list of containers when non-existent --root is specified or not. The current behavior is the directory is always created and then the empty list of container is shown. To my mind, specifying a non-existent root is an error and should be reported as such. This is what this patch does. For backward compatibility, if --root is not set (i.e. a default is used), ENOENT is not reported. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -110,12 +110,19 @@ To list containers created using a non-default value for "--root":
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getContainers(context *cli.Context) ([]containerState, error) {
|
func getContainers(context *cli.Context) ([]containerState, error) {
|
||||||
factory, err := loadFactory(context)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
root := context.GlobalString("root")
|
root := context.GlobalString("root")
|
||||||
list, err := os.ReadDir(root)
|
list, err := os.ReadDir(root)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, os.ErrNotExist) && context.IsSet("root") {
|
||||||
|
// Ignore non-existing default root directory
|
||||||
|
// (no containers created yet).
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
// Report other errors, including non-existent custom --root.
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
factory, err := loadFactory(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user