@@ -36,13 +36,7 @@ func (b *bundleLoader) LoadBundle() error {
36
36
errs = append (errs , err )
37
37
}
38
38
39
- // Compress the bundle to check its size
40
- if data , err := os .ReadFile (b .dir ); err == nil {
41
- if content , err := encoding .GzipBase64Encode (data ); err != nil {
42
- total := int64 (len (content ))
43
- b .bundle .CompressedSize = & total
44
- }
45
- }
39
+ errs = append (errs , b .calculateCompressedBundleSize ())
46
40
47
41
if ! b .foundCSV {
48
42
errs = append (errs , fmt .Errorf ("unable to find a csv in bundle directory %s" , b .dir ))
@@ -53,6 +47,35 @@ func (b *bundleLoader) LoadBundle() error {
53
47
return utilerrors .NewAggregate (errs )
54
48
}
55
49
50
+ // Compress the bundle to check its size
51
+ func (b * bundleLoader ) calculateCompressedBundleSize () error {
52
+ err := filepath .Walk (b .dir ,
53
+ func (path string , info os.FileInfo , err error ) error {
54
+ if err != nil {
55
+ return err
56
+ }
57
+
58
+ if ! info .IsDir () {
59
+ if data , err := os .ReadFile (path ); err == nil {
60
+ content , err := encoding .GzipBase64Encode (data )
61
+ if err != nil {
62
+ return err
63
+ }
64
+ total := int64 (len (content ))
65
+ if b .bundle .CompressedSize != nil {
66
+ total += * b .bundle .CompressedSize
67
+ }
68
+ b .bundle .CompressedSize = & total
69
+ }
70
+ }
71
+ return nil
72
+ })
73
+ if err != nil {
74
+ return err
75
+ }
76
+ return nil
77
+ }
78
+
56
79
// collectWalkErrs calls the given walk func and appends any non-nil, non skip dir error returned to the given errors slice.
57
80
func collectWalkErrs (walk filepath.WalkFunc , errs * []error ) filepath.WalkFunc {
58
81
return func (path string , f os.FileInfo , err error ) (walkErr error ) {
0 commit comments