Exemple #1
0
// btrfs ioctl executor
func ioctlSnapshotExecute(c *subvolSnapshot) error {
	fi, err := os.Stat(c.dest)
	if err == nil && !fi.IsDir() {
		return fmt.Errorf("'%s' exists and it is not a directory", c.dest)
	}

	var newname, dest string
	if err == nil && fi.IsDir() {
		dest = c.dest
		newname = filepath.Base(c.src)
	} else {
		dest = filepath.Dir(c.dest)
		newname = filepath.Base(c.dest)
	}

	if subvol, err := ioctl.TestIsSubvolume(c.src); err != nil {
		return err
	} else if !subvol {
		return c.error(fmt.Errorf("'%s' is not a subvolume", newname))
	}

	err = validators.ValidSubvolumeName(newname)
	if err != nil {
		return err
	}

	err = ioctl.SubvolSnapshot(c.readOnly, c.src, dest, newname)
	if err != nil {
		return err
	}

	return nil
}
Exemple #2
0
func (c *subvolCreate) validate() error {
	if len(c.dest) == 0 {
		return errors.New("destination is empty")
	}

	name := filepath.Base(c.dest)
	err := validators.ValidSubvolumeName(name)
	if err != nil {
		return err
	}

	fi, err := os.Stat(c.dest)
	if err == nil && fi.IsDir() {
		return fmt.Errorf("'%s' exists", c.dest)
	}

	return nil
}