mirror of
https://github.com/containers/skopeo.git
synced 2025-09-24 03:17:17 +00:00
Vendor c/image after merging vrothberg/image:regsv2-docker
Also update the user and tests for the API change.
This commit is contained in:
68
vendor/github.com/containers/storage/layers.go
generated
vendored
68
vendor/github.com/containers/storage/layers.go
generated
vendored
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/containers/storage/pkg/system"
|
||||
"github.com/containers/storage/pkg/truncindex"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
"github.com/opencontainers/selinux/go-selinux/label"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/vbatts/tar-split/tar/asm"
|
||||
"github.com/vbatts/tar-split/tar/storage"
|
||||
@@ -210,7 +211,7 @@ type LayerStore interface {
|
||||
// layers, it should not be written to. An SELinux label to be applied to the
|
||||
// mount can be specified to override the one configured for the layer.
|
||||
// The mappings used by the container can be specified.
|
||||
Mount(id, mountLabel string, uidMaps, gidMaps []idtools.IDMap) (string, error)
|
||||
Mount(id string, options drivers.MountOpts) (string, error)
|
||||
|
||||
// Unmount unmounts a layer when it is no longer in use.
|
||||
Unmount(id string, force bool) (bool, error)
|
||||
@@ -294,6 +295,9 @@ func (r *layerStore) Load() error {
|
||||
mounts := make(map[string]*Layer)
|
||||
compressedsums := make(map[digest.Digest][]string)
|
||||
uncompressedsums := make(map[digest.Digest][]string)
|
||||
if r.lockfile.IsReadWrite() {
|
||||
label.ClearLabels()
|
||||
}
|
||||
if err = json.Unmarshal(data, &layers); len(data) == 0 || err == nil {
|
||||
idlist = make([]string, 0, len(layers))
|
||||
for n, layer := range layers {
|
||||
@@ -312,6 +316,9 @@ func (r *layerStore) Load() error {
|
||||
if layer.UncompressedDigest != "" {
|
||||
uncompressedsums[layer.UncompressedDigest] = append(uncompressedsums[layer.UncompressedDigest], layer.ID)
|
||||
}
|
||||
if layer.MountLabel != "" {
|
||||
label.ReserveLabel(layer.MountLabel)
|
||||
}
|
||||
}
|
||||
}
|
||||
if shouldSave && !r.IsReadWrite() {
|
||||
@@ -535,8 +542,8 @@ func (r *layerStore) Put(id string, parentLayer *Layer, names []string, mountLab
|
||||
_, idInUse = r.byid[id]
|
||||
}
|
||||
}
|
||||
if _, idInUse := r.byid[id]; idInUse {
|
||||
return nil, -1, ErrDuplicateID
|
||||
if duplicateLayer, idInUse := r.byid[id]; idInUse {
|
||||
return duplicateLayer, -1, ErrDuplicateID
|
||||
}
|
||||
names = dedupeNames(names)
|
||||
for _, name := range names {
|
||||
@@ -552,19 +559,31 @@ func (r *layerStore) Put(id string, parentLayer *Layer, names []string, mountLab
|
||||
} else {
|
||||
parentMappings = &idtools.IDMappings{}
|
||||
}
|
||||
if mountLabel != "" {
|
||||
label.ReserveLabel(mountLabel)
|
||||
}
|
||||
idMappings := idtools.NewIDMappingsFromMaps(moreOptions.UIDMap, moreOptions.GIDMap)
|
||||
opts := drivers.CreateOpts{
|
||||
MountLabel: mountLabel,
|
||||
StorageOpt: options,
|
||||
}
|
||||
if writeable {
|
||||
err = r.driver.CreateReadWrite(id, parent, &opts)
|
||||
if err = r.driver.CreateReadWrite(id, parent, &opts); err != nil {
|
||||
if id != "" {
|
||||
return nil, -1, errors.Wrapf(err, "error creating read-write layer with ID %q", id)
|
||||
}
|
||||
return nil, -1, errors.Wrapf(err, "error creating read-write layer")
|
||||
}
|
||||
} else {
|
||||
err = r.driver.Create(id, parent, &opts)
|
||||
if err = r.driver.Create(id, parent, &opts); err != nil {
|
||||
if id != "" {
|
||||
return nil, -1, errors.Wrapf(err, "error creating layer with ID %q", id)
|
||||
}
|
||||
return nil, -1, errors.Wrapf(err, "error creating layer")
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(parentMappings.UIDs(), idMappings.UIDs()) || !reflect.DeepEqual(parentMappings.GIDs(), idMappings.GIDs()) {
|
||||
err = r.driver.UpdateLayerIDMap(id, parentMappings, idMappings, mountLabel)
|
||||
if err != nil {
|
||||
if err = r.driver.UpdateLayerIDMap(id, parentMappings, idMappings, mountLabel); err != nil {
|
||||
// We don't have a record of this layer, but at least
|
||||
// try to clean it up underneath us.
|
||||
r.driver.Remove(id)
|
||||
@@ -640,7 +659,7 @@ func (r *layerStore) Mounted(id string) (int, error) {
|
||||
return layer.MountCount, nil
|
||||
}
|
||||
|
||||
func (r *layerStore) Mount(id, mountLabel string, uidMaps, gidMaps []idtools.IDMap) (string, error) {
|
||||
func (r *layerStore) Mount(id string, options drivers.MountOpts) (string, error) {
|
||||
if !r.IsReadWrite() {
|
||||
return "", errors.Wrapf(ErrStoreIsReadOnly, "not allowed to update mount locations for layers at %q", r.mountspath())
|
||||
}
|
||||
@@ -652,16 +671,16 @@ func (r *layerStore) Mount(id, mountLabel string, uidMaps, gidMaps []idtools.IDM
|
||||
layer.MountCount++
|
||||
return layer.MountPoint, r.Save()
|
||||
}
|
||||
if mountLabel == "" {
|
||||
mountLabel = layer.MountLabel
|
||||
if options.MountLabel == "" {
|
||||
options.MountLabel = layer.MountLabel
|
||||
}
|
||||
|
||||
if (uidMaps != nil || gidMaps != nil) && !r.driver.SupportsShifting() {
|
||||
if !reflect.DeepEqual(uidMaps, layer.UIDMap) || !reflect.DeepEqual(gidMaps, layer.GIDMap) {
|
||||
if (options.UidMaps != nil || options.GidMaps != nil) && !r.driver.SupportsShifting() {
|
||||
if !reflect.DeepEqual(options.UidMaps, layer.UIDMap) || !reflect.DeepEqual(options.GidMaps, layer.GIDMap) {
|
||||
return "", fmt.Errorf("cannot mount layer %v: shifting not enabled", layer.ID)
|
||||
}
|
||||
}
|
||||
mountpoint, err := r.driver.Get(id, mountLabel, uidMaps, gidMaps)
|
||||
mountpoint, err := r.driver.Get(id, options)
|
||||
if mountpoint != "" && err == nil {
|
||||
if layer.MountPoint != "" {
|
||||
delete(r.bymount, layer.MountPoint)
|
||||
@@ -822,14 +841,19 @@ func (r *layerStore) Delete(id string) error {
|
||||
return ErrLayerUnknown
|
||||
}
|
||||
id = layer.ID
|
||||
if _, err := r.Unmount(id, true); err != nil {
|
||||
return err
|
||||
// This check is needed for idempotency of delete where the layer could have been
|
||||
// already unmounted (since c/storage gives you that API directly)
|
||||
for layer.MountCount > 0 {
|
||||
if _, err := r.Unmount(id, false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err := r.driver.Remove(id)
|
||||
if err == nil {
|
||||
os.Remove(r.tspath(id))
|
||||
delete(r.byid, id)
|
||||
r.idindex.Delete(id)
|
||||
mountLabel := layer.MountLabel
|
||||
if layer.MountPoint != "" {
|
||||
delete(r.bymount, layer.MountPoint)
|
||||
}
|
||||
@@ -848,6 +872,18 @@ func (r *layerStore) Delete(id string) error {
|
||||
r.layers = append(r.layers[:toDeleteIndex], r.layers[toDeleteIndex+1:]...)
|
||||
}
|
||||
}
|
||||
if mountLabel != "" {
|
||||
var found bool
|
||||
for _, candidate := range r.layers {
|
||||
if candidate.MountLabel == mountLabel {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
label.ReleaseLabel(mountLabel)
|
||||
}
|
||||
}
|
||||
if err = r.Save(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -948,7 +984,7 @@ func (r *layerStore) newFileGetter(id string) (drivers.FileGetCloser, error) {
|
||||
if getter, ok := r.driver.(drivers.DiffGetterDriver); ok {
|
||||
return getter.DiffGetter(id)
|
||||
}
|
||||
path, err := r.Mount(id, "", nil, nil)
|
||||
path, err := r.Mount(id, drivers.MountOpts{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user