From 03c417c94f32bafe0f61650b0c209c2f0fbfadca Mon Sep 17 00:00:00 2001 From: ja14000 Date: Thu, 9 Jan 2025 22:39:41 +0000 Subject: [PATCH] Update fs.go Added logic to search for layer id in volatile-containers.json, if not found in containers.json --- container/podman/fs.go | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/container/podman/fs.go b/container/podman/fs.go index e714e900c3..5acf69d070 100644 --- a/container/podman/fs.go +++ b/container/podman/fs.go @@ -25,6 +25,7 @@ import ( const ( containersJSONFilename = "containers.json" + volatileContainersJSONFilename = "volatile-containers.json" ) type containersJSON struct { @@ -34,20 +35,34 @@ type containersJSON struct { } func rwLayerID(storageDriver docker.StorageDriver, storageDir string, containerID string) (string, error) { - data, err := os.ReadFile(filepath.Join(storageDir, string(storageDriver)+"-containers", containersJSONFilename)) - if err != nil { - return "", err + searchInFile := func(filename string) (string, error) { + data, err := os.ReadFile(filepath.Join(storageDir, string(storageDriver)+"-containers", filename)) + if err != nil { + return "", err + } + var containers []containersJSON + err = json.Unmarshal(data, &containers) + if err != nil { + return "", err + } + + for _, c := range containers { + if c.ID == containerID { + return c.Layer, nil + } + } + + return "", nil } - var containers []containersJSON - err = json.Unmarshal(data, &containers) - if err != nil { - return "", err + + layer, err := searchInFile(containersJSONFilename) + if err == nil && layer != "" { + return layer, nil } - for _, c := range containers { - if c.ID == containerID { - return c.Layer, nil - } + layer, err = searchInFile(volatileContainersJSONFilename) + if err == nil && layer != "" { + return layer, nil } return "", fmt.Errorf("unable to determine %v rw layer id", containerID)