Commits

Miki Tebeka committed 4cae680

fmt

Comments (0)

Files changed (1)

 /* Copy directory tree */
+// FIXME: Update to go1 filepath.Walk
+
 package main
 
 import (
+	"errors"
 	"flag"
 	"fmt"
 	"io"
 
 type treeCopier struct {
 	src, dest string
-	verbose bool
+	verbose   bool
 
 	// Last error, Visit* function will return immediatly when it's not nil
-	err os.Error
+	err error
 }
 
 // Destination path.
 // TODO: filepath.Walk has changed as of weekly-2011-09-16
 
 // Visit a directory, this will create the destination directory.
-func (c *treeCopier) VisitDir(path string, f *os.FileInfo) bool {
+func (c *treeCopier) VisitDir(path string, f os.FileInfo) bool {
 	if c.err != nil {
 		return false
 	}
 	c.log("creating %s", c.destPath(path))
-	c.err = os.Mkdir(c.destPath(path), f.Mode)
+	c.err = os.Mkdir(c.destPath(path), f.Mode())
 	return c.err == nil
 }
 
 // Visit a file, copy to destination. Parent directories should have been
 // created already
-func (c *treeCopier) VisitFile(path string, f *os.FileInfo) {
+func (c *treeCopier) VisitFile(path string, f os.FileInfo) {
 	if c.err != nil {
 		return
 	}
 
 	c.log("%s -> %s", path, c.destPath(path))
 
-	flags := os.O_WRONLY|os.O_CREATE
-	dest, c.err = os.OpenFile(c.destPath(path), flags, f.Mode)
+	flags := os.O_WRONLY | os.O_CREATE
+	dest, c.err = os.OpenFile(c.destPath(path), flags, f.Mode())
 	if c.err != nil {
 		return
 	}
 		return
 	}
 
-	if size != f.Size {
-		c.err = os.NewError(fmt.Sprintf("%s: %d/%d copied", path, size, f.Size))
+	if size != f.Size() {
+		c.err = errors.New(fmt.Sprintf("%s: %d/%d copied", path, size, f.Size()))
 		return
 	}
 }
 
 // Copy a directory tree from `src` to `dest`
-func CopyTree(src, dest string, verbose bool) os.Error {
+func CopyTree(src, dest string, verbose bool) error {
 	c := &treeCopier{src: src, dest: dest, verbose: verbose}
 	filepath.Walk(src, c, nil)
 	return c.err
 		os.Exit(1)
 	}
 }
-