Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevent-fei committed Nov 16, 2022
1 parent ad09883 commit 6877f1e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
21 changes: 13 additions & 8 deletions cmd/sealer/cmd/alpha/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@ package alpha

import (
"fmt"
"path/filepath"

imagecommon "github.com/sealerio/sealer/pkg/define/options"
"github.com/sealerio/sealer/pkg/imageengine"
"github.com/sealerio/sealer/utils/mount"
"github.com/sealerio/sealer/utils/os"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var longMountCmdDescription = `
mount the image file to a specified directory to check whether the content of the build image and rootfs are consistent in advance
mount the image file to the specified virtual directory and check whether the contents of the build image and rootfs are consistent in advance
You need to specify a virtual path, for example:
'sealer alpha mount my-image /root/rootfs'
rootfs are virtual path
`

var exampleForMountCmd = `
sealer alpha mount my-image /tmp
sealer alpha mount e5b4997adba6 /tmp
sealer alpha mount my-image /tmp/rootfs
sealer alpha mount e5b4997adba6 /tmp/rootfs
`

func NewMountCmd() *cobra.Command {
Expand All @@ -43,11 +48,11 @@ func NewMountCmd() *cobra.Command {
if len(args) < 2 {
return fmt.Errorf("please enter full parameters")
}
exists, err := mount.PathExists(args[1])
path, err := filepath.Abs(args[1])
if err != nil {
return err
}
if exists {
if os.IsFileExist(path) {
return fmt.Errorf("directory name already exists")
}

Expand All @@ -56,14 +61,14 @@ func NewMountCmd() *cobra.Command {
return err
}
if _, err := imageEngine.CreateWorkingContainer(&imagecommon.BuildRootfsOptions{
DestDir: args[1],
DestDir: path,
ImageNameOrID: args[0],
}); err != nil {
return err
}
logrus.Infof("specific path is %s, mount image file success", path)
return nil
},
}

return mountCmd
}
17 changes: 16 additions & 1 deletion cmd/sealer/cmd/alpha/umount.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@
package alpha

import (
"fmt"

imagecommon "github.com/sealerio/sealer/pkg/define/options"
"github.com/sealerio/sealer/pkg/imagedistributor"
"github.com/sealerio/sealer/pkg/imageengine"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var longUmountCmdDescription = `umount image file dir`
var longUmountCmdDescription = `
umount image file virtual path
You need to delete specify virtual path, for example:
'sealer alpha umount /root/rootfs'
rootfs are virtual path
`

var exampleForUmountCmd = `
sealer alpha umount /tmp/rootfs
Expand All @@ -39,10 +47,17 @@ func NewUmountCmd() *cobra.Command {
if err != nil {
return err
}
if err := imageEngine.RemoveContainer(&imagecommon.RemoveContainerOptions{
ContainerNamesOrIDs: nil,
All: true,
}); err != nil {
return fmt.Errorf("failed to remove mounted dir %s: %v", args[0], err)
}
mounter := imagedistributor.NewBuildAhMounter(imageEngine)
if err = mounter.Umount(args[0]); err != nil {
return err
}
logrus.Infof("umount image file success")
return nil
},
}
Expand Down

0 comments on commit 6877f1e

Please sign in to comment.