diff --git a/src/.golangci.yml b/src/.golangci.yml index 25b767257..ab083137f 100644 --- a/src/.golangci.yml +++ b/src/.golangci.yml @@ -25,6 +25,9 @@ linters-settings: # Don't allow creating contexts without logging in tests. Use an ignore # lower down to ensure usages of this outside of tests aren't reported. - 'context\.(Background|TODO)(# tests should use tester\.NewContext )?' + # Don't allow use of pathas it hardcodes separator to `/`. + # Use filepath instead. + - '\bpath\.(Ext|Base|Dir|Join)' lll: line-length: 120 revive: diff --git a/src/cli/config/config.go b/src/cli/config/config.go index 8c140e856..a7a141255 100644 --- a/src/cli/config/config.go +++ b/src/cli/config/config.go @@ -3,7 +3,6 @@ package config import ( "context" "os" - "path" "path/filepath" "strings" @@ -118,14 +117,14 @@ func initWithViper(vpr *viper.Viper, configFP string) error { // We also configure the path, type and filename // because `vpr.SafeWriteConfig` needs these set to // work correctly (it does not use the configured file) - vpr.AddConfigPath(path.Dir(configFP)) + vpr.AddConfigPath(filepath.Dir(configFP)) - ext := path.Ext(configFP) + ext := filepath.Ext(configFP) if len(ext) == 0 { return errors.New("config file requires an extension e.g. `toml`") } - fileName := path.Base(configFP) + fileName := filepath.Base(configFP) fileName = strings.TrimSuffix(fileName, ext) vpr.SetConfigType(strings.TrimPrefix(ext, ".")) vpr.SetConfigName(fileName) diff --git a/src/cli/config/config_test.go b/src/cli/config/config_test.go index a59a5f69e..d8f5371f4 100644 --- a/src/cli/config/config_test.go +++ b/src/cli/config/config_test.go @@ -4,7 +4,7 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" "testing" "github.com/spf13/viper" @@ -50,7 +50,7 @@ func (suite *ConfigSuite) TestReadRepoConfigBasic() { // Generate test config file testConfigData := fmt.Sprintf(configFileTemplate, b, tID) - testConfigFilePath := path.Join(t.TempDir(), "corso.toml") + testConfigFilePath := filepath.Join(t.TempDir(), "corso.toml") err := ioutil.WriteFile(testConfigFilePath, []byte(testConfigData), 0o700) require.NoError(t, err) @@ -81,7 +81,7 @@ func (suite *ConfigSuite) TestWriteReadConfig() { ) // Configure viper to read test config file - testConfigFilePath := path.Join(t.TempDir(), "corso.toml") + testConfigFilePath := filepath.Join(t.TempDir(), "corso.toml") require.NoError(t, initWithViper(vpr, testConfigFilePath), "initializing repo config") s3Cfg := storage.S3Config{Bucket: bkt} @@ -111,7 +111,7 @@ func (suite *ConfigSuite) TestMustMatchConfig() { ) // Configure viper to read test config file - testConfigFilePath := path.Join(t.TempDir(), "corso.toml") + testConfigFilePath := filepath.Join(t.TempDir(), "corso.toml") require.NoError(t, initWithViper(vpr, testConfigFilePath), "initializing repo config") s3Cfg := storage.S3Config{Bucket: bkt} @@ -213,7 +213,7 @@ func (suite *ConfigIntegrationSuite) TestGetStorageAndAccount() { ) // Configure viper to read test config file - testConfigFilePath := path.Join(t.TempDir(), "corso.toml") + testConfigFilePath := filepath.Join(t.TempDir(), "corso.toml") require.NoError(t, initWithViper(vpr, testConfigFilePath), "initializing repo config") s3Cfg := storage.S3Config{ diff --git a/src/internal/kopia/path_encoder.go b/src/internal/kopia/path_encoder.go index dc25f59c8..f30cfaf08 100644 --- a/src/internal/kopia/path_encoder.go +++ b/src/internal/kopia/path_encoder.go @@ -24,6 +24,8 @@ func encodeElements(elements ...string) []string { // if they were a path. The elements are joined with the separator in the golang // path package. func encodeAsPath(elements ...string) string { + // Needs `/` to be used a separator here + //nolint:forbidigo return path.Join(encodeElements(elements...)...) } diff --git a/src/internal/tester/config.go b/src/internal/tester/config.go index 852bbc054..3c8b0a742 100644 --- a/src/internal/tester/config.go +++ b/src/internal/tester/config.go @@ -2,7 +2,7 @@ package tester import ( "os" - "path" + "path/filepath" "strings" "testing" @@ -59,16 +59,16 @@ func NewTestViper() (*viper.Viper, error) { } // Or use a custom file location - ext := path.Ext(configFilePath) + ext := filepath.Ext(configFilePath) if len(ext) == 0 { return nil, errors.New("corso_test requires an extension") } vpr.SetConfigFile(configFilePath) - vpr.AddConfigPath(path.Dir(configFilePath)) + vpr.AddConfigPath(filepath.Dir(configFilePath)) vpr.SetConfigType(ext[1:]) - fileName := path.Base(configFilePath) + fileName := filepath.Base(configFilePath) fileName = strings.TrimSuffix(fileName, ext) vpr.SetConfigName(fileName) @@ -139,19 +139,19 @@ func MakeTempTestConfigClone(t *testing.T, overrides map[string]string) (*viper. return nil, "", err } - fName := path.Base(os.Getenv(EnvCorsoTestConfigFilePath)) + fName := filepath.Base(os.Getenv(EnvCorsoTestConfigFilePath)) if len(fName) == 0 || fName == "." || fName == "/" { fName = ".corso_test.toml" } tDir := t.TempDir() - tDirFp := path.Join(tDir, fName) + tDirFp := filepath.Join(tDir, fName) if _, err := os.Create(tDirFp); err != nil { return nil, "", err } - ext := path.Ext(fName) + ext := filepath.Ext(fName) vpr := viper.New() vpr.SetConfigFile(tDirFp) vpr.AddConfigPath(tDir)