Skip to content

Commit 0c2b261

Browse files
committed
Make path determination more resilient w.r.t. including pipeline id or not
1 parent 0ff08a4 commit 0c2b261

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

components/datadog/agent/package.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ func GetPackagePath(localPath string, flavor tifos.Flavor, agentFlavor string, a
5757
packagePath := localPath
5858
matches := []string{}
5959
if pathInfo.IsDir() {
60-
packagePath = path.Join(packagePath, subFolder)
61-
packagePath = path.Join(packagePath, "pkg")
62-
if flavor == tifos.WindowsServer {
63-
packagePath = path.Join(packagePath, "pipeline-"+pipelineID)
64-
}
65-
entries, err := os.ReadDir(packagePath)
60+
entries, err := getPackageFolderEntries(localPath, subFolder, pipelineID)
6661
if err != nil {
6762
return "", err
6863
}
@@ -157,3 +152,19 @@ func GetPackagePath(localPath string, flavor tifos.Flavor, agentFlavor string, a
157152
}
158153
return packagePath, nil
159154
}
155+
156+
// getPackageFolderEntries returns the DirEntry elements where packages are stored
157+
func getPackageFolderEntries(localPath string, subFolder string, pipelineID string) ([]os.DirEntry, error) {
158+
packagePath := path.Join(localPath, subFolder, "pkg")
159+
160+
// If a dedicated pipeline-identified folder is available, use that
161+
entries, err := os.ReadDir(path.Join(packagePath, "pipeline-"+pipelineID))
162+
if err == nil {
163+
return entries, nil
164+
}
165+
entries, err = os.ReadDir(packagePath)
166+
if err != nil {
167+
return entries, err
168+
}
169+
return entries, nil
170+
}

0 commit comments

Comments
 (0)