77 "net/url"
88 "os"
99 "path/filepath"
10+ "regexp"
1011 "strings"
1112
1213 "hauler.dev/go/hauler/v2/internal/flags"
@@ -20,6 +21,10 @@ import (
2021 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2122)
2223
24+ // matches the old <base>_NNN.<ext> chunk naming of haul_0.tar.zst
25+ // used only to print a hint when a load fails on a file shaped like a stale chunk
26+ var legacyChunkRe = regexp .MustCompile (`_\d+\.` )
27+
2328// extracts the contents of an archived oci layout to an existing oci layout
2429func LoadCmd (ctx context.Context , o * flags.LoadOpts , rso * flags.StoreRootOpts , ro * flags.CliRootOpts ) error {
2530 l := log .FromContext (ctx )
@@ -41,7 +46,7 @@ func LoadCmd(ctx context.Context, o *flags.LoadOpts, rso *flags.StoreRootOpts, r
4146 for _ , fileName := range o .FileName {
4247 resolved := resolveHaulPath (fileName )
4348 l .Infof ("loading haul [%s] to [%s]" , resolved , o .StoreDir )
44- err := unarchiveLayoutTo (ctx , resolved , o .StoreDir , tempDir )
49+ err := unarchiveLayoutTo (ctx , resolved , o .StoreDir , tempDir , ro )
4550 if err != nil {
4651 return err
4752 }
@@ -52,7 +57,7 @@ func LoadCmd(ctx context.Context, o *flags.LoadOpts, rso *flags.StoreRootOpts, r
5257}
5358
5459// accepts an archived OCI layout, extracts the contents to an existing OCI layout, and preserves the index
55- func unarchiveLayoutTo (ctx context.Context , haulPath string , dest string , tempDir string ) error {
60+ func unarchiveLayoutTo (ctx context.Context , haulPath string , dest string , tempDir string , ro * flags. CliRootOpts ) error {
5661 l := log .FromContext (ctx )
5762
5863 if strings .HasPrefix (haulPath , "http://" ) || strings .HasPrefix (haulPath , "https://" ) {
@@ -94,6 +99,19 @@ func unarchiveLayoutTo(ctx context.Context, haulPath string, dest string, tempDi
9499 haulPath = joined
95100
96101 if err := archives .Unarchive (ctx , haulPath , tempDir ); err != nil {
102+ if legacyChunkRe .MatchString (filepath .Base (haulPath )) {
103+ ignoreErrors := ro .IgnoreErrors
104+ if ! ignoreErrors && os .Getenv (consts .HaulerIgnoreErrors ) == "true" {
105+ ignoreErrors = true
106+ }
107+ if ignoreErrors {
108+ l .Warnf ("possibly detected an old chunk format for haul: [%s]" , haulPath )
109+ l .Warnf ("attempt to rename to '<base>.<ext>.NNN' and try loading it again..." )
110+ return nil
111+ }
112+ l .Errorf ("possibly detected an old chunk format for haul: [%s]" , haulPath )
113+ l .Errorf ("attempt to rename to '<base>.<ext>.NNN' and try loading it again..." )
114+ }
97115 return err
98116 }
99117
0 commit comments