// ParseReference takes a name and/or an ID ("_name_"/"@_id_"/"_name_@_id_"), // possibly prefixed with a store specifier in the form "[_graphroot_]" or // "[_driver_@_graphroot_]", tries to figure out which it is, and returns it in // a reference object. If the _graphroot_ is a location other than the default, // it needs to have been previously opened using storage.GetStore(), so that it // can figure out which run root goes with the graph root. func (s *storageTransport) ParseReference(reference string) (types.ImageReference, error) { store, err := s.GetStore() if err != nil { return nil, err } // Check if there's a store location prefix. If there is, then it // needs to match a store that was previously initialized using // storage.GetStore(), or be enough to let the storage library fill out // the rest using knowledge that it has from elsewhere. if reference[0] == '[' { closeIndex := strings.IndexRune(reference, ']') if closeIndex < 1 { return nil, ErrInvalidReference } storeSpec := reference[1:closeIndex] reference = reference[closeIndex+1:] storeInfo := strings.SplitN(storeSpec, "@", 2) if len(storeInfo) == 1 && storeInfo[0] != "" { // One component: the graph root. if !filepath.IsAbs(storeInfo[0]) { return nil, ErrPathNotAbsolute } store2, err := storage.GetStore(storage.StoreOptions{ GraphRoot: storeInfo[0], }) if err != nil { return nil, err } store = store2 } else if len(storeInfo) == 2 && storeInfo[0] != "" && storeInfo[1] != "" { // Two components: the driver type and the graph root. if !filepath.IsAbs(storeInfo[1]) { return nil, ErrPathNotAbsolute } store2, err := storage.GetStore(storage.StoreOptions{ GraphDriverName: storeInfo[0], GraphRoot: storeInfo[1], }) if err != nil { return nil, err } store = store2 } else { // Anything else: store specified in a form we don't // recognize. return nil, ErrInvalidReference } } return s.ParseStoreReference(store, reference) }
func newStore(t *testing.T) storage.Store { wd, err := ioutil.TempDir(topwd, "test.") if err != nil { t.Fatal(err) } err = os.MkdirAll(wd, 0700) if err != nil { t.Fatal(err) } run := filepath.Join(wd, "run") root := filepath.Join(wd, "root") uidmap := []idtools.IDMap{{ ContainerID: 0, HostID: os.Getuid(), Size: 1, }} gidmap := []idtools.IDMap{{ ContainerID: 0, HostID: os.Getgid(), Size: 1, }} store, err := storage.GetStore(storage.StoreOptions{ RunRoot: run, GraphRoot: root, GraphDriverName: "vfs", GraphDriverOptions: []string{}, UIDMap: uidmap, GIDMap: gidmap, }) if err != nil { t.Fatal(err) } Transport.SetStore(store) return store }
func (s *storageTransport) GetStore() (storage.Store, error) { // Return the transport's previously-set store. If we don't have one // of those, initialize one now. if s.store == nil { store, err := storage.GetStore(storage.DefaultStoreOptions) if err != nil { return nil, err } s.store = store } return s.store, nil }