diff options
Diffstat (limited to 'libpod/image')
-rw-r--r-- | libpod/image/docker_registry_options.go | 2 | ||||
-rw-r--r-- | libpod/image/filters.go | 2 | ||||
-rw-r--r-- | libpod/image/image.go | 67 | ||||
-rw-r--r-- | libpod/image/image_test.go | 4 | ||||
-rw-r--r-- | libpod/image/prune.go | 4 | ||||
-rw-r--r-- | libpod/image/pull.go | 4 | ||||
-rw-r--r-- | libpod/image/search.go | 2 |
7 files changed, 71 insertions, 14 deletions
diff --git a/libpod/image/docker_registry_options.go b/libpod/image/docker_registry_options.go index a43a94896..c434f0259 100644 --- a/libpod/image/docker_registry_options.go +++ b/libpod/image/docker_registry_options.go @@ -6,7 +6,7 @@ import ( "github.com/containers/buildah/pkg/parse" "github.com/containers/image/v5/docker/reference" "github.com/containers/image/v5/types" - podmanVersion "github.com/containers/libpod/v2/version" + podmanVersion "github.com/containers/podman/v2/version" ) // DockerRegistryOptions encapsulates settings that affect how we connect or diff --git a/libpod/image/filters.go b/libpod/image/filters.go index 11d081ec3..9738a7d5e 100644 --- a/libpod/image/filters.go +++ b/libpod/image/filters.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/containers/libpod/v2/pkg/inspect" + "github.com/containers/podman/v2/pkg/inspect" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/libpod/image/image.go b/libpod/image/image.go index e2bd1ad5d..8b2aa318f 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -27,11 +27,11 @@ import ( "github.com/containers/image/v5/transports" "github.com/containers/image/v5/transports/alltransports" "github.com/containers/image/v5/types" - "github.com/containers/libpod/v2/libpod/driver" - "github.com/containers/libpod/v2/libpod/events" - "github.com/containers/libpod/v2/pkg/inspect" - "github.com/containers/libpod/v2/pkg/registries" - "github.com/containers/libpod/v2/pkg/util" + "github.com/containers/podman/v2/libpod/driver" + "github.com/containers/podman/v2/libpod/events" + "github.com/containers/podman/v2/pkg/inspect" + "github.com/containers/podman/v2/pkg/registries" + "github.com/containers/podman/v2/pkg/util" "github.com/containers/storage" digest "github.com/opencontainers/go-digest" imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1" @@ -1593,6 +1593,63 @@ func (i *Image) newImageEvent(status events.Status) { } } +// Mount mounts a image's filesystem on the host +// The path where the image has been mounted is returned +func (i *Image) Mount(options []string, mountLabel string) (string, error) { + defer i.newImageEvent(events.Mount) + return i.mount(options, mountLabel) +} + +// Unmount unmounts a image's filesystem on the host +func (i *Image) Unmount(force bool) error { + defer i.newImageEvent(events.Unmount) + return i.unmount(force) +} + +// Mounted returns whether the image is mounted and the path it is mounted +// at (if it is mounted). +// If the image is not mounted, no error is returned, and the mountpoint +// will be set to "". +func (i *Image) Mounted() (bool, string, error) { + mountedTimes, err := i.imageruntime.store.Mounted(i.TopLayer()) + if err != nil { + return false, "", err + } + + if mountedTimes > 0 { + layer, err := i.imageruntime.store.Layer(i.TopLayer()) + if err != nil { + return false, "", err + } + return true, layer.MountPoint, nil + } + + return false, "", nil +} + +// mount mounts the container's root filesystem +func (i *Image) mount(options []string, mountLabel string) (string, error) { + mountPoint, err := i.imageruntime.store.MountImage(i.ID(), options, mountLabel) + if err != nil { + return "", errors.Wrapf(err, "error mounting storage for image %s", i.ID()) + } + mountPoint, err = filepath.EvalSymlinks(mountPoint) + if err != nil { + return "", errors.Wrapf(err, "error resolving storage path for image %s", i.ID()) + } + return mountPoint, nil +} + +// unmount unmounts the image's root filesystem +func (i *Image) unmount(force bool) error { + // Also unmount storage + if _, err := i.imageruntime.store.UnmountImage(i.ID(), force); err != nil { + return errors.Wrapf(err, "error unmounting image %s root filesystem", i.ID()) + } + + return nil +} + // LayerInfo keeps information of single layer type LayerInfo struct { // Layer ID diff --git a/libpod/image/image_test.go b/libpod/image/image_test.go index 645f8d3f3..2704b8baf 100644 --- a/libpod/image/image_test.go +++ b/libpod/image/image_test.go @@ -7,8 +7,8 @@ import ( "os" "testing" - "github.com/containers/libpod/v2/libpod/events" - "github.com/containers/libpod/v2/pkg/util" + "github.com/containers/podman/v2/libpod/events" + "github.com/containers/podman/v2/pkg/util" "github.com/containers/storage" "github.com/containers/storage/pkg/reexec" "github.com/opencontainers/go-digest" diff --git a/libpod/image/prune.go b/libpod/image/prune.go index 5ad7a9a5e..8c9267650 100644 --- a/libpod/image/prune.go +++ b/libpod/image/prune.go @@ -5,8 +5,8 @@ import ( "strings" "time" - "github.com/containers/libpod/v2/libpod/events" - "github.com/containers/libpod/v2/pkg/timetype" + "github.com/containers/podman/v2/libpod/events" + "github.com/containers/podman/v2/pkg/timetype" "github.com/containers/storage" "github.com/pkg/errors" "github.com/sirupsen/logrus" diff --git a/libpod/image/pull.go b/libpod/image/pull.go index f0cde2012..d31f0dbdc 100644 --- a/libpod/image/pull.go +++ b/libpod/image/pull.go @@ -18,8 +18,8 @@ import ( "github.com/containers/image/v5/transports" "github.com/containers/image/v5/transports/alltransports" "github.com/containers/image/v5/types" - "github.com/containers/libpod/v2/libpod/events" - "github.com/containers/libpod/v2/pkg/registries" + "github.com/containers/podman/v2/libpod/events" + "github.com/containers/podman/v2/pkg/registries" "github.com/hashicorp/go-multierror" "github.com/opentracing/opentracing-go" "github.com/pkg/errors" diff --git a/libpod/image/search.go b/libpod/image/search.go index ee1ff0312..6bcc6d3f8 100644 --- a/libpod/image/search.go +++ b/libpod/image/search.go @@ -8,7 +8,7 @@ import ( "github.com/containers/image/v5/docker" "github.com/containers/image/v5/types" - sysreg "github.com/containers/libpod/v2/pkg/registries" + sysreg "github.com/containers/podman/v2/pkg/registries" "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/sync/semaphore" |