@@ -7,14 +7,16 @@ import (
7
7
8
8
ispec "github.com/opencontainers/image-spec/specs-go/v1"
9
9
"github.com/pkg/errors"
10
- "machinerun.io/atomfs/squashfs"
10
+ "machinerun.io/atomfs/pkg/erofs"
11
+ "machinerun.io/atomfs/pkg/squashfs"
12
+ "machinerun.io/atomfs/pkg/verity"
11
13
)
12
14
13
15
var ErrEmptyLayers = errors .New ("empty layers" )
14
16
15
17
type LayerType struct {
16
18
Type string
17
- Verity squashfs .VerityMetadata
19
+ Verity verity .VerityMetadata
18
20
}
19
21
20
22
func (lt LayerType ) String () string {
@@ -44,15 +46,17 @@ func (lt *LayerType) UnmarshalText(text []byte) error {
44
46
return errors .Wrapf (err , "bad verity bool: %s" , fields [1 ])
45
47
}
46
48
47
- lt .Verity = squashfs .VerityMetadata (result )
49
+ lt .Verity = verity .VerityMetadata (result )
48
50
49
51
return nil
50
52
}
51
53
52
- func NewLayerType (lt string , verity squashfs .VerityMetadata ) (LayerType , error ) {
54
+ func NewLayerType (lt string , verity verity .VerityMetadata ) (LayerType , error ) {
53
55
switch lt {
54
56
case "squashfs" :
55
57
return LayerType {Type : lt , Verity : verity }, nil
58
+ case "erofs" :
59
+ return LayerType {Type : lt , Verity : verity }, nil
56
60
case "tar" :
57
61
return LayerType {Type : lt }, nil
58
62
default :
@@ -62,31 +66,38 @@ func NewLayerType(lt string, verity squashfs.VerityMetadata) (LayerType, error)
62
66
63
67
func NewLayerTypeManifest (manifest ispec.Manifest ) (LayerType , error ) {
64
68
if len (manifest .Layers ) == 0 {
65
- return NewLayerType ("tar" , squashfs .VerityMetadataMissing )
69
+ return NewLayerType ("tar" , verity .VerityMetadataMissing )
66
70
}
67
71
72
+ _ , verityMetadataPresent := manifest .Layers [0 ].Annotations [verity .VerityRootHashAnnotation ]
73
+
68
74
switch manifest .Layers [0 ].MediaType {
69
75
case squashfs .BaseMediaTypeLayerSquashfs :
70
76
// older stackers generated media types without compression information
71
77
fallthrough
72
- case squashfs .GenerateSquashfsMediaType (squashfs .GzipCompression , squashfs .VerityMetadataMissing ):
78
+ case squashfs .GenerateSquashfsMediaType (squashfs .GzipCompression ):
79
+ fallthrough
80
+ case squashfs .GenerateSquashfsMediaType (squashfs .ZstdCompression ):
81
+ return NewLayerType ("squashfs" , verity .VerityMetadata (verityMetadataPresent ))
82
+ case erofs .BaseMediaTypeLayerErofs :
83
+ // older stackers generated media types without compression information
84
+ fallthrough
85
+ case erofs .GenerateErofsMediaType (erofs .LZ4HCCompression ):
73
86
fallthrough
74
- case squashfs .GenerateSquashfsMediaType (squashfs .ZstdCompression , squashfs .VerityMetadataMissing ):
75
- return NewLayerType ("squashfs" , squashfs .VerityMetadataMissing )
76
- case squashfs .GenerateSquashfsMediaType (squashfs .GzipCompression , squashfs .VerityMetadataPresent ):
87
+ case erofs .GenerateErofsMediaType (erofs .LZ4Compression ):
77
88
fallthrough
78
- case squashfs . GenerateSquashfsMediaType ( squashfs .ZstdCompression , squashfs . VerityMetadataPresent ):
79
- return NewLayerType ("squashfs " , squashfs . VerityMetadataPresent )
89
+ case erofs . GenerateErofsMediaType ( erofs .ZstdCompression ):
90
+ return NewLayerType ("erofs " , verity . VerityMetadata ( verityMetadataPresent ) )
80
91
case ispec .MediaTypeImageLayerGzip :
81
92
fallthrough
82
93
case ispec .MediaTypeImageLayer :
83
- return NewLayerType ("tar" , squashfs .VerityMetadataMissing )
94
+ return NewLayerType ("tar" , verity .VerityMetadataMissing )
84
95
default :
85
96
return LayerType {}, errors .Errorf ("invalid layer type %s" , manifest .Layers [0 ].MediaType )
86
97
}
87
98
}
88
99
89
- func NewLayerTypes (lts []string , verity squashfs .VerityMetadata ) ([]LayerType , error ) {
100
+ func NewLayerTypes (lts []string , verity verity .VerityMetadata ) ([]LayerType , error ) {
90
101
ret := []LayerType {}
91
102
for _ , lt := range lts {
92
103
hoisted , err := NewLayerType (lt , verity )
0 commit comments