@@ -4,19 +4,15 @@ import (
44 "bytes"
55 "encoding/json"
66 "fmt"
7- "github.com/jfrog/build-info-go/entities"
8- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
9- buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
10- "github.com/jfrog/jfrog-client-go/artifactory/services"
11- servicesUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
12- "github.com/jfrog/jfrog-client-go/utils/io/content"
137 "io"
148 "os"
159 "os/exec"
16- "sort"
1710 "strconv"
1811 "time"
1912
13+ "github.com/jfrog/build-info-go/entities"
14+ "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
15+ buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
2016 "github.com/jfrog/jfrog-cli-core/v2/utils/config"
2117 "github.com/jfrog/jfrog-client-go/utils/errorutils"
2218 "github.com/jfrog/jfrog-client-go/utils/log"
@@ -141,50 +137,25 @@ func (hfu *HuggingFaceUpload) GetArtifacts(buildProperties string) ([]entities.A
141137 }
142138 repoTypePath := hfu .repoType + "s"
143139 revisionPattern := hfu .revision
144- var multipleDirsInSearchResults = false
145140 if ! HasTimestamp (hfu .revision ) {
146141 revisionPattern = hfu .revision + "_*"
147- multipleDirsInSearchResults = true
148142 }
149- aqlQuery := fmt .Sprintf (`{"repo": "%s", "path": {"$match": "%s/%s/%s/*"}}` ,
143+ aqlQuery := fmt .Sprintf (`items.find( {"repo":"%s","path":{"$match":"%s/%s/%s/*"}}).include("repo","path","name","actual_sha1","actual_md5","sha256","type").sort({"$desc":["path"]}) ` ,
150144 repoKey ,
151145 repoTypePath ,
152146 hfu .repoId ,
153147 revisionPattern ,
154148 )
155- searchParams := services.SearchParams {
156- CommonParams : & servicesUtils.CommonParams {
157- Aql : servicesUtils.Aql {ItemsFind : aqlQuery },
158- },
159- }
160- reader , err := serviceManager .SearchFiles (searchParams )
149+ results , err := executeAqlQuery (serviceManager , aqlQuery )
161150 if err != nil {
162151 return nil , fmt .Errorf ("failed to search for HuggingFace artifacts: %w" , err )
163152 }
164- defer func (reader * content.ContentReader ) {
165- err := reader .Close ()
166- if err != nil {
167- log .Error (err )
168- }
169- }(reader )
170- var results []servicesUtils.ResultItem
171- for item := new (servicesUtils.ResultItem ); reader .NextRecord (item ) == nil ; item = new (servicesUtils.ResultItem ) {
172- results = append (results , * item )
173- }
174153 if len (results ) == 0 {
175154 return nil , nil
176155 }
177- if multipleDirsInSearchResults {
178- sort .Slice (results , func (i , j int ) bool {
179- return results [i ].Path > results [j ].Path
180- })
181- }
182- var latestCreatedDir string
156+ latestCreatedDir := results [0 ].Path
183157 var artifacts []entities.Artifact
184- for index , resultItem := range results {
185- if index == 0 {
186- latestCreatedDir = resultItem .Path
187- }
158+ for _ , resultItem := range results {
188159 artifacts = append (artifacts , entities.Artifact {
189160 Name : resultItem .Name ,
190161 Type : resultItem .Type ,
@@ -194,15 +165,18 @@ func (hfu *HuggingFaceUpload) GetArtifacts(buildProperties string) ([]entities.A
194165 Sha256 : resultItem .Sha256 ,
195166 },
196167 })
197- if latestCreatedDir != resultItem .Path {
198- break
199- }
200168 }
201- err = updateReaderContents (reader , repoKey , latestCreatedDir , "" )
169+ // Create content reader for the folder to set build properties
170+ reader , err := createContentReader (repoKey , latestCreatedDir , "" , "folder" )
202171 if err != nil {
203- return nil , err
172+ log .Warn ("Failed to create content reader: " , err )
173+ return artifacts , nil
204174 }
205- reader .Reset ()
175+ defer func () {
176+ if closeErr := reader .Close (); closeErr != nil {
177+ log .Error (closeErr )
178+ }
179+ }()
206180 addBuildPropertiesOnArtifacts (serviceManager , reader , buildProperties )
207181 return artifacts , nil
208182}
0 commit comments