Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:修复windows文件名称问题 #205

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clients/cache/disk_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@ import (
"fmt"
"io/ioutil"
"os"
"runtime"
"strconv"
"strings"

"github.com/go-errors/errors"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/common/file"
"github.com/nacos-group/nacos-sdk-go/common/logger"
"github.com/nacos-group/nacos-sdk-go/model"
"github.com/nacos-group/nacos-sdk-go/util"
)

func GetFileName(cacheKey string, cacheDir string) string {

if runtime.GOOS == "windows" {
cacheKey = strings.ReplaceAll(cacheKey, ":", constant.WINDOWS_LEGAL_NAME_SPLITER)
zhaoyunxing92 marked this conversation as resolved.
Show resolved Hide resolved
}

return cacheDir + string(os.PathSeparator) + cacheKey
}

Expand Down
35 changes: 35 additions & 0 deletions clients/cache/disk_cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 1999-2020 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cache

import (
"runtime"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetFileName(t *testing.T) {

name := GetFileName("nacos@@providers:org.apache.dubbo.UserProvider:hangzhou", "tmp")

if runtime.GOOS == "windows" {
assert.Equal(t, name, "tmp\\nacos@@providers&org.apache.dubbo.UserProvider&hangzhou")
} else {
assert.Equal(t, name, "tmp/nacos@@providers:org.apache.dubbo.UserProvider:hangzhou")
}
}
1 change: 1 addition & 0 deletions common/constant/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ const (
NAMING_INSTANCE_ID_SPLITTER = "#"
DefaultClientErrorCode = "SDK.NacosError"
DEFAULT_SERVER_SCHEME = "http"
WINDOWS_LEGAL_NAME_SPLITER = "&"
)