Skip to content

Commit 02bbeb9

Browse files
ostermanhaitham911
andauthored
Revert "Replace path.Join with filepath.Join (#856)" (#887)
* Revert "Replace path.Join with filepath.Join (#856)" This reverts commit 2051592. * fix some missing atmosConfig changes * get a go test report * attempt to fix vendor errors * revert to makefile as output is too large for summary * try to fix vendor test for windows * Try to sanitize filename on windows * sanitize filenames everywhere a URI is used to derive the filename * drop query string * try to fix globs * revert doublestar fix * fix vendor on windows * fix unit test replace path with filepath --------- Co-authored-by: Haitham Rageh <[email protected]>
1 parent b406027 commit 02bbeb9

29 files changed

+163
-117
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ jobs:
142142
143143
- name: Acceptance tests
144144
timeout-minutes: 10
145-
run: |
146-
make testacc
145+
run: make testacc
147146

148147
docker:
149148
name: "Docker Lint"

cmd/cmd_utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"os"
8+
"path"
89
"path/filepath"
910
"strings"
1011
"time"
@@ -404,7 +405,7 @@ func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) {
404405
u.PrintMessageInColor("atmos.yaml", c1)
405406
fmt.Println(" CLI config file was not found.")
406407
fmt.Print("\nThe default Atmos stacks directory is set to ")
407-
u.PrintMessageInColor(filepath.Join(atmosConfig.BasePath, atmosConfig.Stacks.BasePath), c1)
408+
u.PrintMessageInColor(path.Join(atmosConfig.BasePath, atmosConfig.Stacks.BasePath), c1)
408409
fmt.Println(",\nbut the directory does not exist in the current path.")
409410
} else {
410411
// If Atmos found an `atmos.yaml` config file, but it defines invalid paths to Atmos stacks and components

cmd/docs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"os"
66
"os/exec"
7-
"path/filepath"
7+
"path"
88
"runtime"
99

1010
"github.com/charmbracelet/glamour"
@@ -59,7 +59,7 @@ var docsCmd = &cobra.Command{
5959
}
6060

6161
// Construct the full path to the Terraform component by combining the Atmos base path, Terraform base path, and component name
62-
componentPath := filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, info.Component)
62+
componentPath := path.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, info.Component)
6363
componentPathExists, err := u.IsDirectory(componentPath)
6464
if err != nil {
6565
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
@@ -68,7 +68,7 @@ var docsCmd = &cobra.Command{
6868
u.LogErrorAndExit(schema.AtmosConfiguration{}, fmt.Errorf("Component '%s' not found in path: '%s'", info.Component, componentPath))
6969
}
7070

71-
readmePath := filepath.Join(componentPath, "README.md")
71+
readmePath := path.Join(componentPath, "README.md")
7272
if _, err := os.Stat(readmePath); err != nil {
7373
if os.IsNotExist(err) {
7474
u.LogErrorAndExit(schema.AtmosConfiguration{}, fmt.Errorf("No README found for component: %s", info.Component))

internal/exec/atlantis_generate_repo_config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package exec
22

33
import (
44
"fmt"
5+
"path"
56
"path/filepath"
67
"reflect"
78
"strings"
@@ -338,7 +339,7 @@ func ExecuteAtlantisGenerateRepoConfig(
338339
}
339340

340341
// Absolute path to the terraform component
341-
terraformComponentPath := filepath.Join(
342+
terraformComponentPath := path.Join(
342343
atmosConfig.BasePath,
343344
atmosConfig.Components.Terraform.BasePath,
344345
terraformComponent,

internal/exec/aws_eks_update_kubeconfig.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package exec
22

33
import (
44
"fmt"
5-
"path/filepath"
5+
"path"
66
"strings"
77

88
"github.com/pkg/errors"
@@ -158,11 +158,11 @@ func ExecuteAwsEksUpdateKubeconfig(kubeconfigContext schema.AwsEksUpdateKubeconf
158158

159159
configAndStacksInfo.ComponentType = "terraform"
160160
configAndStacksInfo, err = ProcessStacks(atmosConfig, configAndStacksInfo, true, true)
161-
shellCommandWorkingDir = filepath.Join(atmosConfig.TerraformDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
161+
shellCommandWorkingDir = path.Join(atmosConfig.TerraformDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
162162
if err != nil {
163163
configAndStacksInfo.ComponentType = "helmfile"
164164
configAndStacksInfo, err = ProcessStacks(atmosConfig, configAndStacksInfo, true, true)
165-
shellCommandWorkingDir = filepath.Join(atmosConfig.HelmfileDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
165+
shellCommandWorkingDir = path.Join(atmosConfig.HelmfileDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
166166
if err != nil {
167167
return err
168168
}

internal/exec/describe_affected_utils.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,9 @@ func executeDescribeAffected(
432432
}
433433

434434
// Update paths to point to the cloned remote repo dir
435-
atmosConfig.StacksBaseAbsolutePath = filepath.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Stacks.BasePath)
436-
atmosConfig.TerraformDirAbsolutePath = filepath.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Components.Terraform.BasePath)
437-
atmosConfig.HelmfileDirAbsolutePath = filepath.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Components.Helmfile.BasePath)
435+
atmosConfig.StacksBaseAbsolutePath = path.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Stacks.BasePath)
436+
atmosConfig.TerraformDirAbsolutePath = path.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Components.Terraform.BasePath)
437+
atmosConfig.HelmfileDirAbsolutePath = path.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Components.Helmfile.BasePath)
438438

439439
atmosConfig.StackConfigFilesAbsolutePaths, err = u.JoinAbsolutePathWithPaths(
440440
filepath.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Stacks.BasePath),
@@ -1182,9 +1182,9 @@ func isComponentFolderChanged(
11821182

11831183
switch componentType {
11841184
case "terraform":
1185-
componentPath = filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, component)
1185+
componentPath = path.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, component)
11861186
case "helmfile":
1187-
componentPath = filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Helmfile.BasePath, component)
1187+
componentPath = path.Join(atmosConfig.BasePath, atmosConfig.Components.Helmfile.BasePath, component)
11881188
}
11891189

11901190
componentPathAbs, err := filepath.Abs(componentPath)
@@ -1220,7 +1220,7 @@ func areTerraformComponentModulesChanged(
12201220
changedFiles []string,
12211221
) (bool, error) {
12221222

1223-
componentPath := filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, component)
1223+
componentPath := path.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, component)
12241224

12251225
componentPathAbs, err := filepath.Abs(componentPath)
12261226
if err != nil {
@@ -1241,7 +1241,7 @@ func areTerraformComponentModulesChanged(
12411241
continue
12421242
}
12431243

1244-
modulePath := filepath.Join(path.Dir(moduleConfig.Pos.Filename), moduleConfig.Source)
1244+
modulePath := path.Join(path.Dir(moduleConfig.Pos.Filename), moduleConfig.Source)
12451245

12461246
modulePathAbs, err := filepath.Abs(modulePath)
12471247
if err != nil {

internal/exec/helmfile.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package exec
55
import (
66
"fmt"
77
"os"
8-
"path/filepath"
8+
"path"
99

1010
"github.com/pkg/errors"
1111
"github.com/spf13/cobra"
@@ -78,20 +78,20 @@ func ExecuteHelmfile(info schema.ConfigAndStacksInfo) error {
7878
}
7979

8080
// Check if the component exists as a helmfile component
81-
componentPath := filepath.Join(atmosConfig.HelmfileDirAbsolutePath, info.ComponentFolderPrefix, info.FinalComponent)
81+
componentPath := path.Join(atmosConfig.HelmfileDirAbsolutePath, info.ComponentFolderPrefix, info.FinalComponent)
8282
componentPathExists, err := u.IsDirectory(componentPath)
8383
if err != nil || !componentPathExists {
8484
return fmt.Errorf("'%s' points to the Helmfile component '%s', but it does not exist in '%s'",
8585
info.ComponentFromArg,
8686
info.FinalComponent,
87-
filepath.Join(atmosConfig.Components.Helmfile.BasePath, info.ComponentFolderPrefix),
87+
path.Join(atmosConfig.Components.Helmfile.BasePath, info.ComponentFolderPrefix),
8888
)
8989
}
9090

9191
// Check if the component is allowed to be provisioned (`metadata.type` attribute)
9292
if (info.SubCommand == "sync" || info.SubCommand == "apply" || info.SubCommand == "deploy") && info.ComponentIsAbstract {
9393
return fmt.Errorf("abstract component '%s' cannot be provisioned since it's explicitly prohibited from being deployed "+
94-
"by 'metadata.type: abstract' attribute", filepath.Join(info.ComponentFolderPrefix, info.Component))
94+
"by 'metadata.type: abstract' attribute", path.Join(info.ComponentFolderPrefix, info.Component))
9595
}
9696

9797
// Print component variables
@@ -196,7 +196,7 @@ func ExecuteHelmfile(info schema.ConfigAndStacksInfo) error {
196196
u.LogDebug(atmosConfig, "Stack: "+info.StackFromArg)
197197
} else {
198198
u.LogDebug(atmosConfig, "Stack: "+info.StackFromArg)
199-
u.LogDebug(atmosConfig, "Stack path: "+filepath.Join(atmosConfig.BasePath, atmosConfig.Stacks.BasePath, info.Stack))
199+
u.LogDebug(atmosConfig, "Stack path: "+path.Join(atmosConfig.BasePath, atmosConfig.Stacks.BasePath, info.Stack))
200200
}
201201

202202
workingDir := constructHelmfileComponentWorkingDir(atmosConfig, info)

internal/exec/oci_utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"fmt"
99
"io"
1010
"os"
11-
"path/filepath"
11+
"path"
1212

1313
"github.com/google/go-containerregistry/pkg/name"
1414
"github.com/google/go-containerregistry/pkg/v1/remote"
@@ -30,7 +30,7 @@ func processOciImage(atmosConfig schema.AtmosConfiguration, imageName string, de
3030
defer removeTempDir(atmosConfig, tempDir)
3131

3232
// Temp tarball file name
33-
tempTarFileName := filepath.Join(tempDir, uuid.New().String()) + ".tar"
33+
tempTarFileName := path.Join(tempDir, uuid.New().String()) + ".tar"
3434

3535
// Get the image reference from the OCI registry
3636
ref, err := name.ParseReference(imageName)
@@ -91,7 +91,7 @@ func processOciImage(atmosConfig schema.AtmosConfiguration, imageName string, de
9191

9292
// Extract the layers into the destination directory
9393
for _, l := range manifest.Layers {
94-
layerPath := filepath.Join(tempDir, l)
94+
layerPath := path.Join(tempDir, l)
9595

9696
err = extractTarball(atmosConfig, layerPath, destDir)
9797
if err != nil {

internal/exec/stack_processor_utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func ProcessYAMLConfigFile(
357357

358358
found := false
359359
for _, extension := range extensions {
360-
testPath := filepath.Join(basePath, imp+extension)
360+
testPath := path.Join(basePath, imp+extension)
361361
if _, err := os.Stat(testPath); err == nil {
362362
impWithExt = imp + extension
363363
found = true
@@ -372,12 +372,12 @@ func ProcessYAMLConfigFile(
372372
} else if ext == u.YamlFileExtension || ext == u.YmlFileExtension {
373373
// Check if there's a template version of this file
374374
templatePath := impWithExt + u.TemplateExtension
375-
if _, err := os.Stat(filepath.Join(basePath, templatePath)); err == nil {
375+
if _, err := os.Stat(path.Join(basePath, templatePath)); err == nil {
376376
impWithExt = templatePath
377377
}
378378
}
379379

380-
impWithExtPath := filepath.Join(basePath, impWithExt)
380+
impWithExtPath := path.Join(basePath, impWithExt)
381381

382382
if impWithExtPath == filePath {
383383
errorMessage := fmt.Sprintf("invalid import in the manifest '%s'\nThe file imports itself in '%s'",
@@ -2180,7 +2180,7 @@ func ProcessBaseComponentConfig(
21802180
if checkBaseComponentExists {
21812181
// Check if the base component exists as Terraform/Helmfile component
21822182
// If it does exist, don't throw errors if it is not defined in YAML config
2183-
componentPath := filepath.Join(componentBasePath, baseComponent)
2183+
componentPath := path.Join(componentBasePath, baseComponent)
21842184
componentPathExists, err := u.IsDirectory(componentPath)
21852185
if err != nil || !componentPathExists {
21862186
return errors.New("The component '" + component + "' inherits from the base component '" +

internal/exec/stack_utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package exec
22

33
import (
44
"fmt"
5-
"path/filepath"
5+
"path"
66
"strings"
77

88
cfg "github.com/cloudposse/atmos/pkg/config"
@@ -164,9 +164,9 @@ func BuildComponentPath(
164164

165165
if stackComponentSection, ok := componentSectionMap[cfg.ComponentSectionName].(string); ok {
166166
if componentType == "terraform" {
167-
componentPath = filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, stackComponentSection)
167+
componentPath = path.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, stackComponentSection)
168168
} else if componentType == "helmfile" {
169-
componentPath = filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Helmfile.BasePath, stackComponentSection)
169+
componentPath = path.Join(atmosConfig.BasePath, atmosConfig.Components.Helmfile.BasePath, stackComponentSection)
170170
}
171171
}
172172

internal/exec/terraform_generate_backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package exec
22

33
import (
44
"fmt"
5-
"path/filepath"
5+
"path"
66

77
"github.com/pkg/errors"
88
"github.com/spf13/cobra"
@@ -75,7 +75,7 @@ func ExecuteTerraformGenerateBackendCmd(cmd *cobra.Command, args []string) error
7575
}
7676

7777
// Write backend config to file
78-
var backendFilePath = filepath.Join(
78+
var backendFilePath = path.Join(
7979
atmosConfig.BasePath,
8080
atmosConfig.Components.Terraform.BasePath,
8181
info.ComponentFolderPrefix,

internal/exec/terraform_generate_backends.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package exec
33
import (
44
"errors"
55
"fmt"
6+
"path"
67
"path/filepath"
78
"strings"
89

@@ -160,7 +161,7 @@ func ExecuteTerraformGenerateBackends(
160161
}
161162

162163
// Path to the terraform component
163-
terraformComponentPath := filepath.Join(
164+
terraformComponentPath := path.Join(
164165
atmosConfig.BasePath,
165166
atmosConfig.Components.Terraform.BasePath,
166167
terraformComponent,
@@ -290,7 +291,7 @@ func ExecuteTerraformGenerateBackends(
290291

291292
processedTerraformComponents[terraformComponent] = terraformComponent
292293

293-
backendFilePath = filepath.Join(
294+
backendFilePath = path.Join(
294295
terraformComponentPath,
295296
"backend.tf",
296297
)

internal/exec/terraform_generate_varfiles.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package exec
33
import (
44
"errors"
55
"fmt"
6+
"path"
67
"path/filepath"
78
"strings"
89

@@ -159,7 +160,7 @@ func ExecuteTerraformGenerateVarfiles(
159160
}
160161

161162
// Absolute path to the terraform component
162-
terraformComponentPath := filepath.Join(
163+
terraformComponentPath := path.Join(
163164
atmosConfig.BasePath,
164165
atmosConfig.Components.Terraform.BasePath,
165166
terraformComponent,

internal/exec/terraform_utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"os"
8+
"path"
89
"path/filepath"
910
"time"
1011

@@ -87,7 +88,7 @@ func execTerraformOutput(atmosConfig schema.AtmosConfiguration, component string
8788

8889
// Auto-generate backend file
8990
if atmosConfig.Components.Terraform.AutoGenerateBackendFile {
90-
backendFileName := filepath.Join(componentPath, "backend.tf.json")
91+
backendFileName := path.Join(componentPath, "backend.tf.json")
9192

9293
u.LogTrace(atmosConfig, "\nWriting the backend config to file:")
9394
u.LogTrace(atmosConfig, backendFileName)
@@ -120,7 +121,7 @@ func execTerraformOutput(atmosConfig schema.AtmosConfiguration, component string
120121
providersSection, ok := sections["providers"].(map[string]any)
121122

122123
if ok && len(providersSection) > 0 {
123-
providerOverrideFileName := filepath.Join(componentPath, "providers_override.tf.json")
124+
providerOverrideFileName := path.Join(componentPath, "providers_override.tf.json")
124125

125126
u.LogTrace(atmosConfig, "\nWriting the provider overrides to file:")
126127
u.LogTrace(atmosConfig, providerOverrideFileName)

internal/exec/validate_component.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package exec
33
import (
44
"fmt"
55
"os"
6-
"path/filepath"
6+
"path"
77

88
"github.com/mitchellh/mapstructure"
99
"github.com/pkg/errors"
@@ -197,11 +197,11 @@ func validateComponentInternal(
197197
switch schemaType {
198198
case "jsonschema":
199199
{
200-
filePath = filepath.Join(atmosConfig.BasePath, atmosConfig.Schemas.JsonSchema.BasePath, schemaPath)
200+
filePath = path.Join(atmosConfig.BasePath, atmosConfig.Schemas.JsonSchema.BasePath, schemaPath)
201201
}
202202
case "opa":
203203
{
204-
filePath = filepath.Join(atmosConfig.BasePath, atmosConfig.Schemas.Opa.BasePath, schemaPath)
204+
filePath = path.Join(atmosConfig.BasePath, atmosConfig.Schemas.Opa.BasePath, schemaPath)
205205
}
206206
}
207207

@@ -228,7 +228,7 @@ func validateComponentInternal(
228228
}
229229
case "opa":
230230
{
231-
modulePathsAbsolute, err := u.JoinAbsolutePathWithPaths(filepath.Join(atmosConfig.BasePath, atmosConfig.Schemas.Opa.BasePath), modulePaths)
231+
modulePathsAbsolute, err := u.JoinAbsolutePathWithPaths(path.Join(atmosConfig.BasePath, atmosConfig.Schemas.Opa.BasePath), modulePaths)
232232
if err != nil {
233233
return false, err
234234
}

0 commit comments

Comments
 (0)