mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
list: getContainers: less indentation
Instead of a huge if {} block, use continue.
Best reviewed with --ignore-all-space.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
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,
|
||||
})
|
||||
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,
|
||||
})
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user