github.com/golang/dep@v0.5.4/internal/fs/rename_windows.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build windows 6 7 package fs 8 9 import ( 10 "os" 11 "syscall" 12 13 "github.com/pkg/errors" 14 ) 15 16 // renameFallback attempts to determine the appropriate fallback to failed rename 17 // operation depending on the resulting error. 18 func renameFallback(err error, src, dst string) error { 19 // Rename may fail if src and dst are on different devices; fall back to 20 // copy if we detect that case. syscall.EXDEV is the common name for the 21 // cross device link error which has varying output text across different 22 // operating systems. 23 terr, ok := err.(*os.LinkError) 24 if !ok { 25 return err 26 } 27 28 if terr.Err != syscall.EXDEV { 29 // In windows it can drop down to an operating system call that 30 // returns an operating system error with a different number and 31 // message. Checking for that as a fall back. 32 noerr, ok := terr.Err.(syscall.Errno) 33 34 // 0x11 (ERROR_NOT_SAME_DEVICE) is the windows error. 35 // See https://msdn.microsoft.com/en-us/library/cc231199.aspx 36 if ok && noerr != 0x11 { 37 return errors.Wrapf(terr, "link error: cannot rename %s to %s", src, dst) 38 } 39 } 40 41 return renameByCopy(src, dst) 42 }