зеркало из https://github.com/golang/dep.git
s/renameElseCopy/renameWithFallback/
Changes both name and implementation of renameElseCopy to reflect that the outcome will be like a rename, even in the event of a cross-device link error.
This commit is contained in:
Родитель
7bec4bd58f
Коммит
096576a29c
24
ensure.go
24
ensure.go
|
@ -338,9 +338,10 @@ func deduceConstraint(s string) gps.Constraint {
|
|||
return gps.NewVersion(s)
|
||||
}
|
||||
|
||||
// renameElseCopy attempts to rename a file or directory, but falls back to
|
||||
// copying in the event of a cross-link device error.
|
||||
func renameElseCopy(src, dest string) error {
|
||||
// renameWithFallback attempts to rename a file or directory, but falls back to
|
||||
// copying in the event of a cross-link device error. If the fallback copy
|
||||
// succeeds, src is still removed, emulating normal rename behavior.
|
||||
func renameWithFallback(src, dest string) error {
|
||||
fi, err := os.Lstat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -360,12 +361,13 @@ func renameElseCopy(src, dest string) error {
|
|||
// copy if we detect that case. syscall.EXDEV is the common name for the
|
||||
// cross device link error which has varying output text across different
|
||||
// operating systems.
|
||||
var cerr error
|
||||
if terr.Err == syscall.EXDEV {
|
||||
vlogf("Cross link err (is temp dir on same partition as project?); falling back to manual copy: %s", terr)
|
||||
if fi.IsDir() {
|
||||
return copyFolder(src, dest)
|
||||
cerr = copyFolder(src, dest)
|
||||
} else {
|
||||
return copyFile(src, dest)
|
||||
cerr = copyFile(src, dest)
|
||||
}
|
||||
} else if runtime.GOOS == "windows" {
|
||||
// In windows it can drop down to an operating system call that
|
||||
|
@ -377,14 +379,20 @@ func renameElseCopy(src, dest string) error {
|
|||
if ok && noerr == 0x11 {
|
||||
vlogf("Cross link err (is temp dir on same partition as project?); falling back to manual copy: %s", terr)
|
||||
if fi.IsDir() {
|
||||
return copyFolder(src, dest)
|
||||
cerr = copyFolder(src, dest)
|
||||
} else {
|
||||
return copyFile(src, dest)
|
||||
cerr = copyFile(src, dest)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return terr
|
||||
}
|
||||
|
||||
return terr
|
||||
if cerr != nil {
|
||||
return cerr
|
||||
}
|
||||
|
||||
return os.RemoveAll(src)
|
||||
}
|
||||
|
||||
// copyFolder takes in a directory and copies its contents to the destination.
|
||||
|
|
|
@ -154,7 +154,7 @@ func (sw safeWriter) writeAllSafe(forceVendor bool) error {
|
|||
if _, err := os.Stat(mpath); err == nil {
|
||||
// move out the old one
|
||||
tmploc := filepath.Join(td, manifestName+".orig")
|
||||
failerr = renameElseCopy(mpath, tmploc)
|
||||
failerr = renameWithFallback(mpath, tmploc)
|
||||
if failerr != nil {
|
||||
goto fail
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ func (sw safeWriter) writeAllSafe(forceVendor bool) error {
|
|||
}
|
||||
|
||||
// move in the new one
|
||||
failerr = renameElseCopy(filepath.Join(td, manifestName), mpath)
|
||||
failerr = renameWithFallback(filepath.Join(td, manifestName), mpath)
|
||||
if failerr != nil {
|
||||
goto fail
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ func (sw safeWriter) writeAllSafe(forceVendor bool) error {
|
|||
// move out the old one
|
||||
tmploc := filepath.Join(td, lockName+".orig")
|
||||
|
||||
failerr = renameElseCopy(lpath, tmploc)
|
||||
failerr = renameWithFallback(lpath, tmploc)
|
||||
if failerr != nil {
|
||||
goto fail
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ func (sw safeWriter) writeAllSafe(forceVendor bool) error {
|
|||
}
|
||||
|
||||
// move in the new one
|
||||
failerr = renameElseCopy(filepath.Join(td, lockName), lpath)
|
||||
failerr = renameWithFallback(filepath.Join(td, lockName), lpath)
|
||||
if failerr != nil {
|
||||
goto fail
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ func (sw safeWriter) writeAllSafe(forceVendor bool) error {
|
|||
vendorbak = filepath.Join(td, "vendor.orig")
|
||||
}
|
||||
|
||||
failerr = renameElseCopy(vpath, vendorbak)
|
||||
failerr = renameWithFallback(vpath, vendorbak)
|
||||
if failerr != nil {
|
||||
goto fail
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ func (sw safeWriter) writeAllSafe(forceVendor bool) error {
|
|||
}
|
||||
|
||||
// move in the new one
|
||||
failerr = renameElseCopy(filepath.Join(td, "vendor"), vpath)
|
||||
failerr = renameWithFallback(filepath.Join(td, "vendor"), vpath)
|
||||
if failerr != nil {
|
||||
goto fail
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ fail:
|
|||
// If we failed at any point, move all the things back into place, then bail
|
||||
for _, pair := range restore {
|
||||
// Nothing we can do on err here, as we're already in recovery mode
|
||||
renameElseCopy(pair.from, pair.to)
|
||||
renameWithFallback(pair.from, pair.to)
|
||||
}
|
||||
return failerr
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче