Exemplo n.º 1
0
Arquivo: rsync.go Projeto: yuuki/droot
func Rsync(from, to string, arg ...string) error {
	from = from + "/"
	// append "/" when not terminated by "/"
	if strings.LastIndex(to, "/") != len(to)-1 {
		to = to + "/"
	}

	rsyncArgs := []string{}
	rsyncArgs = append(rsyncArgs, RsyncDefaultOpts...)

	// Exclude bind-mounted directory by droot run
	mnt := mounter.NewMounter(to)
	mounts, err := mnt.GetMountsRoot()
	if err != nil {
		return err
	}
	for _, m := range mounts {
		mp := strings.TrimPrefix(m.Mountpoint, to)
		rsyncArgs = append(rsyncArgs, fmt.Sprintf("--exclude=/%s", mp))
	}

	rsyncArgs = append(rsyncArgs, from, to)

	if err := osutil.RunCmd("rsync", rsyncArgs...); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 2
0
func CleanupSymlink(destDir string) error {
	mainLink := destDir + ".drootmain"
	backupLink := destDir + ".drootbackup"
	contentDir := destDir + ".d/"

	log.Info("-->", "Removing", backupLink)
	if err := osutil.RunCmd("rm", "-f", backupLink); err != nil {
		return err
	}
	log.Info("-->", "Removing", mainLink)
	if err := osutil.RunCmd("rm", "-f", mainLink); err != nil {
		return err
	}
	log.Info("-->", "Removing", contentDir)
	if err := osutil.RunCmd("rm", "-fr", contentDir); err != nil {
		return err
	}

	return osutil.RunCmd("rm", "-f", destDir)
}
Exemplo n.º 3
0
Arquivo: rm.go Projeto: yuuki/droot
func doRm(c *cli.Context) error {
	optRootDir := c.String("root")
	if optRootDir == "" {
		cli.ShowCommandHelp(c, "run")
		return errors.New("--root option required")
	}

	rootDir, err := mounter.ResolveRootDir(optRootDir)
	if err != nil {
		return err
	}

	mnt := mounter.NewMounter(rootDir)
	if err := mnt.UmountRoot(); err != nil {
		return err
	}

	if osutil.IsSymlink(optRootDir) {
		return deploy.CleanupSymlink(optRootDir)
	}

	log.Info("-->", "Removing", rootDir)
	return osutil.RunCmd("rm", "-fr", rootDir)
}