Unverified Commit c41037d9 authored by Brice Rising's avatar Brice Rising Committed by Matt Farina
Browse files

Fix rename for helm dep upgrade

helm dependency upgrade wasn't working on certain file system because it assumes that os.rename is available. Since rename isn't available for subfolders in docker containers, I ripped a fallback rename strategy from dep (https://github.com/golang/dep/blob/5b1fe9e6d89372487d0aac78d9c5362a517857e7/internal/fs/fs.go#L103-L118

) that works in docker.

Signed-off-by: default avatarBrice Rising <brice.rising@slalom.com>
(cherry picked from commit 94d87ef9)
No related merge requests found
Showing with 1906 additions and 3 deletions
+1906 -3
......@@ -31,6 +31,7 @@ import (
"github.com/ghodss/yaml"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/fsutil"
"k8s.io/helm/pkg/getter"
"k8s.io/helm/pkg/helm/helmpath"
"k8s.io/helm/pkg/proto/hapi/chart"
......@@ -205,7 +206,7 @@ func (m *Manager) downloadAll(deps []*chartutil.Dependency) error {
return fmt.Errorf("%q is not a directory", destPath)
}
if err := os.Rename(destPath, tmpPath); err != nil {
if err := fs.RenameWithFallback(destPath, tmpPath); err != nil {
return fmt.Errorf("Unable to move current charts to tmp dir: %v", err)
}
......@@ -307,7 +308,7 @@ func (m *Manager) downloadAll(deps []*chartutil.Dependency) error {
if err := os.RemoveAll(destPath); err != nil {
return fmt.Errorf("Failed to remove %v: %v", destPath, err)
}
if err := os.Rename(tmpPath, destPath); err != nil {
if err := fs.RenameWithFallback(tmpPath, destPath); err != nil {
return fmt.Errorf("Unable to move current charts to tmp dir: %v", err)
}
return saveError
......@@ -686,7 +687,7 @@ func move(tmpPath, destPath string) error {
filename := file.Name()
tmpfile := filepath.Join(tmpPath, filename)
destfile := filepath.Join(destPath, filename)
if err := os.Rename(tmpfile, destfile); err != nil {
if err := fs.RenameWithFallback(tmpfile, destfile); err != nil {
return fmt.Errorf("Unable to move local charts to charts dir: %v", err)
}
}
......
This diff is collapsed.
This diff is collapsed.
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !windows
package fs
import (
"os"
"syscall"
"github.com/pkg/errors"
)
// renameFallback attempts to determine the appropriate fallback to failed rename
// operation depending on the resulting error.
func renameFallback(err error, src, dst string) error {
// Rename may fail if src and dst are on different devices; fall back to
// 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.
terr, ok := err.(*os.LinkError)
if !ok {
return err
} else if terr.Err != syscall.EXDEV {
return errors.Wrapf(terr, "link error: cannot rename %s to %s", src, dst)
}
return renameByCopy(src, dst)
}
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build windows
package fs
import (
"os"
"syscall"
"github.com/pkg/errors"
)
// renameFallback attempts to determine the appropriate fallback to failed rename
// operation depending on the resulting error.
func renameFallback(err error, src, dst string) error {
// Rename may fail if src and dst are on different devices; fall back to
// 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.
terr, ok := err.(*os.LinkError)
if !ok {
return err
}
if terr.Err != syscall.EXDEV {
// 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 {
return errors.Wrapf(terr, "link error: cannot rename %s to %s", src, dst)
}
}
return renameByCopy(src, dst)
}
../test.file
\ No newline at end of file
/non/existing/file
\ No newline at end of file
C:/Users/ibrahim/go/src/github.com/golang/dep/internal/fs/testdata/test.file
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment