Skip to content

Commit

Permalink
fix relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
haitham911 committed Jan 26, 2025
1 parent 687a00d commit e8c8c8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
19 changes: 3 additions & 16 deletions pkg/config/base_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,18 @@ func (cl *ConfigLoader) BasePathComputing(configAndStacksInfo schema.ConfigAndSt
return cl.resolveAndValidatePath(envBasePath, "ENV var")
}

// Check base path from configuration
// Check base path from configuration
if cl.atmosConfig.BasePath != "" {

source := "atmos config"
if !filepath.IsAbs(cl.atmosConfig.BasePath) {
source := "atmos config relative"
// If relative, make it absolute based on the current working directory
absPath, err := filepath.Abs(cl.atmosConfig.BasePath)
if err != nil {
return "", fmt.Errorf("failed to resolve relative base path from %s: %w", source, err)
}
currentDir, err := os.Getwd()
if err != nil {
return "", err
}
relativePath, err := filepath.Rel(currentDir, absPath)
if err != nil {
return "", fmt.Errorf("Error base path from from atmos config can not resolving relative path:%w", err)
}
_, err = cl.resolveAndValidatePath(relativePath, source)
if err != nil {
return "", err
}
return relativePath, nil
cl.atmosConfig.BasePath = absPath
}
source := "atmos config"
return cl.resolveAndValidatePath(cl.atmosConfig.BasePath, source)
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/config/base_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ func TestBasePathComputingWithBasePathSetInConfiguration(t *testing.T) {
if err != nil {
t.Fatalf("Failed to create directory %q: %v", subDirTemp, err)
}
expectedPath, _ = filepath.Abs(subDirTemp)

configLoader.atmosConfig.BasePath = "sub-dir"
result, err = configLoader.BasePathComputing(info)
assert.NoError(t, err)
assert.Equal(t, "sub-dir", result)
assert.Equal(t, expectedPath, result)

}

0 comments on commit e8c8c8c

Please sign in to comment.