summaryrefslogtreecommitdiffstats
path: root/mount.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 17:12:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 17:12:05 +0000
commit9ec46d47bedefa10bdaaa8a587ddb1851ef396ec (patch)
treeba7545ee99b384a6fc3e5ea028ae4c643648d683 /mount.go
parentInitial commit. (diff)
downloadgolang-github-containers-buildah-9ec46d47bedefa10bdaaa8a587ddb1851ef396ec.tar.xz
golang-github-containers-buildah-9ec46d47bedefa10bdaaa8a587ddb1851ef396ec.zip
Adding upstream version 1.33.5+ds1.upstream/1.33.5+ds1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mount.go')
-rw-r--r--mount.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/mount.go b/mount.go
new file mode 100644
index 0000000..932c1bb
--- /dev/null
+++ b/mount.go
@@ -0,0 +1,51 @@
+package buildah
+
+import "fmt"
+
+// Mount mounts a container's root filesystem in a location which can be
+// accessed from the host, and returns the location.
+func (b *Builder) Mount(label string) (string, error) {
+ mountpoint, err := b.store.Mount(b.ContainerID, label)
+ if err != nil {
+ return "", fmt.Errorf("mounting build container %q: %w", b.ContainerID, err)
+ }
+ b.MountPoint = mountpoint
+
+ err = b.Save()
+ if err != nil {
+ return "", fmt.Errorf("saving updated state for build container %q: %w", b.ContainerID, err)
+ }
+ return mountpoint, nil
+}
+
+func (b *Builder) setMountPoint(mountPoint string) error {
+ b.MountPoint = mountPoint
+ if err := b.Save(); err != nil {
+ return fmt.Errorf("saving updated state for build container %q: %w", b.ContainerID, err)
+ }
+ return nil
+}
+
+// Mounted returns whether the container is mounted or not
+func (b *Builder) Mounted() (bool, error) {
+ mountCnt, err := b.store.Mounted(b.ContainerID)
+ if err != nil {
+ return false, fmt.Errorf("determining if mounting build container %q is mounted: %w", b.ContainerID, err)
+ }
+ mounted := mountCnt > 0
+ if mounted && b.MountPoint == "" {
+ ctr, err := b.store.Container(b.ContainerID)
+ if err != nil {
+ return mountCnt > 0, fmt.Errorf("determining if mounting build container %q is mounted: %w", b.ContainerID, err)
+ }
+ layer, err := b.store.Layer(ctr.LayerID)
+ if err != nil {
+ return mountCnt > 0, fmt.Errorf("determining if mounting build container %q is mounted: %w", b.ContainerID, err)
+ }
+ return mounted, b.setMountPoint(layer.MountPoint)
+ }
+ if !mounted && b.MountPoint != "" {
+ return mounted, b.setMountPoint("")
+ }
+ return mounted, nil
+}