From d43004b9bddbe4a1bca784e1b962c869778c5a2c Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 28 Dec 2022 11:08:51 +0900 Subject: [PATCH] use path/filepath instead of path --- common/client.go | 7 ++++--- common/common.go | 8 ++++---- common/common_test.go | 16 +++++++-------- common/configuration.go | 8 ++++---- common/configuration_test.go | 8 ++++---- example/example_objectstorage_test.go | 20 +++++++++---------- .../transfer/multipart_manifest_test.go | 4 ++-- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/common/client.go b/common/client.go index 8cf7f2ffd0..0a7ab7b866 100644 --- a/common/client.go +++ b/common/client.go @@ -20,6 +20,7 @@ import ( "os" "os/user" "path" + "path/filepath" "reflect" "runtime" "strings" @@ -323,7 +324,7 @@ func getHomeFolder() string { func DefaultConfigProvider() ConfigurationProvider { defaultConfigFile := getDefaultConfigFilePath() homeFolder := getHomeFolder() - secondaryConfigFile := path.Join(homeFolder, secondaryConfigDirName, defaultConfigFileName) + secondaryConfigFile := filepath.Join(homeFolder, secondaryConfigDirName, defaultConfigFileName) defaultFileProvider, _ := ConfigurationProviderFromFile(defaultConfigFile, "") secondaryFileProvider, _ := ConfigurationProviderFromFile(secondaryConfigFile, "") @@ -336,7 +337,7 @@ func DefaultConfigProvider() ConfigurationProvider { func getDefaultConfigFilePath() string { homeFolder := getHomeFolder() - defaultConfigFile := path.Join(homeFolder, defaultConfigDirName, defaultConfigFileName) + defaultConfigFile := filepath.Join(homeFolder, defaultConfigDirName, defaultConfigFileName) if _, err := os.Stat(defaultConfigFile); err == nil { return defaultConfigFile } @@ -382,7 +383,7 @@ func setRawPath(u *url.URL) error { func CustomProfileConfigProvider(customConfigPath string, profile string) ConfigurationProvider { homeFolder := getHomeFolder() if customConfigPath == "" { - customConfigPath = path.Join(homeFolder, defaultConfigDirName, defaultConfigFileName) + customConfigPath = filepath.Join(homeFolder, defaultConfigDirName, defaultConfigFileName) } customFileProvider, _ := ConfigurationProviderFromFileWithProfile(customConfigPath, profile, "") defaultFileProvider, _ := ConfigurationProviderFromFileWithProfile(customConfigPath, "DEFAULT", "") diff --git a/common/common.go b/common/common.go index 5a527a3e1d..965c2b6cb4 100644 --- a/common/common.go +++ b/common/common.go @@ -9,13 +9,13 @@ import ( "io/ioutil" "net/http" "os" - "path" + "path/filepath" "regexp" "strings" "time" ) -//Region type for regions +// Region type for regions type Region string const ( @@ -140,7 +140,7 @@ func (region Region) RealmID() (string, error) { return "", fmt.Errorf("cannot find realm for region : %s", region) } -//StringToRegion convert a string to Region type +// StringToRegion convert a string to Region type func StringToRegion(stringRegion string) (r Region) { regionStr := strings.ToLower(stringRegion) // check if short region name provided @@ -238,7 +238,7 @@ func setRegionMetadataFromCfgFile(region *string) bool { // Mark readCfgFile Flag as false since it has already been visited. readCfgFile = false homeFolder := getHomeFolder() - configFile := path.Join(homeFolder, regionMetadataCfgDirName, regionMetadataCfgFileName) + configFile := filepath.Join(homeFolder, regionMetadataCfgDirName, regionMetadataCfgFileName) if jsonArr, ok := readAndParseConfigFile(&configFile); ok { added := false for _, jsonItem := range jsonArr { diff --git a/common/common_test.go b/common/common_test.go index 5a0554cddf..119281af26 100644 --- a/common/common_test.go +++ b/common/common_test.go @@ -9,7 +9,7 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" "strings" "testing" @@ -356,8 +356,8 @@ func TestStringToRegion(t *testing.T) { "regionIdentifier" : "us-testregion-3" } ]` - tmpLocation := path.Join(getHomeFolder(), ".oci", "regions-config.json") - tmpPath := path.Join(getHomeFolder(), ".oci") + tmpLocation := filepath.Join(getHomeFolder(), ".oci", "regions-config.json") + tmpPath := filepath.Join(getHomeFolder(), ".oci") if _, err := os.Stat(tmpPath); err != nil && os.IsNotExist(err) { if err := os.Mkdir(tmpPath, 0777); err != nil { @@ -466,8 +466,8 @@ func TestSetRegionMetadataFromCfgFileWithNormalRegionName(t *testing.T) { "regionIdentifier" : "us-testregion-3" } ]` - tmpLocation := path.Join(getHomeFolder(), ".oci", "regions-config.json") - tmpPath := path.Join(getHomeFolder(), ".oci") + tmpLocation := filepath.Join(getHomeFolder(), ".oci", "regions-config.json") + tmpPath := filepath.Join(getHomeFolder(), ".oci") if _, err := os.Stat(tmpPath); err != nil && os.IsNotExist(err) { if err := os.Mkdir(tmpPath, 0777); err != nil { @@ -513,8 +513,8 @@ func TestSetRegionMetadataFromCfgFileWithShortRegionName(t *testing.T) { "regionIdentifier" : "us-testregion-3" } ]` - tmpLocation := path.Join(getHomeFolder(), ".oci", "regions-config.json") - tmpPath := path.Join(getHomeFolder(), ".oci") + tmpLocation := filepath.Join(getHomeFolder(), ".oci", "regions-config.json") + tmpPath := filepath.Join(getHomeFolder(), ".oci") if _, err := os.Stat(tmpPath); err != nil && os.IsNotExist(err) { if err := os.Mkdir(tmpPath, 0777); err != nil { @@ -547,7 +547,7 @@ func TestSetRegionMetadataFromCfgFileWithShortRegionName(t *testing.T) { func TestSetRegionMetadataFromCfgFileWithInvalidFileContent(t *testing.T) { fileContent := "" - tmpLocation := path.Join(getHomeFolder(), ".oci", "regions-config.json") + tmpLocation := filepath.Join(getHomeFolder(), ".oci", "regions-config.json") if _, err := os.Stat(tmpLocation); err == nil || os.IsExist(err) { os.Remove(tmpLocation) diff --git a/common/configuration.go b/common/configuration.go index 9705ec32f2..5468e73266 100644 --- a/common/configuration.go +++ b/common/configuration.go @@ -9,7 +9,7 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" "regexp" "strings" ) @@ -380,12 +380,12 @@ func parseConfigAtLine(start int, content []string) (info *configFileInfo, err e // cleans and expands the path if it contains a tilde , returns the expanded path or the input path as is if not expansion // was performed -func expandPath(filepath string) (expandedPath string) { - cleanedPath := path.Clean(filepath) +func expandPath(filename string) (expandedPath string) { + cleanedPath := filepath.Clean(filename) expandedPath = cleanedPath if strings.HasPrefix(cleanedPath, "~") { rest := cleanedPath[2:] - expandedPath = path.Join(getHomeFolder(), rest) + expandedPath = filepath.Join(getHomeFolder(), rest) } return } diff --git a/common/configuration_test.go b/common/configuration_test.go index 1663342c7b..27986eae21 100644 --- a/common/configuration_test.go +++ b/common/configuration_test.go @@ -9,7 +9,7 @@ import ( "os" "testing" - "path" + "path/filepath" "strings" "github.com/stretchr/testify/assert" @@ -836,7 +836,7 @@ compartment = somecompartment region=someregion ` - tmpKeyLocation := path.Join(getHomeFolder(), "testKey") + tmpKeyLocation := filepath.Join(getHomeFolder(), "testKey") e := ioutil.WriteFile(tmpKeyLocation, []byte(testEncryptedPrivateKeyConf), 777) if e != nil { assert.FailNow(t, e.Error()) @@ -876,7 +876,7 @@ func TestExpandPath(t *testing.T) { { name: "should expand tilde and return appended home dir", inPath: "~/somepath", - expectedPath: path.Join(home, "somepath"), + expectedPath: filepath.Join(home, "somepath"), }, { name: "should not do anything", @@ -886,7 +886,7 @@ func TestExpandPath(t *testing.T) { { name: "should replace one tilde only", inPath: "~/~/some/path", - expectedPath: path.Join(home, "~/some/path"), + expectedPath: filepath.Join(home, "~/some/path"), }, } for _, tio := range testIO { diff --git a/example/example_objectstorage_test.go b/example/example_objectstorage_test.go index 5bc100a2c7..22d0a524ba 100644 --- a/example/example_objectstorage_test.go +++ b/example/example_objectstorage_test.go @@ -12,7 +12,7 @@ import ( "log" "net/http" "os" - "path" + "path/filepath" "github.com/oracle/oci-go-sdk/v65/common" "github.com/oracle/oci-go-sdk/v65/example/helpers" @@ -33,13 +33,13 @@ func ExampleObjectStorage_UploadFile() { defer deleteBucket(ctx, c, namespace, bname) contentlen := 1024 * 1000 - filepath, filesize := helpers.WriteTempFileOfSize(int64(contentlen)) - filename := path.Base(filepath) + fpath, filesize := helpers.WriteTempFileOfSize(int64(contentlen)) + filename := filepath.Base(fpath) defer func() { os.Remove(filename) }() - file, e := os.Open(filepath) + file, e := os.Open(fpath) defer file.Close() helpers.FatalIfError(e) @@ -69,8 +69,8 @@ func ExampleObjectStorage_UploadManager_UploadFile() { defer deleteBucket(ctx, c, namespace, bname) contentlen := 1024 * 1024 * 300 // 300MB - filepath, _ := helpers.WriteTempFileOfSize(int64(contentlen)) - filename := path.Base(filepath) + fpath, _ := helpers.WriteTempFileOfSize(int64(contentlen)) + filename := filepath.Base(fpath) defer os.Remove(filename) uploadManager := transfer.NewUploadManager() @@ -86,7 +86,7 @@ func ExampleObjectStorage_UploadManager_UploadFile() { ObjectStorageClient: &c, EnableMultipartChecksumVerification: common.Bool(true), }, - FilePath: filepath, + FilePath: fpath, } // if you want to overwrite default value, you can do it @@ -137,8 +137,8 @@ func ExampleObjectStorage_UploadManager_Stream() { defer deleteBucket(ctx, c, namespace, bname) contentlen := 1024 * 1000 * 130 // 130MB - filepath, _ := helpers.WriteTempFileOfSize(int64(contentlen)) - filename := path.Base(filepath) + fpath, _ := helpers.WriteTempFileOfSize(int64(contentlen)) + filename := filepath.Base(fpath) defer func() { os.Remove(filename) }() @@ -146,7 +146,7 @@ func ExampleObjectStorage_UploadManager_Stream() { uploadManager := transfer.NewUploadManager() objectName := "sampleStreamUploadObj" - file, _ := os.Open(filepath) + file, _ := os.Open(fpath) defer file.Close() req := transfer.UploadStreamRequest{ diff --git a/objectstorage/transfer/multipart_manifest_test.go b/objectstorage/transfer/multipart_manifest_test.go index 01971d0a87..3a2f72a2a9 100644 --- a/objectstorage/transfer/multipart_manifest_test.go +++ b/objectstorage/transfer/multipart_manifest_test.go @@ -5,7 +5,7 @@ package transfer import ( "os" - "path" + "path/filepath" "testing" "github.com/oracle/oci-go-sdk/v65/example/helpers" @@ -70,7 +70,7 @@ func TestSplitFileParts(t *testing.T) { assert.Equal(t, testData.expectedLastPartSize, parts[len(parts)-1].size) file.Close() - os.Remove(path.Base(filePath)) + os.Remove(filepath.Base(filePath)) close(done) } }