@@ -76,12 +76,9 @@ func (i *ContainersImageRegistry) Unpack(ctx context.Context, catalog *catalogdv
76
76
//
77
77
//////////////////////////////////////////////////////
78
78
unpackPath := i .unpackPath (catalog .Name , canonicalRef .Digest ())
79
- if unpackStat , err := os .Stat (unpackPath ); err == nil {
80
- if ! unpackStat .IsDir () {
81
- panic (fmt .Sprintf ("unexpected file at unpack path %q: expected a directory" , unpackPath ))
82
- }
79
+ if isUnpacked , unpackTime := isImageUnpacked (unpackPath ); isUnpacked {
83
80
l .Info ("image already unpacked" , "ref" , imgRef .String (), "digest" , canonicalRef .Digest ().String ())
84
- return successResult (unpackPath , canonicalRef , unpackStat . ModTime () ), nil
81
+ return successResult (unpackPath , canonicalRef , unpackTime ), nil
85
82
}
86
83
87
84
//////////////////////////////////////////////////////
@@ -296,6 +293,10 @@ func (i *ContainersImageRegistry) unpackImage(ctx context.Context, unpackPath st
296
293
return wrapTerminal (fmt .Errorf ("catalog image is missing the required label %q" , ConfigDirLabel ), specIsCanonical )
297
294
}
298
295
296
+ // ensure unpack directory is empty
297
+ if err := os .RemoveAll (unpackPath ); err != nil {
298
+ return fmt .Errorf ("error removing unpacked path: %w" , err )
299
+ }
299
300
if err := os .MkdirAll (unpackPath , 0700 ); err != nil {
300
301
return fmt .Errorf ("error creating unpack directory: %w" , err )
301
302
}
@@ -431,3 +432,13 @@ func wrapTerminal(err error, isTerminal bool) error {
431
432
}
432
433
return reconcile .TerminalError (err )
433
434
}
435
+
436
+ func isImageUnpacked (unpackPath string ) (bool , time.Time ) {
437
+ if unpackStat , err := os .Stat (unpackPath ); err == nil {
438
+ if ! unpackStat .IsDir () {
439
+ panic (fmt .Sprintf ("unexpected file at unpack path %q: expected a directory" , unpackPath ))
440
+ }
441
+ return true , unpackStat .ModTime ()
442
+ }
443
+ return false , time.Time {}
444
+ }
0 commit comments