Updating the copying when cross device link err presents itself
diff --git a/path/path.go b/path/path.go index 48e95fb..953d851 100644 --- a/path/path.go +++ b/path/path.go
@@ -235,7 +235,11 @@ return err } - d, _ := os.Open(source) + d, err := os.Open(source) + if err != nil { + return err + } + defer d.Close() objects, err := d.Readdir(-1)
diff --git a/repo/installer.go b/repo/installer.go index 52dcf12..8faee97 100644 --- a/repo/installer.go +++ b/repo/installer.go
@@ -8,6 +8,7 @@ "runtime" "strings" "sync" + "syscall" "time" "github.com/Masterminds/glide/cache" @@ -360,15 +361,29 @@ err = os.Rename(vp, i.VendorPath()) - // When there are different physical devices we cannot rename cross device. - // Note, windows does not return the cross-device link message but instead - // bubbles up a system message (I believe is i18n). So, we try to detect the - // cross device link error or a windows error. If copy fails that will bubble - // up an additional error. - if err != nil && (strings.Contains(err.Error(), "cross-device link") || runtime.GOOS == "windows") { - msg.Debug("Cross link err, trying manual copy: %s", err) - - err = gpath.CopyDir(vp, i.VendorPath()) + if err != nil { + // When there are different physical devices we cannot rename cross device. + // Instead we copy. + switch terr := err.(type) { + case *os.LinkError: + // syscall.EXDEV is the common name for the cross device link error + // which has varying output text across different operating systems. + if terr.Err == syscall.EXDEV { + msg.Debug("Cross link err, trying manual copy: %s", err) + return gpath.CopyDir(vp, i.VendorPath()) + } else if runtime.GOOS == "windows" { + // In windows it can drop down to an operating system call that + // returns an operating system error with a different number and + // message. Checking for that as a fall back. + noerr, ok := terr.Err.(syscall.Errno) + // 0x11 (ERROR_NOT_SAME_DEVICE) is the windows error. + // See https://msdn.microsoft.com/en-us/library/cc231199.aspx + if ok && noerr == 0x11 { + msg.Debug("Cross link err on Windows, trying manual copy: %s", err) + return gpath.CopyDir(vp, i.VendorPath()) + } + } + } } return err