/
mount.go
49 lines (44 loc) · 1.01 KB
/
mount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var (
mountCmd = &cobra.Command{
Use: "mount",
Short: "mount a cache image to a directory",
Long: "Mount a cache image to a directory",
Example: fmt.Sprintf(" %s mount --name mycache /data/myvolume", os.Args[0]),
Args: cobra.RangeArgs(0, 1),
PreRunE: validateOptions,
RunE: runMountCmd,
}
modeFlag os.FileMode = 0750
)
func init() {
mountCmd.Flags().Uint32Var((*uint32)(&modeFlag), "mode", uint32(modeFlag), "set mount directory access permissions")
addContainerFlag(mountCmd)
rootCmd.AddCommand(mountCmd)
}
func runMountCmd(cmd *cobra.Command, args []string) (err error) {
if len(args) > 0 {
mountOptions.ExtMountDir = args[0]
}
store, err := newStore()
if err != nil {
return err
}
defer store.Free()
applyDefaults(&mountOptions)
dir, err := store.Mount(mountOptions)
if err != nil {
return err
}
err = os.Chmod(dir, modeFlag)
if err != nil {
return err
}
fmt.Fprintln(cmd.OutOrStdout(), dir)
return err
}