Skip to content

Commit

Permalink
feat(layer): add whiteout (#55)
Browse files Browse the repository at this point in the history
* feat(layer): add whiteout

* chore: file format
  • Loading branch information
Tsuki124 authored Dec 29, 2022
1 parent 9e2a691 commit 27e1e11
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 6 deletions.
8 changes: 8 additions & 0 deletions go/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,11 @@ func (l *Layer) Image() *Image {
func (l *Layer) ID() string {
return l.layer.DockerLayerID()
}

func (l *Layer) Opaques() ([]string, error) {
return l.layer.DockerLayerOpaques()
}

func (l *Layer) Whiteouts() ([]string, error) {
return l.layer.DockerLayerWhiteouts()
}
2 changes: 2 additions & 0 deletions go/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Layer interface {

Close() error
ID() string
Opaques() ([]string, error)
Whiteouts() ([]string, error)
}

// Image is the open image object from a runtime.
Expand Down
54 changes: 54 additions & 0 deletions go/pkg/binding/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,24 @@ func (h Handle) DockerLayerID() string {
return result.String()
}

func (h Handle) DockerLayerOpaques() ([]string, error) {
var result Handle
if err := handleError(C.veinmind_DockerLayerOpaques(result.Ptr(), h.ID())); err != nil {
return nil, err
}
defer result.Free()
return result.StringArray(), nil
}

func (h Handle) DockerLayerWhiteouts() ([]string, error) {
var result Handle
if err := handleError(C.veinmind_DockerLayerWhiteouts(result.Ptr(), h.ID())); err != nil {
return nil, err
}
defer result.Free()
return result.StringArray(), nil
}

func ContainerdMakeNewOptionList() Handle {
var result Handle
assertNoError(C.veinmind_ContainerdMakeNewOptionList(result.Ptr()))
Expand Down Expand Up @@ -686,6 +704,24 @@ func (h Handle) TarballLayerId() string {
return result.String()
}

func (h Handle) TarballLayerOpaques() ([]string, error) {
var result Handle
if err := handleError(C.veinmind_TarballLayerOpaques(result.Ptr(), h.ID())); err != nil {
return nil, err
}
defer result.Free()
return result.StringArray(), nil
}

func (h Handle) TarballLayerWhiteouts() ([]string, error) {
var result Handle
if err := handleError(C.veinmind_TarballLayerWhiteouts(result.Ptr(), h.ID())); err != nil {
return nil, err
}
defer result.Free()
return result.StringArray(), nil
}

func RemoteNew(root string) (Handle, error) {
var result Handle
rootStr := NewString(root)
Expand Down Expand Up @@ -735,3 +771,21 @@ func (h Handle) RemoteLayerId() string {
defer result.Free()
return result.String()
}

func (h Handle) RemoteLayerOpaques() ([]string, error) {
var result Handle
if err := handleError(C.veinmind_RemoteLayerOpaques(result.Ptr(), h.ID())); err != nil {
return nil, err
}
defer result.Free()
return result.StringArray(), nil
}

func (h Handle) RemoteLayerWhiteouts() ([]string, error) {
var result Handle
if err := handleError(C.veinmind_RemoteLayerWhiteouts(result.Ptr(), h.ID())); err != nil {
return nil, err
}
defer result.Free()
return result.StringArray(), nil
}
8 changes: 8 additions & 0 deletions go/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,11 @@ func (t *Runtime) Load(imageRef string, opts ...LoadOption) ([]string, error) {
func (t *Runtime) Close() error {
return t.runtime.Close()
}

func (l *Layer) Opaques() ([]string, error) {
return l.layer.RemoteLayerOpaques()
}

func (l *Layer) Whiteouts() ([]string, error) {
return l.layer.RemoteLayerWhiteouts()
}
14 changes: 11 additions & 3 deletions go/tarball/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func (i *Image) OpenLayer(index int) (api.Layer, error) {
}

return &Layer{
Closer: behaviour.NewCloser(&h),
Closer: behaviour.NewCloser(&h),
FileSystem: behaviour.NewFileSystem(&h),
layer: h,
image: i,
layer: h,
image: i,
}, nil
}

Expand All @@ -51,3 +51,11 @@ func (l *Layer) ID() string {
func (l *Layer) Image() *Image {
return l.image
}

func (l *Layer) Opaques() ([]string, error) {
return l.layer.TarballLayerOpaques()
}

func (l *Layer) Whiteouts() ([]string, error) {
return l.layer.TarballLayerWhiteouts()
}
20 changes: 20 additions & 0 deletions python3/veinmind/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@ def id(self):
with handle as handle:
return handle.str()

_opaques = binding.lookup(b"veinmind_DockerLayerOpaques", b"VEINMIND_1.5")
def opaques(self):
"Retrieve the opaques of the docker layer."

handle = binding.Handle()
binding.handle_error(Layer._opaques(
handle.ptr(), self.__handle__().val()))
with handle as handle:
return handle.str_list()

_whiteouts = binding.lookup(b"veinmind_DockerLayerWhiteouts", b"VEINMIND_1.5")
def whiteouts(self):
"Retrieve the whiteouts of the docker layer."

handle = binding.Handle()
binding.handle_error(Layer._whiteouts(
handle.ptr(), self.__handle__().val()))
with handle as handle:
return handle.str_list()

class Image(image.Image):
"Image refers to a docker specific image."

Expand Down
23 changes: 21 additions & 2 deletions python3/veinmind/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,35 @@ def __init__(self, handle):
super(Layer, self).__init__(handle=handle)

_id = binding.lookup(b"veinmind_RemoteLayerID", b"VEINMIND_1.4")

def id(self):
"Retrieve the diff ID of the docker layer."
"Retrieve the diff ID of the remote layer."

handle = binding.Handle()
binding.handle_error(Layer._id(
handle.ptr(), self.__handle__().val()))
with handle as handle:
return handle.str()

_opaques = binding.lookup(b"veinmind_RemoteLayerOpaques", b"VEINMIND_1.5")
def opaques(self):
"Retrieve the opaques of the remote layer."

handle = binding.Handle()
binding.handle_error(Layer._opaques(
handle.ptr(), self.__handle__().val()))
with handle as handle:
return handle.str_list()

_whiteouts = binding.lookup(b"veinmind_RemoteLayerWhiteouts", b"VEINMIND_1.5")
def whiteouts(self):
"Retrieve the whiteouts of the remote layer."

handle = binding.Handle()
binding.handle_error(Layer._whiteouts(
handle.ptr(), self.__handle__().val()))
with handle as handle:
return handle.str_list()


class Image(image.Image):
_open_layer = binding.lookup(
Expand Down
24 changes: 23 additions & 1 deletion python3/veinmind/tarball.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,26 @@ def num_layers(self):
result = C.c_size_t()
binding.handle_error(Image._num_layers(
C.pointer(result), self.__handle__().val()))
return result.value
return result.value

_opaques = binding.lookup(
b"veinmind_TarballLayerOpaques", b"VEINMIND_1.5")
def opaques(self):
"Retrieve the opaques of the tarball layer."

handle = binding.Handle()
binding.handle_error(Layer._opaques(
handle.ptr(), self.__handle__().val()))
with handle as handle:
return handle.str_list()

_whiteouts = binding.lookup(
b"veinmind_TarballLayerWhiteouts", b"VEINMIND_1.5")
def whiteouts(self):
"Retrieve the whiteouts of the tarball layer."

handle = binding.Handle()
binding.handle_error(Layer._whiteouts(
handle.ptr(), self.__handle__().val()))
with handle as handle:
return handle.str_list()

0 comments on commit 27e1e11

Please sign in to comment.