github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/image/rootfs_windows.go (about) 1 // +build windows 2 3 package image 4 5 import ( 6 "crypto/sha512" 7 "fmt" 8 9 "github.com/docker/distribution/digest" 10 "github.com/docker/docker/layer" 11 ) 12 13 // TypeLayersWithBase is used for RootFS.Type for Windows filesystems that have layers and a centrally-stored base layer. 14 const TypeLayersWithBase = "layers+base" 15 16 // RootFS describes images root filesystem 17 // This is currently a placeholder that only supports layers. In the future 18 // this can be made into an interface that supports different implementations. 19 type RootFS struct { 20 Type string `json:"type"` 21 DiffIDs []layer.DiffID `json:"diff_ids,omitempty"` 22 BaseLayer string `json:"base_layer,omitempty"` 23 } 24 25 // BaseLayerID returns the 64 byte hex ID for the baselayer name. 26 func (r *RootFS) BaseLayerID() string { 27 if r.Type != TypeLayersWithBase { 28 panic("tried to get base layer ID without a base layer") 29 } 30 baseID := sha512.Sum384([]byte(r.BaseLayer)) 31 return fmt.Sprintf("%x", baseID[:32]) 32 } 33 34 // ChainID returns the ChainID for the top layer in RootFS. 35 func (r *RootFS) ChainID() layer.ChainID { 36 ids := r.DiffIDs 37 if r.Type == TypeLayersWithBase { 38 // Add an extra ID for the base. 39 baseDiffID := layer.DiffID(digest.FromBytes([]byte(r.BaseLayerID()))) 40 ids = append([]layer.DiffID{baseDiffID}, ids...) 41 } 42 return layer.CreateChainID(ids) 43 } 44 45 // NewRootFSWithBaseLayer returns a RootFS struct with a base layer 46 func NewRootFSWithBaseLayer(baseLayer string) *RootFS { 47 return &RootFS{Type: TypeLayersWithBase, BaseLayer: baseLayer} 48 }