github.com/koderover/helm@v2.17.0+incompatible/internal/third_party/dep/fs/rename_windows.go (about) 1 // +build windows 2 3 /* 4 Copyright (c) for portions of rename_windows.go are held by The Go Authors, 2016 and are provided under 5 the BSD license. 6 7 Redistribution and use in source and binary forms, with or without 8 modification, are permitted provided that the following conditions are 9 met: 10 11 * Redistributions of source code must retain the above copyright 12 notice, this list of conditions and the following disclaimer. 13 * Redistributions in binary form must reproduce the above 14 copyright notice, this list of conditions and the following disclaimer 15 in the documentation and/or other materials provided with the 16 distribution. 17 * Neither the name of Google Inc. nor the names of its 18 contributors may be used to endorse or promote products derived from 19 this software without specific prior written permission. 20 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 package fs 35 36 import ( 37 "os" 38 "syscall" 39 40 "github.com/pkg/errors" 41 ) 42 43 // renameFallback attempts to determine the appropriate fallback to failed rename 44 // operation depending on the resulting error. 45 func renameFallback(err error, src, dst string) error { 46 // Rename may fail if src and dst are on different devices; fall back to 47 // copy if we detect that case. syscall.EXDEV is the common name for the 48 // cross device link error which has varying output text across different 49 // operating systems. 50 terr, ok := err.(*os.LinkError) 51 if !ok { 52 return err 53 } 54 55 if terr.Err != syscall.EXDEV { 56 // In windows it can drop down to an operating system call that 57 // returns an operating system error with a different number and 58 // message. Checking for that as a fall back. 59 noerr, ok := terr.Err.(syscall.Errno) 60 61 // 0x11 (ERROR_NOT_SAME_DEVICE) is the windows error. 62 // See https://msdn.microsoft.com/en-us/library/cc231199.aspx 63 if ok && noerr != 0x11 { 64 return errors.Wrapf(terr, "link error: cannot rename %s to %s", src, dst) 65 } 66 } 67 68 return renameByCopy(src, dst) 69 }