@@ -21,6 +21,7 @@ import (
2121 "errors"
2222 "fmt"
2323 "io"
24+ "path/filepath"
2425 "sync"
2526 "time"
2627
@@ -71,7 +72,7 @@ const (
7172 DefaultContainerdContentStorePath = "/var/lib/containerd/io.containerd.content.v1.content"
7273
7374 // Default path to soci content addressable storage
74- DefaultSociContentStorePath = "/var/lib/soci-snapshotter-grpc/ content"
75+ DefaultSociContentStorePath = config . DefaultSociSnapshotterRootPath + " content"
7576)
7677
7778func ErrUnknownContentStoreType (contentStoreType ContentStoreType ) error {
@@ -122,7 +123,8 @@ func (c *ContainerdClient) Client() (*containerd.Client, error) {
122123
123124type ContentStoreConfig struct {
124125 config.ContentStoreConfig
125- ctdClient * ContainerdClient
126+ ctdClient * ContainerdClient
127+ SnapshotterRoot string
126128}
127129
128130func NewStoreConfig (opts ... Option ) ContentStoreConfig {
@@ -153,6 +155,12 @@ func WithContainerdAddress(address string) Option {
153155 }
154156}
155157
158+ func WithSnapshotterRoot (root string ) Option {
159+ return func (sc * ContentStoreConfig ) {
160+ sc .SnapshotterRoot = root
161+ }
162+ }
163+
156164func WithClient (client * ContainerdClient ) Option {
157165 return func (sc * ContentStoreConfig ) {
158166 sc .ctdClient = client
@@ -173,7 +181,7 @@ func CanonicalizeContentStoreType(contentStoreType ContentStoreType) (ContentSto
173181}
174182
175183// GetContentStorePath returns the top level directory for the content store.
176- func GetContentStorePath (contentStoreType ContentStoreType ) (string , error ) {
184+ func GetContentStorePath (contentStoreType ContentStoreType , root string ) (string , error ) {
177185 contentStoreType , err := CanonicalizeContentStoreType (contentStoreType )
178186 if err != nil {
179187 return "" , err
@@ -182,7 +190,10 @@ func GetContentStorePath(contentStoreType ContentStoreType) (string, error) {
182190 case ContainerdContentStoreType :
183191 return DefaultContainerdContentStorePath , nil
184192 case SociContentStoreType :
185- return DefaultSociContentStorePath , nil
193+ if root == "" {
194+ return DefaultSociContentStorePath , nil
195+ }
196+ return filepath .Join (root , "content" ), nil
186197 }
187198 return "" , errors .New ("unexpectedly reached end of GetContentStorePath" )
188199}
@@ -202,7 +213,11 @@ func NewContentStore(opts ...Option) (Store, error) {
202213 case ContainerdContentStoreType :
203214 return NewContainerdStore (storeConfig )
204215 case SociContentStoreType :
205- return NewSociStore ()
216+ path , err := GetContentStorePath (SociContentStoreType , storeConfig .SnapshotterRoot )
217+ if err != nil {
218+ return nil , err
219+ }
220+ return NewSociStore (path )
206221 }
207222 return nil , errors .New ("unexpectedly reached end of NewContentStore" )
208223}
@@ -216,8 +231,11 @@ type SociStore struct {
216231var _ Store = (* SociStore )(nil )
217232
218233// NewSociStore creates a sociStore.
219- func NewSociStore () (* SociStore , error ) {
220- store , err := oci .New (DefaultSociContentStorePath )
234+ func NewSociStore (path string ) (* SociStore , error ) {
235+ if path == "" {
236+ path = DefaultSociContentStorePath
237+ }
238+ store , err := oci .New (path )
221239 return & SociStore {store }, err
222240}
223241
0 commit comments