Refactor checking for compressed diff type
Signed-off-by: Darren Stahl <darst@microsoft.com>
This commit is contained in:
parent
e6280a7c82
commit
95a0b3af95
@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd/archive"
|
"github.com/containerd/containerd/archive"
|
||||||
@ -75,18 +74,10 @@ func (s *walkingDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts
|
|||||||
}).Debugf("diff applied")
|
}).Debugf("diff applied")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
var isCompressed bool
|
|
||||||
switch desc.MediaType {
|
isCompressed, err := images.IsCompressedDiff(ctx, desc.MediaType)
|
||||||
case ocispec.MediaTypeImageLayer, images.MediaTypeDockerSchema2Layer:
|
if err != nil {
|
||||||
case ocispec.MediaTypeImageLayerGzip, images.MediaTypeDockerSchema2LayerGzip:
|
return emptyDesc, errors.Wrapf(errdefs.ErrNotImplemented, "unsupported diff media type: %v", desc.MediaType)
|
||||||
isCompressed = true
|
|
||||||
default:
|
|
||||||
// Still apply all generic media types *.tar[.+]gzip and *.tar
|
|
||||||
if strings.HasSuffix(desc.MediaType, ".tar.gzip") || strings.HasSuffix(desc.MediaType, ".tar+gzip") {
|
|
||||||
isCompressed = true
|
|
||||||
} else if !strings.HasSuffix(desc.MediaType, ".tar") {
|
|
||||||
return emptyDesc, errors.Wrapf(errdefs.ErrNotImplemented, "unsupported diff media type: %v", desc.MediaType)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ocidesc ocispec.Descriptor
|
var ocidesc ocispec.Descriptor
|
||||||
|
@ -5,7 +5,6 @@ package windows
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
winio "github.com/Microsoft/go-winio"
|
winio "github.com/Microsoft/go-winio"
|
||||||
@ -74,18 +73,10 @@ func (s *windowsDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts
|
|||||||
}).Debugf("diff applied")
|
}).Debugf("diff applied")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
var isCompressed bool
|
|
||||||
switch desc.MediaType {
|
isCompressed, err := images.IsCompressedDiff(ctx, desc.MediaType)
|
||||||
case ocispec.MediaTypeImageLayer, images.MediaTypeDockerSchema2Layer:
|
if err != nil {
|
||||||
case ocispec.MediaTypeImageLayerGzip, images.MediaTypeDockerSchema2LayerGzip:
|
return emptyDesc, errors.Wrapf(errdefs.ErrNotImplemented, "unsupported diff media type: %v", desc.MediaType)
|
||||||
isCompressed = true
|
|
||||||
default:
|
|
||||||
// Still apply all generic media types *.tar[.+]gzip and *.tar
|
|
||||||
if strings.HasSuffix(desc.MediaType, ".tar.gzip") || strings.HasSuffix(desc.MediaType, ".tar+gzip") {
|
|
||||||
isCompressed = true
|
|
||||||
} else if !strings.HasSuffix(desc.MediaType, ".tar") {
|
|
||||||
return emptyDesc, errors.Wrapf(errdefs.ErrNotImplemented, "unsupported diff media type: %v", desc.MediaType)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ra, err := s.store.ReaderAt(ctx, desc.Digest)
|
ra, err := s.store.ReaderAt(ctx, desc.Digest)
|
||||||
|
@ -3,6 +3,7 @@ package images
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd/content"
|
"github.com/containerd/containerd/content"
|
||||||
@ -359,3 +360,22 @@ func RootFS(ctx context.Context, provider content.Provider, configDesc ocispec.D
|
|||||||
}
|
}
|
||||||
return config.RootFS.DiffIDs, nil
|
return config.RootFS.DiffIDs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsCompressedDiff returns true if mediaType is a known compressed diff media type.
|
||||||
|
// It returns false if the media type is a diff, but not compressed. If the media type
|
||||||
|
// is not a known diff type, it returns errdefs.ErrNotImplemented
|
||||||
|
func IsCompressedDiff(ctx context.Context, mediaType string) (bool, error) {
|
||||||
|
switch mediaType {
|
||||||
|
case ocispec.MediaTypeImageLayer, MediaTypeDockerSchema2Layer:
|
||||||
|
case ocispec.MediaTypeImageLayerGzip, MediaTypeDockerSchema2LayerGzip:
|
||||||
|
return true, nil
|
||||||
|
default:
|
||||||
|
// Still apply all generic media types *.tar[.+]gzip and *.tar
|
||||||
|
if strings.HasSuffix(mediaType, ".tar.gzip") || strings.HasSuffix(mediaType, ".tar+gzip") {
|
||||||
|
return true, nil
|
||||||
|
} else if !strings.HasSuffix(mediaType, ".tar") {
|
||||||
|
return false, errdefs.ErrNotImplemented
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user