-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Revert "Replace path.Join with filepath.Join (#856)" #887
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 2051592.
📝 WalkthroughWalkthroughThe pull request introduces a systematic replacement of Changes
Suggested labels
Suggested reviewers
Possibly related PRs
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 11
🧹 Nitpick comments (31)
internal/exec/workflow.go (1)
7-7
: Potential Windows compatibility concern
Replacing "filepath" with "path" may break cross-platform usage if the code relies on OS-specific separators.cmd/docs.go (2)
7-7
: Consider OS-specific path handling
Importing "path" might cause separator mismatches on Windows.
62-62
: Cross-platform path caution
Using "path.Join" can lead to breakage if Windows file paths are involved.pkg/generate/terraform_generate_varfiles_test.go (1)
31-31
: Potential Windows path issue in tests
"filePattern" may not match expected directory structures on Windows.internal/exec/terraform_generate_backend.go (1)
78-78
: Double-check file path handling
Switching to "path.Join" could disrupt Windows support unless that's not a concern.internal/exec/oci_utils.go (2)
11-11
: Evaluate cross-platform requirements for OCI workflows
Using "path" may ignore Windows path delimiters.
94-94
: Layer extraction path caution
"filepath.Join" is recommended if layer paths must be valid on Windows.pkg/vender/component_vendor_test.go (4)
5-5
: Consider using 'filepath' if targeting OS-specific paths.
You’re importing "path", which treats paths as URL-like. If these are filesystem-specific paths, replacing "path" with "filepath" might be safer for cross-platform compatibility (especially on Windows).
32-37
: Potential filesystem compatibility concern.
All these path joins use "path.Join(...)" rather than "filepath.Join(...)", which may not respect Windows path separators. If you’re dealing with local paths, consider "filepath.Join".
48-64
: Same OS compatibility concern.
Again, these lines rely on "path.Join(...)". Only use "path" if paths are URL-like or platform-agnostic.
67-85
: Confirm file deletion logic with OS-specific semantics.
The "os.Remove(...)" and "os.RemoveAll(...)" calls will succeed, but if the broader codebase requires OS-consistent path handling, switching these joins from "path" to "filepath" is recommended.pkg/vender/vendor_config_test.go (5)
7-7
: Check whether local or URL paths.
Importing "path" will treat paths as URL-like. For local paths, "filepath" is generally a more reliable cross-platform choice.
31-31
: Platform-agnostic path usage.
"componentPath := path.Join(...)" might behave unexpectedly on Windows if the code expects local filesystem semantics.
87-87
: Candidate for 'filepath.Join'.
Since this references a file on disk, "filepath.Join" is suggested for operating-system consistency.
105-105
: Nonexistent file test logic.
Using "path.Join" here can pass the incorrect path on certain OSes. If the test is intended for all OSes, switching to "filepath.Join" is safer.
129-129
: Path join inside local filesystem.
This can cause confusion if the code eventually runs on Windows with backslashes in the path.pkg/utils/file_utils.go (1)
72-72
: Cross-platform join check.
At line 72, "path.Join" might cause issues on Windows. If these are pure filesystem paths, switch to "filepath.Join".internal/exec/terraform_utils.go (3)
8-8
: Mixed path imports.
You’re importing both "path" and "filepath". Consolidate your approach: generally "filepath" is standard for local file manipulation.
91-91
: Adjust for local file usage.
"backendFileName := path.Join(...)" is likely operating-system dependent. If these are truly local filesystem paths, prefer "filepath.Join".
124-124
: Maintain cross-platform compatibility.
Using "path.Join" for the "providers_override.tf.json" path can lead to unexpected results on Windows.internal/exec/stack_utils.go (1)
167-167
: Ensure consistency in path handling for Terraform components
Double-check whether the component paths are expected to be OS-agnostic or purely slash-based paths. If they are local file system paths, revert to “filepath.Join” for local compatibility.internal/exec/workflow_utils.go (2)
6-6
: Use “filepath” instead of “path” for local paths
For multi-platform support, consider reverting to “filepath” imports for handling local directories.
150-150
: Reevaluate “path.Join” for workflows
If these workflow definitions point to local file paths, revert to “filepath.Join” to avoid OS path separator issues.internal/exec/terraform_generate_backends.go (1)
294-294
: Revert to “filepath.Join” for local file creation
Backends are typically stored in local directories. Using “filepath.Join” will ensure correctness on different operating systems.pkg/config/config.go (3)
136-136
: Check if this path needs OS-aware handling.
Replacing filepath.Join with path.Join may introduce unexpected behavior on Windows.
165-165
: Assess cross-platform implications.
While simpler, path.Join may fail if components contain backslashes on Windows.
192-192
: Check uniform usage of path joining logic.
Having both path and filepath in the same file can be confusing.internal/exec/describe_affected_utils.go (2)
1185-1187
: Assess if path.Join is valid for the 'component' argument.
On Windows, a backslash can creep in and cause mismatch.
1244-1244
: Ensure path.Join is correct for module calls.
If these paths are always local file references, consider reverting to filepath.Join.internal/exec/stack_processor_utils.go (1)
375-375
: Consider fallback to filepath for template lookups.
Local-based lookups often rely on OS-specific separators.pkg/utils/glob_utils.go (1)
39-39
: Traverse results carefully on Windows.
Forward slash separators might break local references in certain edge cases.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (25)
cmd/cmd_utils.go
(2 hunks)cmd/docs.go
(3 hunks)internal/exec/atlantis_generate_repo_config.go
(2 hunks)internal/exec/aws_eks_update_kubeconfig.go
(2 hunks)internal/exec/describe_affected_utils.go
(4 hunks)internal/exec/helmfile.go
(3 hunks)internal/exec/oci_utils.go
(3 hunks)internal/exec/stack_processor_utils.go
(3 hunks)internal/exec/stack_utils.go
(2 hunks)internal/exec/terraform_generate_backend.go
(2 hunks)internal/exec/terraform_generate_backends.go
(3 hunks)internal/exec/terraform_generate_varfiles.go
(2 hunks)internal/exec/terraform_utils.go
(3 hunks)internal/exec/validate_component.go
(3 hunks)internal/exec/validate_stacks.go
(4 hunks)internal/exec/vendor_component_utils.go
(3 hunks)internal/exec/vendor_utils.go
(2 hunks)internal/exec/workflow.go
(2 hunks)internal/exec/workflow_utils.go
(3 hunks)pkg/config/config.go
(8 hunks)pkg/generate/terraform_generate_varfiles_test.go
(2 hunks)pkg/utils/file_utils.go
(2 hunks)pkg/utils/glob_utils.go
(2 hunks)pkg/vender/component_vendor_test.go
(3 hunks)pkg/vender/vendor_config_test.go
(6 hunks)
✅ Files skipped from review due to trivial changes (8)
- internal/exec/atlantis_generate_repo_config.go
- cmd/cmd_utils.go
- internal/exec/validate_component.go
- internal/exec/aws_eks_update_kubeconfig.go
- internal/exec/terraform_generate_varfiles.go
- internal/exec/vendor_utils.go
- internal/exec/helmfile.go
- internal/exec/validate_stacks.go
🔇 Additional comments (16)
internal/exec/workflow.go (1)
83-83
: Recommend verifying path correctness on all platforms
If Windows usage is expected, consider reverting to "filepath.Join" to avoid separator issues.
pkg/generate/terraform_generate_varfiles_test.go (1)
5-5
: Check for platform consistency
Importing "path" can lead to inconsistent file patterns on Windows.
internal/exec/terraform_generate_backend.go (1)
5-5
: Platform-aware path usage
"filepath" is typically used for local file system paths. Confirm if "path" suffices.
✅ Verification successful
Let me verify how the path
package is being used in this context.
This will help us understand:
- How the path package is being used in the context
- Whether filepath is already present
- The specific path operations being performed
Using path
package is correct in this context
The path
package is being used to join path components for generating a backend configuration file path that will be used in Terraform configuration. Since this appears to be for generating paths that will be used within Terraform's configuration (which uses forward slashes regardless of the platform), using the path
package is actually the correct choice here instead of filepath
. The path
package always uses forward slashes which is exactly what we want for Terraform configurations.
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Check the usage of path package in the file
rg -A 5 -B 5 'path\.' internal/exec/terraform_generate_backend.go
# Check if filepath package is also imported or used
rg 'filepath' internal/exec/terraform_generate_backend.go
# Look at the complete context of path usage
ast-grep --pattern 'path.$_($_)'
Length of output: 485
internal/exec/stack_utils.go (2)
5-5
: Consider reverting to “filepath” for file paths on local systems
“path” is typically for URL paths; for improved cross-platform compatibility involving file system paths, “filepath” is more appropriate.
169-169
: Confirm Helmfile component path usage
Similar to the comments above, confirm that the Helmfile base path is truly OS-agnostic before finalizing the use of “path.Join.”
✅ Verification successful
Let me verify the usage of path joining in the codebase to ensure OS compatibility.
This will help us understand:
- Which path joining method is consistently used
- Whether the imports indicate awareness of OS-specific path handling
Let me check more thoroughly by examining the imports and overall path handling patterns in the file.
Path handling is correctly implemented
The code is using the standard path
package (imported as "path"
) which is designed specifically for slash-separated paths and is OS-agnostic. The implementation consistently uses path.Join
throughout the file for both Terraform and Helmfile component paths, making it safe for cross-platform usage.
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Search for path joining usage patterns in the codebase
rg -A 2 "path\.Join|filepath\.Join" internal/exec/stack_utils.go
# Look for any imports of path/filepath packages
rg "^import.*\"path\".*|^import.*\"path/filepath\".*" internal/exec/stack_utils.go
Length of output: 429
Script:
#!/bin/bash
# Get the full content of the file to analyze imports and path handling
cat internal/exec/stack_utils.go
# Also check for any tests that might reveal path handling expectations
fd stack_utils_test.go --exec cat {}
Length of output: 8080
internal/exec/terraform_generate_backends.go (1)
164-164
: Check the base path usage
Consider using “filepath.Join” if the path references a folder in a local environment so that Windows path separators are respected.
internal/exec/vendor_component_utils.go (1)
9-9
: Avoid mixing “path” for local file paths
When dealing with real files in operating systems, “filepath” is safer.
pkg/config/config.go (5)
296-296
: Maintain consistent path joining for Terraform base path.
Ensure environment-specific paths don’t conflict with path.Join usage.
[approve]
304-304
: Same note applies to helmfileBasePath.
Double-check if path.Join fits all usage patterns.
✅ Verification successful
Let me search for how helmfileBasePath
is being used in the codebase to verify if path.Join
is appropriate for all usage patterns.
path.Join
usage for helmfileBasePath
is appropriate and verified
The code analysis shows that helmfileBasePath
is used correctly in a path joining operation. It's immediately converted to an absolute path using filepath.Abs()
, which is the proper way to handle filesystem paths. The usage pattern is consistent with the codebase's path handling requirements.
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Search for usages of helmfileBasePath
rg "helmfileBasePath" -A 3 -B 3
# Also search for any path manipulation patterns related to helmfile
rg "helmfile.*Path" -A 3 -B 3
Length of output: 14511
274-274
: Watch out for Windows path separators.
Using path.Join here could break if the BasePath and Stacks.BasePath are mixed with backslashes.
8-8
: Consider platform-specific nuances when using path.Join.
For OS-agnostic file paths (including Windows), filepath.Join might be more reliable.
151-151
: Confirm consistency across all configuration paths.
This usage of path.Join can lead to cross-platform issues if called from Windows-based scripts.
internal/exec/describe_affected_utils.go (2)
1223-1223
: Check local module references for Windows.
Using path.Join may result in broken references on certain systems.
435-437
: Double-check cross-platform paths for stack elements.
Replacing filepath with path might be risky if these are local filesystem paths rather than URL paths.
✅ Verification successful
Let me gather more information about the path handling in this codebase.
This will help us understand:
- The current path handling approach in the file
- Whether filepath package is imported and used elsewhere
- If there's any OS-specific path handling logic
- The import statements to confirm which package is being used
Let me check the imports more thoroughly to understand the complete context.
The path handling is correct as implemented.
The code correctly uses both path
and filepath
packages based on their intended purposes:
path.Join
is used for constructing logical paths that are part of the Atmos configuration (BasePath, Components paths)filepath
is used for actual filesystem operations (Abs, Rel) when dealing with the local filesystem
The codebase shows a consistent pattern where:
- Configuration paths use the
path
package for cross-platform consistency - Actual filesystem operations use
filepath
for OS-specific path handling - Both packages are properly imported and used according to Go's best practices
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Check for other usages of path vs filepath in the codebase
rg "path\." -A 2 internal/exec/describe_affected_utils.go
# Look for any platform-specific path handling
rg "filepath\." -A 2 internal/exec/describe_affected_utils.go
# Check imports to see which package is being used
rg "^import.*path" internal/exec/describe_affected_utils.go
rg "^import.*filepath" internal/exec/describe_affected_utils.go
# Look for any OS-specific path handling patterns
ast-grep --pattern 'if runtime.GOOS == $_'
Length of output: 3741
Script:
#!/bin/bash
# Check the full import block
rg "^import \(" -A 20 internal/exec/describe_affected_utils.go
# Check if this file has any OS-specific imports
rg "runtime|os" internal/exec/describe_affected_utils.go
# Look for any path manipulation utility functions
ast-grep --pattern 'func $_(path $_) $_'
Length of output: 10452
internal/exec/stack_processor_utils.go (1)
2183-2183
: Confirm that baseComponent now uses path.Join.
If the component directory resides on Windows, validate that path.Join won't break references.
[approve]
pkg/utils/glob_utils.go (1)
6-6
: Mixing path and OS-based file lookups can lead to confusion.
Check if intended usage is for file system or URL paths.
✅ Verification successful
Let me gather more information about the usage of the path
package in the codebase to verify this concern.
This will help us understand:
- The full context of the glob_utils.go file
- How the path package is being used
- If there's any mixing with filepath package that could cause confusion
After analyzing the code, I can now provide a definitive response about the usage of the path
package in glob_utils.go
.
The path
package usage here is correct and intentional.
The code is using path
package specifically for path manipulation in a platform-agnostic way, while also providing a clear PathMatch
function that serves as a drop-in replacement for filepath.Match()
with explicit documentation about path separators. The code shows a clear understanding of when to use each:
path.Join
is used for clean path joining in a platform-agnostic wayfilepath
functions are properly used when dealing with the actual filesystem
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# First, let's see the content of the file to understand the context
cat pkg/utils/glob_utils.go
# Then, let's search for usage of path-related functions across the codebase
rg "path\." -A 2
# Also check for filepath package usage to see if there's mixing
rg "filepath\." -A 2
Length of output: 63017
@@ -68,7 +68,7 @@ var docsCmd = &cobra.Command{ | |||
u.LogErrorAndExit(schema.AtmosConfiguration{}, fmt.Errorf("Component '%s' not found in path: '%s'", info.Component, componentPath)) | |||
} | |||
|
|||
readmePath := filepath.Join(componentPath, "README.md") | |||
readmePath := path.Join(componentPath, "README.md") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Switch to filepath.Join for cross-platform compatibility
The codebase shows consistent Windows support patterns and platform-specific handling. In file_utils.go
and other core utilities, filepath.Join
is predominantly used for system paths, while path.Join
is used for URL-like paths. Since this code in cmd/docs.go
deals with filesystem paths, using filepath.Join
would be more appropriate for cross-platform compatibility.
- Replace
path.Join(componentPath, "README.md")
withfilepath.Join(componentPath, "README.md")
🔗 Analysis chain
Ensure path usage aligns with your platform needs
"filepath.Join" might be safer if Windows is a target.
Let me verify this by checking the codebase for platform-specific considerations and path handling patterns.
This will help us understand:
- The usage patterns of path/filepath across the codebase
- Any platform-specific considerations in the build
- The import patterns for path handling
Let me check specifically how paths are handled in this codebase, particularly focusing on the file utils and path utilities.
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Check for platform-specific imports and path handling
rg -l "filepath\.|path\." --type go
# Look for any build constraints or platform-specific code
rg -l "//\s+\+build\s+" --type go
# Check the main package and other key files for OS-specific handling
ast-grep --pattern 'import $_"path/filepath"'
ast-grep --pattern 'import $_"path"'
Length of output: 1264
Script:
#!/bin/bash
# Check path handling in file utils
rg "filepath\.|path\." pkg/utils/file_utils.go -B 2 -A 2
# Check path handling in path utils
rg "filepath\.|path\." internal/exec/path_utils.go -B 2 -A 2
# Look for any Windows-specific handling
rg -i "windows|filepath.separator" --type go
Length of output: 5601
@@ -30,7 +30,7 @@ func processOciImage(atmosConfig schema.AtmosConfiguration, imageName string, de | |||
defer removeTempDir(atmosConfig, tempDir) | |||
|
|||
// Temp tarball file name | |||
tempTarFileName := filepath.Join(tempDir, uuid.New().String()) + ".tar" | |||
tempTarFileName := path.Join(tempDir, uuid.New().String()) + ".tar" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Use filepath.Join instead of path.Join for cross-platform compatibility
The codebase shows consistent usage of path/filepath
package in other files within the internal/exec
directory, and there's evidence of Windows-specific handling in shell_utils.go
. Since this code processes file paths, it should use filepath.Join
instead of path.Join
to ensure proper path handling across all platforms.
internal/exec/oci_utils.go
: Replacepath.Join
withfilepath.Join
fortempTarFileName
andlayerPath
variables
🔗 Analysis chain
Temporary tar file path might fail on Windows
If the function is expected to run on Windows, "filepath.Join" is safer.
Let me verify this by checking the codebase for platform-specific code and usage patterns.
This will help us understand:
- If there's Windows-specific handling in the codebase
- Whether filepath.Join is consistently used elsewhere
- The context around the temporary file creation
Let me check for Windows-specific handling in this file and related OCI functionality.
This will help us understand if there's any platform-specific handling in the OCI-related code and surrounding files.
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Check if there are any platform-specific imports or conditions for Windows
rg -l "runtime.GOOS" --type go
# Check for filepath package usage
rg "filepath\." --type go
# Look for the specific file content
cat internal/exec/oci_utils.go
Length of output: 11289
Script:
#!/bin/bash
# Check for Windows-specific handling in the package
rg "windows" internal/exec/ -i
# Check for platform-specific path handling in the package
rg "os.(PathSeparator|PathListSeparator)" internal/exec/
# Check if this file or related files use filepath package
rg "\"path/filepath\"" internal/exec/
Length of output: 1220
pkg/vender/vendor_config_test.go
Outdated
@@ -47,7 +47,7 @@ spec: | |||
included_paths: | |||
- "**/*.tf" | |||
` | |||
vendorYamlPath := filepath.Join(testDir, "vendor.yaml") | |||
vendorYamlPath := path.Join(testDir, "vendor.yaml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consistent path joining approach.
Double-check that the rest of your codebase uses the same approach for building paths; mixing "path" and "filepath" may produce inconsistent behaviors.
@@ -93,7 +93,7 @@ func JoinAbsolutePathWithPath(basePath string, providedPath string) (string, err | |||
} | |||
|
|||
// Join the base path with the provided path | |||
joinedPath := filepath.Join(basePath, providedPath) | |||
joinedPath := path.Join(basePath, providedPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Ensure consistent path logic.
You’re using "filepath.IsAbs" to check if it’s absolute, but then "path.Join" to combine paths. For consistency in local filesystem usage, consider "filepath.Join" here as well.
workflowPath = path.Join(atmosConfig.Workflows.BasePath, f) | ||
} else { | ||
workflowPath = filepath.Join(atmosConfig.BasePath, atmosConfig.Workflows.BasePath, f) | ||
workflowPath = path.Join(atmosConfig.BasePath, atmosConfig.Workflows.BasePath, f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Use filepath.Join for cross-platform path handling
The codebase shows inconsistent use of path handling, where path.Join
is used in workflow_utils.go but filepath.Join
is used in other parts of the codebase. For cross-platform compatibility, especially on Windows:
- Replace
path.Join
withfilepath.Join
in workflow_utils.go for the following lines:workflowsDir = path.Join(atmosConfig.BasePath, atmosConfig.Workflows.BasePath)
workflowPath = path.Join(atmosConfig.Workflows.BasePath, f)
workflowPath = path.Join(atmosConfig.BasePath, atmosConfig.Workflows.BasePath, f)
The path
package uses forward slashes which can cause issues on Windows, while filepath.Join
automatically uses the correct path separator for the operating system.
🔗 Analysis chain
Maintain consistency for reading workflow files
Double-check if the absolute or relative file references might break on Windows. Reverting to “filepath.Join” may prevent unforeseen issues.
Let me verify this by checking the codebase for any potential issues with path handling.
Let me check more context about the path handling patterns across the codebase.
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Search for path-related imports and usage in workflow_utils.go
rg -A 2 "\"path\"" internal/exec/workflow_utils.go
# Search for filepath-related imports and usage
rg -A 2 "\"path/filepath\"" internal/exec/workflow_utils.go
# Look for other path.Join usages in the file
rg "path\.Join" internal/exec/workflow_utils.go
# Look for filepath.Join usages in the file
rg "filepath\.Join" internal/exec/workflow_utils.go
# Check if there are any Windows-specific path handling tests
rg -g "*_test.go" "Windows|filepath" internal/exec/
Length of output: 566
Script:
#!/bin/bash
# Search for path.Join usage patterns across the codebase
rg "path\.Join" -A 2
# Search for filepath.Join usage patterns across the codebase
rg "filepath\.Join" -A 2
# Look for any Windows-specific path handling or comments
rg -i "windows.*path|path.*windows"
# Check if there are any documented path handling conventions
fd "README|CONTRIBUTING" --exec cat {} \;
Length of output: 66270
@@ -25,7 +26,7 @@ func findComponentConfigFile(basePath, fileName string) (string, error) { | |||
componentConfigExtensions := []string{"yaml", "yml"} | |||
|
|||
for _, ext := range componentConfigExtensions { | |||
configFilePath := filepath.Join(basePath, fmt.Sprintf("%s.%s", fileName, ext)) | |||
configFilePath := path.Join(basePath, fmt.Sprintf("%s.%s", fileName, ext)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert to “filepath.Join” for consistent file lookups
Local config file resolution might otherwise fail on Windows due to mixed separators.
@@ -50,7 +51,7 @@ | |||
return componentConfig, "", fmt.Errorf("type '%s' is not supported. Valid types are 'terraform' and 'helmfile'", componentType) | |||
} | |||
|
|||
componentPath := filepath.Join(atmosConfig.BasePath, componentBasePath, component) | |||
componentPath := path.Join(atmosConfig.BasePath, componentBasePath, component) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Confirm local path usage for component vendor directory
If components are stored in local disk structures, “filepath.Join” is recommended for OS compatibility.
@@ -174,7 +175,7 @@ func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks | |||
configFilePath4 := os.Getenv("ATMOS_CLI_CONFIG_PATH") | |||
if len(configFilePath4) > 0 { | |||
u.LogTrace(atmosConfig, fmt.Sprintf("Found ENV var ATMOS_CLI_CONFIG_PATH=%s", configFilePath4)) | |||
configFile4 := filepath.Join(configFilePath4, CliConfigFileName) | |||
configFile4 := path.Join(configFilePath4, CliConfigFileName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Path handling inconsistency detected - action required
The codebase shows mixed usage of path.Join
and filepath.Join
. While path.Join
is used for config file paths, filepath.Join
is used for cache and absolute path operations. Since this is a CLI tool that handles local filesystem paths, filepath.Join
should be used consistently as it handles OS-specific path separators correctly, especially for Windows compatibility.
pkg/config/config.go
: Replacepath.Join
withfilepath.Join
in all config file path constructions (lines with configFile1 through configFile5)pkg/config/config.go
: Replacepath.Join
withfilepath.Join
for stacksBasePath, terraformBasePath, and helmfileBasePath construction
🔗 Analysis chain
Ensure consistent approach to path handling in environment variables.
If the path references local files on Windows, consider filepath.Join.
Let me gather more information about the path handling approach in the codebase.
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Check for path handling patterns in the codebase
rg -B2 -A2 "path\.Join|filepath\.Join" pkg/config/
# Look for the specific config file related code
rg -B2 -A2 "CliConfigFileName" pkg/config/
# Check imports to see if filepath is used
ast-grep --pattern 'import (
$$$
"path/filepath"
$$$
)'
Length of output: 5164
@@ -357,7 +357,7 @@ func ProcessYAMLConfigFile( | |||
|
|||
found := false | |||
for _, extension := range extensions { | |||
testPath := filepath.Join(basePath, imp+extension) | |||
testPath := path.Join(basePath, imp+extension) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Use filepath.Join instead of path.Join for OS-agnostic path handling
The code shows mixed usage of path.Join
and filepath.Join
in the codebase. In this specific case, since testPath
is used with os.Stat()
for file system operations, we should use filepath.Join
to ensure correct path separators on all operating systems, especially Windows.
internal/exec/stack_processor_utils.go
: Replacepath.Join(basePath, imp+extension)
withfilepath.Join(basePath, imp+extension)
The evidence shows that:
- The file uses
filepath.Ext
andfilepath.Walk
for other file operations - The
testPath
is used directly withos.Stat()
, which requires OS-specific path separators - Other similar file system operations in the codebase use
filepath.Join
for OS compatibility
🔗 Analysis chain
Review the glob logic with path vs filepath.
path.Join may create forward slashes on Windows, which could cause missing-file errors.
Let me verify this by checking the codebase for the usage context and platform-specific handling.
This will help us understand:
- The context where testPath is used
- Whether filepath package is used elsewhere in the file
- The overall path handling approach in the codebase
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Check the context of the testPath usage and any platform-specific handling
rg -B 5 -A 5 "testPath :=" internal/exec/stack_processor_utils.go
# Look for any filepath package usage in the same file
rg "filepath\." internal/exec/stack_processor_utils.go
# Check if there's any platform-specific path handling
rg -g "*.go" "path[./]Join|filepath[./]Join"
Length of output: 14588
impWithExt = templatePath | ||
} | ||
} | ||
|
||
impWithExtPath := filepath.Join(basePath, impWithExt) | ||
impWithExtPath := path.Join(basePath, impWithExt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Path comparison needs Windows compatibility fixes
The code uses path.Join
for path manipulation but performs direct string comparison (impWithExtPath == filePath
) without normalizing path separators. This can indeed cause issues on Windows where paths might use different separators. Here's what needs attention:
- Use
filepath.Clean
andfilepath.ToSlash
on both paths before comparison - Replace
path.Join
withfilepath.Join
for cross-platform compatibility - The comparison at line 380 should normalize paths before equality check
🔗 Analysis chain
Ensure self-import check accounts for Windows paths.
Mismatched separators can yield false negatives.
Let me gather information about path handling in the codebase to verify this concern.
This will help us understand:
- How paths are handled in the file
- If there are tests covering Windows path scenarios
- If there's any Windows-specific path handling logic
Let me check how the file paths are actually compared in the codebase to better understand the self-import check implementation.
This will help us understand if there's proper path normalization before comparison and how the self-import check is implemented.
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Search for path-related operations and separator handling
rg -U "path\.(Join|Clean|Separator|filepath\.|\\\\|/)" internal/exec/stack_processor_utils.go -A 2
# Look for any path-related tests that might handle Windows paths
fd ".*test.*\.go" internal/exec/ --exec rg -l "path|filepath|windows|separator"
# Search for any Windows-specific path handling
ast-grep --pattern 'if runtime.GOOS == "windows" { $$$ }'
Length of output: 3165
Script:
#!/bin/bash
# Search for the self-import check implementation
rg -U "self.*import|impWithExtPath.*filePath" internal/exec/stack_processor_utils.go -B 5 -A 5
# Check if filepath package is used anywhere in the file
rg "filepath\." internal/exec/stack_processor_utils.go
# Look for path normalization or cleaning
rg "Clean|ToSlash|FromSlash" internal/exec/stack_processor_utils.go
Length of output: 623
Important Cloud Posse Engineering Team Review RequiredThis pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes. To expedite this process, reach out to us on Slack in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
internal/exec/vendor_utils.go (1)
Line range hint
1-645
: Consider implementing a platform-agnostic path handling strategyGiven the history of path-related issues (mentioned in PR #856) and the addition of Windows-specific handling, consider:
- Creating a centralized path handling utility
- Documenting the path handling strategy
- Adding integration tests for cross-platform scenarios
This would help prevent future path-related issues and make the codebase more maintainable.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/exec/vendor_utils.go
(4 hunks)
🔇 Additional comments (2)
internal/exec/vendor_utils.go (2)
6-8
: Both path and filepath packages are imported
This could lead to confusion as both packages are used for path manipulation. The PR description mentions reverting from filepath.Join to path.Join, but both imports remain.
Let's check the usage patterns:
✅ Verification successful
Both path and filepath packages are used appropriately
Based on the usage patterns found in the codebase:
path.Join
is primarily used for handling URL-style paths and configuration paths that need to be platform-independentfilepath.Join
is correctly used for filesystem operations where OS-specific path separators are required
The coexistence of both packages is intentional and follows Go's best practices:
path
for virtual/URL paths (platform-independent)filepath
for actual filesystem paths (platform-specific)
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check usage patterns of path.Join and filepath.Join
echo "Checking path.Join usage:"
rg "path\.Join\(" -A 1
echo -e "\nChecking filepath.Join usage:"
rg "filepath\.Join\(" -A 1
Length of output: 24000
556-558
: Ensure consistent path handling across platforms
The usage of sanitizeFileName
here is good, but we should ensure consistent path handling across all platforms.
Let's check for similar patterns that might need the same treatment:
✅ Verification successful
Let me check for any instances where file paths are constructed without proper sanitization. I'll search for direct file path construction patterns.
Let me check the implementation of the sanitizeFileName function to ensure it's properly handling paths.
Let me see the complete implementation of sanitizeFileName since it was cut off.
Let me get the complete function implementation as it seems to be cut off.
Path handling is properly implemented and secure
The sanitizeFileName
function is well-implemented with proper platform-specific handling:
- On non-Windows systems, it safely extracts the base filename
- On Windows, it properly sanitizes invalid characters and handles query strings
- The function is correctly used in the codebase for safe filename construction
All other instances of filepath.Join
in the codebase are used appropriately for path construction, and don't require additional sanitization as they're working with internal paths rather than external URIs.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Look for other instances where file paths are constructed
rg "filepath\.Join\([^)]*\)" -A 1
Length of output: 5968
Script:
#!/bin/bash
# Look for direct file path construction without sanitization
rg "filepath\.Join.*\(" -C 2 internal/exec/
Length of output: 12862
Script:
#!/bin/bash
# Check for the sanitizeFileName function implementation and usage
ast-grep --pattern 'func sanitizeFileName($_) { $$$ }'
Length of output: 56
Script:
#!/bin/bash
# Look for other file name handling functions
rg "func.*[Ff]ile[Nn]ame" -A 2
Length of output: 2685
Script:
#!/bin/bash
# Get the implementation of sanitizeFileName
rg -A 10 "func sanitizeFileName" internal/exec/vendor_utils.go
Length of output: 355
Script:
#!/bin/bash
# Get the complete implementation of sanitizeFileName with more context
rg -A 20 "func sanitizeFileName" internal/exec/vendor_utils.go
Length of output: 623
Script:
#!/bin/bash
# Get the complete implementation with more lines
rg -A 30 "func sanitizeFileName" internal/exec/vendor_utils.go
Length of output: 928
Script:
#!/bin/bash
# Look for any calls to this function
rg "sanitizeFileName\(" internal/exec/
Length of output: 184
@@ -164,7 +166,7 @@ func ReadAndProcessVendorConfigFile( | |||
|
|||
if !fileExists { | |||
// Look for the vendoring manifest in the directory pointed to by the `base_path` setting in `atmos.yaml` | |||
pathToVendorConfig := filepath.Join(atmosConfig.BasePath, vendorConfigFile) | |||
pathToVendorConfig := path.Join(atmosConfig.BasePath, vendorConfigFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verify the impact of using path.Join instead of filepath.Join
Using path.Join
here could cause issues on Windows systems as it always uses forward slashes, while Windows expects backslashes. The PR description mentions that this change caused significant issues that were difficult to debug.
Consider reverting this change back to filepath.Join
:
- pathToVendorConfig := path.Join(atmosConfig.BasePath, vendorConfigFile)
+ pathToVendorConfig := filepath.Join(atmosConfig.BasePath, vendorConfigFile)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
pathToVendorConfig := path.Join(atmosConfig.BasePath, vendorConfigFile) | |
pathToVendorConfig := filepath.Join(atmosConfig.BasePath, vendorConfigFile) |
internal/exec/vendor_utils.go
Outdated
// sanitizeFileName replaces invalid characters and query strings with underscores for Windows. | ||
func sanitizeFileName(uri string) string { | ||
// This logic applies only to Windows | ||
if runtime.GOOS != "windows" { | ||
return filepath.Base(uri) | ||
} | ||
|
||
// Extract the path part (ignoring query strings) | ||
if idx := strings.Index(uri, "?"); idx != -1 { | ||
uri = strings.ReplaceAll(uri, "?", "_") | ||
} | ||
|
||
// Extract the base name (last segment of the path) | ||
base := filepath.Base(uri) | ||
|
||
// Replace invalid characters for Windows | ||
base = strings.Map(func(r rune) rune { | ||
switch r { | ||
case '\\', '/', ':', '*', '?', '"', '<', '>', '|': | ||
return '_' | ||
default: | ||
return r | ||
} | ||
}, base) | ||
|
||
return base | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Unit tests needed for sanitizeFileName function
The verification confirms that:
- There are no existing test files in the internal/exec directory
- The sanitizeFileName function is used in a critical path for handling file paths, specifically when dealing with local file sources
- The function contains Windows-specific logic that needs proper testing
Action items:
- Create a new test file
internal/exec/vendor_utils_test.go
- Add test cases covering:
- Windows vs non-Windows behavior
- Query string sanitization
- Invalid character replacement
- Path handling with different URI formats
🔗 Analysis chain
New sanitizeFileName function needs unit tests
The function handles Windows-specific filename sanitization, but there are no tests to verify its behavior. The PR description mentions that Windows tests have been added, but they should specifically cover this function.
Let's check for existing tests:
Would you like me to help create unit tests for this function? I can generate test cases covering:
- Windows vs non-Windows behavior
- Query string handling
- Invalid character replacement
- Path traversal cases
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Look for test files that might contain tests for sanitizeFileName
rg "func.*Test.*sanitizeFileName"
Length of output: 35
Script:
#!/bin/bash
# Let's search for any tests or references to sanitizeFileName in test files
rg "sanitizeFileName" --type go -g "*_test.go" -C 2
# Also search for any test files in the same directory as vendor_utils.go
fd "_test.go" internal/exec/
Length of output: 80
Script:
#!/bin/bash
# Let's check if there are any test files in the internal/exec directory
ls -la internal/exec/*_test.go
# Let's also check if the function is used anywhere to understand its importance
rg "sanitizeFileName\(" --type go -C 2
Length of output: 882
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
internal/exec/vendor_model_component.go (1)
162-162
: Avoid duplicating path-sanitization logic."tempDir2 = filepath.Join(tempDir, sanitizeFileName(p.uri))" repeats the logic at line 127. Consider extracting this path creation into a helper method to improve reusability.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
internal/exec/vendor_component_utils.go
(4 hunks)internal/exec/vendor_model.go
(1 hunks)internal/exec/vendor_model_component.go
(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- internal/exec/vendor_model.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/exec/vendor_component_utils.go
🔇 Additional comments (1)
internal/exec/vendor_model_component.go (1)
127-127
: Consider validating the sanitized path.
Using "sanitizeFileName(p.uri)" is effective for removing invalid path characters. However, ensure that sanitized names don't become empty or produce collisions if different URIs map to the same sanitized value.
This reverts commit 2051592.
what
why
Summary by CodeRabbit