@@ -186,84 +186,78 @@ func (d *depot) Put(id strfmt.UUID) error {
186186}
187187
188188// DeployViaLink will take an artifact from the depot and link it to the target path.
189- func (d * depot ) DeployViaLink (id strfmt.UUID , relativeSrc , absoluteDest string ) error {
189+ func (d * depot ) DeployViaLink (id strfmt.UUID , relativeSrc , absoluteDest string ) ( * deployment , error ) {
190190 d .fsMutex .Lock ()
191191 defer d .fsMutex .Unlock ()
192192
193193 if exists , _ := d .Exists (id ); ! exists {
194- return errs .New ("artifact not found in depot" )
194+ return nil , errs .New ("artifact not found in depot" )
195195 }
196196
197197 if err := d .validateVolume (absoluteDest ); err != nil {
198- return errs .Wrap (err , "volume validation failed" )
198+ return nil , errs .Wrap (err , "volume validation failed" )
199199 }
200200
201201 // Collect artifact meta info
202202 var err error
203203 absoluteDest , err = fileutils .ResolvePath (absoluteDest )
204204 if err != nil {
205- return errs .Wrap (err , "failed to resolve path" )
205+ return nil , errs .Wrap (err , "failed to resolve path" )
206206 }
207207
208208 if err := fileutils .MkdirUnlessExists (absoluteDest ); err != nil {
209- return errs .Wrap (err , "failed to create path" )
209+ return nil , errs .Wrap (err , "failed to create path" )
210210 }
211211
212212 absoluteSrc := filepath .Join (d .Path (id ), relativeSrc )
213213 if ! fileutils .DirExists (absoluteSrc ) {
214- return errs .New ("artifact src does not exist: %s" , absoluteSrc )
214+ return nil , errs .New ("artifact src does not exist: %s" , absoluteSrc )
215215 }
216216
217217 // Copy or link the artifact files, depending on whether the artifact in question relies on file transformations
218218 if err := smartlink .LinkContents (absoluteSrc , absoluteDest ); err != nil {
219- return errs .Wrap (err , "failed to link artifact" )
219+ return nil , errs .Wrap (err , "failed to link artifact" )
220220 }
221221
222222 files , err := fileutils .ListDir (absoluteSrc , false )
223223 if err != nil {
224- return errs .Wrap (err , "failed to list files" )
224+ return nil , errs .Wrap (err , "failed to list files" )
225225 }
226226
227- // Record deployment to config
228- err = d .Track (id , & deployment {
227+ return & deployment {
229228 Type : deploymentTypeLink ,
230229 Path : absoluteDest ,
231230 Files : files .RelativePaths (),
232231 RelativeSrc : relativeSrc ,
233- }, nil )
234- if err != nil {
235- return errs .Wrap (err , "Could not record artifact use" )
236- }
237-
238- return nil
232+ }, nil
239233}
240234
241235// DeployViaCopy will take an artifact from the depot and copy it to the target path.
242- func (d * depot ) DeployViaCopy (id strfmt.UUID , relativeSrc , absoluteDest string ) error {
236+ func (d * depot ) DeployViaCopy (id strfmt.UUID , relativeSrc , absoluteDest string ) ( * deployment , error ) {
243237 d .fsMutex .Lock ()
244238 defer d .fsMutex .Unlock ()
245239
246240 if exists , _ := d .Exists (id ); ! exists {
247- return errs .New ("artifact not found in depot" )
241+ return nil , errs .New ("artifact not found in depot" )
248242 }
249243
250244 var err error
251245 absoluteDest , err = fileutils .ResolvePath (absoluteDest )
252246 if err != nil {
253- return errs .Wrap (err , "failed to resolve path" )
247+ return nil , errs .Wrap (err , "failed to resolve path" )
254248 }
255249
256250 if err := d .validateVolume (absoluteDest ); err != nil {
257- return errs .Wrap (err , "volume validation failed" )
251+ return nil , errs .Wrap (err , "volume validation failed" )
258252 }
259253
260254 if err := fileutils .MkdirUnlessExists (absoluteDest ); err != nil {
261- return errs .Wrap (err , "failed to create path" )
255+ return nil , errs .Wrap (err , "failed to create path" )
262256 }
263257
264258 absoluteSrc := filepath .Join (d .Path (id ), relativeSrc )
265259 if ! fileutils .DirExists (absoluteSrc ) {
266- return errs .New ("artifact src does not exist: %s" , absoluteSrc )
260+ return nil , errs .New ("artifact src does not exist: %s" , absoluteSrc )
267261 }
268262
269263 // Copy or link the artifact files, depending on whether the artifact in question relies on file transformations
@@ -272,38 +266,30 @@ func (d *depot) DeployViaCopy(id strfmt.UUID, relativeSrc, absoluteDest string)
272266 if errors .As (err , & errExist ) {
273267 logging .Warning ("Skipping files that already exist: " + errs .JoinMessage (errExist ))
274268 } else {
275- return errs .Wrap (err , "failed to copy artifact" )
269+ return nil , errs .Wrap (err , "failed to copy artifact" )
276270 }
277271 }
278272
279273 files , err := fileutils .ListDir (absoluteSrc , false )
280274 if err != nil {
281- return errs .Wrap (err , "failed to list files" )
275+ return nil , errs .Wrap (err , "failed to list files" )
282276 }
283277
284- // Record deployment to config
285- err = d .Track (id , & deployment {
278+ return & deployment {
286279 Type : deploymentTypeCopy ,
287280 Path : absoluteDest ,
288281 Files : files .RelativePaths (),
289282 RelativeSrc : relativeSrc ,
290- }, nil )
291- if err != nil {
292- return errs .Wrap (err , "Could not record artifact use" )
293- }
294-
295- return nil
283+ }, nil
296284}
297285
298286// Track will record an artifact deployment.
299- // This is automatically called by `DeployVia*()` functions.
300- // This should be called for ecosystems that handle installation of artifacts.
301- // The artifact parameter is only necessary for tracking dynamically imported artifacts after being
302- // added by an ecosystem.
303- func (d * depot ) Track (id strfmt.UUID , deploy * deployment , artifact * buildplan.Artifact ) error {
287+ func (d * depot ) Track (artifact * buildplan.Artifact , deploy * deployment ) error {
304288 d .mapMutex .Lock ()
305289 defer d .mapMutex .Unlock ()
306290
291+ id := artifact .ArtifactID
292+
307293 // Record deployment of this artifact.
308294 if _ , ok := d .config .Deployments [id ]; ! ok {
309295 d .config .Deployments [id ] = []deployment {}
@@ -474,10 +460,12 @@ func (d *depot) Save() error {
474460 for id := range d .artifacts {
475461 if deployments , ok := d .config .Deployments [id ]; ! ok || len (deployments ) == 0 {
476462 if _ , exists := d .config .Cache [id ]; ! exists {
477- err := d .Track (id , nil , nil ) // create cache entry for previously used artifact
463+ // Create cache entry for previously used artifact.
464+ size , err := fileutils .GetDirSize (d .Path (id ))
478465 if err != nil {
479- return errs .Wrap (err , "Could not update depot cache with previously used artifact " )
466+ return errs .Wrap (err , "Could not get artifact size on disk " )
480467 }
468+ d .config .Cache [id ] = & artifactInfo {Size : size , id : id }
481469 }
482470 d .config .Cache [id ].InUse = false
483471 logging .Debug ("Artifact '%s' is no longer in use" , id .String ())
0 commit comments