Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions container/podman/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

const (
containersJSONFilename = "containers.json"
volatileContainersJSONFilename = "volatile-containers.json"
)

type containersJSON struct {
Expand All @@ -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)
Expand Down
Loading