no panic if listing non existing container image
Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
c0c93b153a
commit
883de9c4fc
@@ -318,6 +318,7 @@ func ContainerList() (containerInfo []*wwapiv1.ContainerInfo, err error) {
|
||||
_, kernelVersion, _ := kernel.FindKernel(container.RootFsDir(source))
|
||||
var creationTime uint64
|
||||
sourceStat, err := os.Stat(container.SourceDir(source))
|
||||
wwlog.Debug("Checking creation time for: %s,%v", container.SourceDir(source), sourceStat.ModTime())
|
||||
if err != nil {
|
||||
wwlog.Error("%s\n", err)
|
||||
} else {
|
||||
@@ -332,13 +333,13 @@ func ContainerList() (containerInfo []*wwapiv1.ContainerInfo, err error) {
|
||||
if err != nil {
|
||||
wwlog.Error("%s\n", err)
|
||||
}
|
||||
imgF, err := os.Stat(container.ImageFile(source))
|
||||
if err != nil {
|
||||
wwlog.Error("%s\n", err)
|
||||
imgSize := 0
|
||||
if imgF, err := os.Stat(container.ImageFile(source)); err == nil {
|
||||
imgSize = int(imgF.Size())
|
||||
}
|
||||
imgFC, err := os.Stat(container.ImageFile(source) + ".gz")
|
||||
if err != nil {
|
||||
wwlog.Error("%s\n", err)
|
||||
imgCSize := 0
|
||||
if imgFC, err := os.Stat(container.ImageFile(source) + ".gz"); err == nil {
|
||||
imgCSize = int(imgFC.Size())
|
||||
}
|
||||
containerInfo = append(containerInfo, &wwapiv1.ContainerInfo{
|
||||
Name: source,
|
||||
@@ -347,8 +348,8 @@ func ContainerList() (containerInfo []*wwapiv1.ContainerInfo, err error) {
|
||||
CreateDate: creationTime,
|
||||
ModDate: modTime,
|
||||
Size: uint64(size),
|
||||
ImgSize: uint64(imgF.Size()),
|
||||
ImgSizeComp: uint64(imgFC.Size()),
|
||||
ImgSize: uint64(imgSize),
|
||||
ImgSizeComp: uint64(imgCSize),
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||
|
||||
@@ -131,6 +132,10 @@ func (env *TestEnv) WriteFile(t *testing.T, fileName string, content string) {
|
||||
defer f.Close()
|
||||
_, err = f.WriteString(content)
|
||||
assert.NoError(t, err)
|
||||
err = os.Chtimes(env.GetPath(fileName),
|
||||
time.Date(2006, time.February, 1, 3, 4, 5, 0, time.UTC),
|
||||
time.Date(2006, time.February, 1, 3, 4, 5, 0, time.UTC))
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
// ReadFile returns the content of fileName as converted to a
|
||||
|
||||
Reference in New Issue
Block a user