Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for searching volatile-containers.json #3644

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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