Skip to content

Commit

Permalink
fix: trim duplicated space
Browse files Browse the repository at this point in the history
  • Loading branch information
cvvz committed Apr 25, 2023
1 parent ec3aa96 commit 7f39e1b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ func (d *Driver) mountBlobfuseWithProxy(args, protocol string, authEnv []string)
func (d *Driver) mountBlobfuseInsideDriver(args string, protocol string, authEnv []string) (string, error) {
var cmd *exec.Cmd

args = volumehelper.TrimDuplicatedSpace(args)

mountLog := "mount inside driver with"
if protocol == Fuse2 {
mountLog += " v2"
Expand Down
2 changes: 2 additions & 0 deletions pkg/blobfuse-proxy/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ func (server *MountServer) MountAzureBlob(ctx context.Context,
klog.V(2).Infof("append --ignore-open-flags=true to mount args")
args = args + " " + "--ignore-open-flags=true"
}
args = util.TrimDuplicatedSpace(args)
klog.V(2).Infof("mount with v2, protocol: %s, args: %s", protocol, args)
cmd = exec.Command("blobfuse2", strings.Split(args, " ")...)
} else {
args = util.TrimDuplicatedSpace(args)
klog.V(2).Infof("mount with v1, protocol: %s, args: %s", protocol, args)
cmd = exec.Command("blobfuse", strings.Split(args, " ")...)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package util
import (
"fmt"
"os"
"regexp"
"strings"
"sync"

Expand Down Expand Up @@ -183,3 +184,9 @@ func GetOSInfo(f interface{}) (*OsInfo, error) {
klog.V(2).Infof("get OS info: %v", oi)
return oi, nil
}

func TrimDuplicatedSpace(s string) string {
reg := regexp.MustCompile(`\s+`)
s = reg.ReplaceAllString(s, " ")
return s
}
26 changes: 26 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,29 @@ func TestGetOSInfo(t *testing.T) {
})
}
}

func TestTrimDuplicatedSpace(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want string
}{
{
name: "trim duplicated space",
args: args{
s: " fo o bar ",
},
want: " fo o bar ",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := TrimDuplicatedSpace(tt.args.s); got != tt.want {
t.Errorf("TrimDuplicatedSpace() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 7f39e1b

Please sign in to comment.