diff --git a/list.go b/list.go index 3503dcd2f5e..bf6ce792e69 100644 --- a/list.go +++ b/list.go @@ -127,50 +127,51 @@ func getContainers(context *cli.Context) ([]containerState, error) { var s []containerState for _, item := range list { - if item.IsDir() { - st, err := os.Stat(filepath.Join(absRoot, item.Name())) - if err != nil { - fatal(err) - } - // This cast is safe on Linux. - uid := st.Sys().(*syscall.Stat_t).Uid - owner, err := user.LookupUid(int(uid)) - if err != nil { - owner.Name = fmt.Sprintf("#%d", uid) - } + if !item.IsDir() { + continue + } + st, err := os.Stat(filepath.Join(absRoot, item.Name())) + if err != nil { + fatal(err) + } + // This cast is safe on Linux. + uid := st.Sys().(*syscall.Stat_t).Uid + owner, err := user.LookupUid(int(uid)) + if err != nil { + owner.Name = fmt.Sprintf("#%d", uid) + } - container, err := factory.Load(item.Name()) - if err != nil { - fmt.Fprintf(os.Stderr, "load container %s: %v\n", item.Name(), err) - continue - } - containerStatus, err := container.Status() - if err != nil { - fmt.Fprintf(os.Stderr, "status for %s: %v\n", item.Name(), err) - continue - } - state, err := container.State() - if err != nil { - fmt.Fprintf(os.Stderr, "state for %s: %v\n", item.Name(), err) - continue - } - pid := state.BaseState.InitProcessPid - if containerStatus == libcontainer.Stopped { - pid = 0 - } - bundle, annotations := utils.Annotations(state.Config.Labels) - s = append(s, containerState{ - Version: state.BaseState.Config.Version, - ID: state.BaseState.ID, - InitProcessPid: pid, - Status: containerStatus.String(), - Bundle: bundle, - Rootfs: state.BaseState.Config.Rootfs, - Created: state.BaseState.Created, - Annotations: annotations, - Owner: owner.Name, - }) + container, err := factory.Load(item.Name()) + if err != nil { + fmt.Fprintf(os.Stderr, "load container %s: %v\n", item.Name(), err) + continue + } + containerStatus, err := container.Status() + if err != nil { + fmt.Fprintf(os.Stderr, "status for %s: %v\n", item.Name(), err) + continue + } + state, err := container.State() + if err != nil { + fmt.Fprintf(os.Stderr, "state for %s: %v\n", item.Name(), err) + continue + } + pid := state.BaseState.InitProcessPid + if containerStatus == libcontainer.Stopped { + pid = 0 } + bundle, annotations := utils.Annotations(state.Config.Labels) + s = append(s, containerState{ + Version: state.BaseState.Config.Version, + ID: state.BaseState.ID, + InitProcessPid: pid, + Status: containerStatus.String(), + Bundle: bundle, + Rootfs: state.BaseState.Config.Rootfs, + Created: state.BaseState.Created, + Annotations: annotations, + Owner: owner.Name, + }) } return s, nil }