52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
)
|
|
|
|
func Clone(root, src, dst string) error {
|
|
cmd := exec.Command("juicefs", "clone", root+src, root+dst)
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return fmt.Errorf("clone failed: %v, output: %s", err, string(output))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Move(root, src, dst string) error {
|
|
cmd := exec.Command("mv", root+src, root+dst)
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return fmt.Errorf("move failed: %v, output: %s", err, string(output))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Remove(root, path string, isDir bool) error {
|
|
var cmd *exec.Cmd
|
|
if isDir {
|
|
cmd = exec.Command("rm", "-r", root+path)
|
|
} else {
|
|
cmd = exec.Command("rm", root+path)
|
|
}
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return fmt.Errorf("remove failed: %v, output: %s", err, string(output))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Mkdir(root, path string) error {
|
|
cmd := exec.Command("mkdir", root+path)
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return fmt.Errorf("mkdir failed: %v, output: %s", err, string(output))
|
|
}
|
|
|
|
return nil
|
|
}
|