Ejemplo n.º 1
0
func main() {
	flag.Parse()

	if recursive {
		remove = os.RemoveAll
	}

	paths := flag.Args()
	if len(paths) < 1 {
		msg.Errln("rm: no files given")
	}

	for _, p := range paths {
		for p != "." {
			err := remove(p)
			if err != nil {
				msg.Errf("rm: %s\n", err)
			}
			if !parents {
				break
			}
			p = path.Dir(p)
		}
	}
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()

	paths := flag.Args()
	switch len(paths) {
	case 0:
		msg.Errln("mv: missing file operand")
	case 1:
		msg.Errf("mv: missing destination operand after %q\n", paths[0])
	case 2:
		src, dest := paths[0], paths[1]

		err := shared.Move(src, dest)
		if err != nil {
			msg.Errf("mv: %s\n", err)
			os.Exit(1)
		}
	// More than 2 arguments.
	default:
		srcs, dest := paths[:len(paths)-1], paths[len(paths)-1]

		var exitcode int
		for _, src := range srcs {
			err := shared.Move(src, dest)
			if err != nil {
				msg.Errf("mv: %s\n", err)
				exitcode++
			}
		}
		os.Exit(exitcode)
	}
}
Ejemplo n.º 3
0
// The first form of ln. Links the target file to the named file.
func first_form(target, name string) (err error) {
	err = link(target, name)
	if err != nil {
		msg.Errln(err)
	}
	return
}
Ejemplo n.º 4
0
func main() {
	var (
		exit int // the exit value of the program
	)

	flag.Parse()

	modenum, err := strconv.ParseInt(modestring, 8, 32)
	if err != nil {
		msg.Errln(err)
		os.Exit(1)
	}
	mode := os.FileMode(modenum)

	dirs := flag.Args()
	if len(dirs) < 1 {
		msg.Errln("mkdir: no directories specified")
		os.Exit(1)
	}

	for _, dir := range dirs {
		if createParents {
			err = os.MkdirAll(dir, os.FileMode(mode))
			if err != nil {
				msg.Errln(err)
				exit = 1
			}
		} else {
			err = os.Mkdir(dir, os.FileMode(mode))
			if err != nil {
				msg.Errln(err)
				exit = 1
			}
		}
		if err == nil && verbose {
			fmt.Printf("mkdir: Created directory '%s'", dir)
		}
	}
	os.Exit(exit)
}
Ejemplo n.º 5
0
func main() {
	flag.Parse()

	files := flag.Args()
	if len(files) != 2 {
		msg.Errln("Need 2 arguments.")
		os.Exit(1)
	}
	src, dest := files[0], files[1]

	err := shared.Copy(src, dest)
	if err != nil {
		msg.Errf("cp: %s\n", err)
		os.Exit(1)
	}
}
Ejemplo n.º 6
0
func main() {
	var (
		paths []string
		err   error
	)
	flag.Parse()

	if symbolic {
		// Change the link function from os.Link to os.Symlink.
		link = os.Symlink
	}

	paths = flag.Args()

	l := len(paths)
	switch {
	// No arguments.
	case l < 1:
		msg.Errln("Not enough arguments.")
		os.Exit(1)
	// First form.
	case l == 2:
		target := paths[0]
		name := paths[1]
		err = first_form(target, name)
	// Second form.
	case l == 1:
		target := paths[0]
		err = second_form(target)
	// Third form.
	case l > 2:
		targets := paths[:len(paths)-1]
		dir := paths[len(paths)-1]
		err = third_form(dir, targets...)
	}

	if err != nil {
		os.Exit(1)
	}
}