github.com/golang/dep@v0.5.4/internal/fs/rename.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  	} else if terr.Err != syscall.EXDEV {
    27  		return errors.Wrapf(terr, "link error: cannot rename %s to %s", src, dst)
    28  	}
    29  
    30  	return renameByCopy(src, dst)
    31  }