Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions pkg/cli/audit_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,6 @@ func extractDownloadedFiles(logsPath string) []FileInfo {
return files
}

// Get current working directory to calculate relative paths
cwd, err := os.Getwd()
if err != nil {
auditReportLog.Printf("Failed to get current directory: %v", err)
cwd = ""
}

for _, entry := range entries {
// Skip directories
if entry.IsDir() {
Expand All @@ -355,16 +348,15 @@ func extractDownloadedFiles(logsPath string) []FileInfo {
name := entry.Name()
fullPath := filepath.Join(logsPath, name)

// Calculate relative path from workspace root (current working directory)
relativePath := fullPath
if cwd != "" {
if relPath, err := filepath.Rel(cwd, fullPath); err == nil {
relativePath = relPath
}
// Use absolute path so callers get a directly usable path
absPath, err := filepath.Abs(fullPath)
if err != nil {
auditReportLog.Printf("Failed to resolve absolute path for %s: %v", fullPath, err)
absPath = fullPath
}

fileInfo := FileInfo{
Path: relativePath,
Path: absPath,
Description: describeFile(name),
}

Expand Down
11 changes: 9 additions & 2 deletions pkg/cli/audit_report_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,17 @@ func TestDownloadedFilesInAuditData(t *testing.T) {
t.Errorf("Expected %d files, got %d", expectedCount, len(files))
}

// Verify all paths are absolute
for _, file := range files {
if !filepath.IsAbs(file.Path) {
t.Errorf("Expected absolute path, got relative path: %s", file.Path)
}
}

// Verify specific files have correct attributes
fileMap := make(map[string]FileInfo)
for _, file := range files {
// Use basename for lookup since paths are now relative to workspace root
// Use basename for lookup since we only need to find files by name
basename := filepath.Base(file.Path)
fileMap[basename] = file
}
Expand Down Expand Up @@ -323,7 +330,7 @@ func TestAuditReportFileListingIntegration(t *testing.T) {
// Build a map for easy lookup
fileMap := make(map[string]FileInfo)
for _, f := range files {
// Use basename for lookup since paths are now relative to workspace root
// Use basename for lookup since we only need to find files by name
basename := filepath.Base(f.Path)
fileMap[basename] = f
}
Expand Down
Loading