diff --git a/common/client.go b/common/client.go index 116ee0e4f6..ff02e129d1 100644 --- a/common/client.go +++ b/common/client.go @@ -20,6 +20,7 @@ import ( "os" "os/user" "path" + "path/filepath" "reflect" "runtime" "strings" @@ -324,7 +325,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, "") @@ -337,7 +338,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 } @@ -383,7 +384,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 6061c1a2d9..079ee17970 100644 --- a/common/common.go +++ b/common/common.go @@ -9,7 +9,7 @@ import ( "io/ioutil" "net/http" "os" - "path" + "path/filepath" "regexp" "strings" "time" @@ -244,7 +244,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 64ec8dc564..b9406eea84 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 2989598a43..4176535cd1 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 7281739c7d..d1e6f4fecb 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 8cac6e9cc1..72c0a69e92 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) } }