Skip to content
Browse files

various bug fixes for move logic

  • Loading branch information...
1 parent 45be6d7 commit 574ecb57b450c9a032560642b66d4bcc53258e57 @falconindy committed Aug 30, 2010
Showing with 14 additions and 6 deletions.
  1. +14 −6 gobble.go
View
20 gobble.go
@@ -101,8 +101,9 @@ func movePkg(pkg *archpkg) os.Error {
/* try to rename, first */
err := os.Rename(fmt.Sprintf("%s/%s", *cachePath, filename), fmt.Sprintf("%s/%s", *destPath, filename))
- if err == os.EXDEV { /* from link(2) */
- src, err := os.Open(flag.Arg(0), os.O_RDONLY, 0666)
+ switch err.(type) {
+ case *os.LinkError:
+ src, err := os.Open(fmt.Sprintf("%s/%s", *cachePath, filename), os.O_RDONLY, 0666)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err.String())
os.Exit(1)
@@ -111,16 +112,16 @@ func movePkg(pkg *archpkg) os.Error {
sfi, err := src.Stat()
- dst, err := os.Open(flag.Arg(1), os.O_WRONLY|os.O_CREAT|os.O_TRUNC, sfi.Permission())
+ dst, err := os.Open(fmt.Sprintf("%s/%s", *destPath, filename) , os.O_WRONLY|os.O_CREAT|os.O_TRUNC, sfi.Permission())
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err.String())
os.Exit(1)
}
defer dst.Close()
err = doCopy(src, bufio.NewWriter(dst))
- if err != nil {
- return os.Remove(fmt.Sprintf("%s/%s", cachePath, filename))
+ if err == nil {
+ return os.Remove(fmt.Sprintf("%s/%s", *cachePath, filename))
}
return err /* different from err outside if */
}
@@ -222,6 +223,11 @@ func main() {
os.Exit(5)
}
+ if *keep == 0 {
+ fmt.Fprintln(os.Stderr, "error: keep cannot equal 0")
+ os.Exit(5)
+ }
+
d, err := os.Open(*cachePath, os.O_RDONLY, 0666)
if err != nil {
fmt.Fprintln(os.Stderr, err.String())
@@ -235,7 +241,9 @@ func main() {
os.Exit(1)
}
- if !*delete { fmt.Println("Performing dry-run...") }
+ if !*delete && *destPath == "" {
+ fmt.Println("Performing dry-run...")
+ }
found := 0
for _, pkg := range fi {

0 comments on commit 574ecb5

Please sign in to comment.
Something went wrong with that request. Please try again.