Permalink
Browse files

use syscall.Rename rather than os.Rename to avoid mess with os.LinkEr…

…ror. this makes catching EXDEV a lot cleaner
  • Loading branch information...
1 parent 47b46c1 commit a774331df94ded74980f3e06410d0a81efd1e45a @falconindy committed Aug 30, 2010
Showing with 6 additions and 4 deletions.
  1. +6 −4 gobble.go
View
@@ -9,6 +9,7 @@ import (
"io"
"os"
"strings"
+ "syscall"
)
const (
@@ -100,9 +101,10 @@ func movePkg(pkg *archpkg) os.Error {
filename := fmt.Sprintf("%s-%s-%s.%s", pkg.Name, pkg.Version, pkg.Arch, pkg.Ext)
/* try to rename, first */
- err := os.Rename(fmt.Sprintf("%s/%s", *cachePath, filename), fmt.Sprintf("%s/%s", *destPath, filename))
- switch err.(type) {
- case *os.LinkError:
+ errno := syscall.Rename(fmt.Sprintf("%s/%s", *cachePath, filename), fmt.Sprintf("%s/%s", *destPath, filename))
+
+ switch errno {
+ case syscall.EXDEV:
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())
@@ -126,7 +128,7 @@ func movePkg(pkg *archpkg) os.Error {
return err /* different from err outside if */
}
- return err
+ return os.Errno(errno)
}
func addPkgToMap(pkg *archpkg) {

0 comments on commit a774331

Please sign in to comment.