Create btrfs directory if it does not exist

We may want to create this as a subvolume if the parent is btrfs
or support mounting on load in the future.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2017-07-12 11:30:39 -07:00
parent 8f1c11d862
commit 97bb760c2a
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB

View File

@ -39,13 +39,23 @@ type snapshotter struct {
// a file in the provided root.
// root needs to be a mount point of btrfs.
func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
mnt, err := mount.Lookup(root)
if mnt.FSType != "btrfs" {
return nil, fmt.Errorf("expected btrfs, got %s", mnt.FSType)
// If directory does not exist, create it
if _, err := os.Stat(root); err != nil {
if !os.IsNotExist(err) {
return nil, err
}
if err := os.Mkdir(root, 0755); err != nil {
return nil, err
}
}
mnt, err := mount.Lookup(root)
if err != nil {
return nil, err
}
if mnt.FSType != "btrfs" {
return nil, fmt.Errorf("expected btrfs, got %s", mnt.FSType)
}
var (
active = filepath.Join(root, "active")
snapshots = filepath.Join(root, "snapshots")