From ca6cd808a728c7dc5a2f579a4c3c999e2735b79a Mon Sep 17 00:00:00 2001 From: joshuafc Date: Thu, 27 May 2021 19:14:10 +0800 Subject: [PATCH] Clear .passwd-s3fs before write new AccessKey & SecretKey Two Storage Class, with different s3 cluster, so different AccessKey & SecretKey. The second s3 cluster cannot mount. Because of .passwd-s3fs is not cleared before write it's new AccessKey & SecretKey. for examble: *****:******xxxx ***is new AccessKey & SecretKey. And xxxx is part of old AccessKey & SecretKey. Use os.O_TRUNC to clear .passwd-s3fs before write new AccessKey & SecretKey. --- pkg/mounter/s3fs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/mounter/s3fs.go b/pkg/mounter/s3fs.go index 9649388..88c9fa1 100644 --- a/pkg/mounter/s3fs.go +++ b/pkg/mounter/s3fs.go @@ -55,7 +55,7 @@ func (s3fs *s3fsMounter) Mount(source string, target string) error { func writes3fsPass(pwFileContent string) error { pwFileName := fmt.Sprintf("%s/.passwd-s3fs", os.Getenv("HOME")) - pwFile, err := os.OpenFile(pwFileName, os.O_RDWR|os.O_CREATE, 0600) + pwFile, err := os.OpenFile(pwFileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return err }