From 79f0e70ce8dbb43e1baae628ac703108642774bc Mon Sep 17 00:00:00 2001 From: KUOKA Yusuke Date: Thu, 30 Aug 2018 17:20:38 +0900 Subject: [PATCH] fix: avoid "cross-device link" errors while decrypting secrets (#260) ref https://github.com/roboll/helmfile/issues/251#issuecomment-417166296 --- helmexec/exec.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/helmexec/exec.go b/helmexec/exec.go index 9bd03d8a..4039e3f6 100644 --- a/helmexec/exec.go +++ b/helmexec/exec.go @@ -115,9 +115,18 @@ func (helm *execer) DecryptSecret(name string) (string, error) { if err != nil { return "", err } - tmpFile.Close() + defer tmpFile.Close() - err = os.Rename(name+".dec", tmpFile.Name()) + // os.Rename seems to results in "cross-device link` errors in some cases + // Instead of moving, copy it to the destination temp file as a work-around + // See https://github.com/roboll/helmfile/issues/251#issuecomment-417166296 + decFile, err := os.Open(name + ".dec") + if err != nil { + return "", err + } + defer decFile.Close() + + _, err = io.Copy(tmpFile, decFile) if err != nil { return "", err }