Skip to content

Commit

Permalink
Merge pull request moby#39140 from ehazlett/apply-diff-rwlayer
Browse files Browse the repository at this point in the history
ApplyDiff to RWLayer
  • Loading branch information
dmcgowan authored May 1, 2019
2 parents 9a2c263 + 794e811 commit e516af6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions layer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ type RWLayer interface {

// Metadata returns the low level metadata for the mutable layer
Metadata() (map[string]string, error)

// ApplyDiff applies the diff to the RW layer
ApplyDiff(diff io.Reader) (int64, error)
}

// Metadata holds information about a
Expand Down
58 changes: 58 additions & 0 deletions layer/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,64 @@ func TestMountChanges(t *testing.T) {
})
}

func TestMountApply(t *testing.T) {
// TODO Windows: Figure out why this is failing
if runtime.GOOS == "windows" {
t.Skip("Failing on Windows")
}
ls, _, cleanup := newTestStore(t)
defer cleanup()

basefile := newTestFile("testfile.txt", []byte("base data!"), 0644)
newfile := newTestFile("newfile.txt", []byte("new data!"), 0755)

li := initWithFiles(basefile)
layer, err := createLayer(ls, "", li)
if err != nil {
t.Fatal(err)
}

di := initWithFiles(newfile)
diffLayer, err := createLayer(ls, "", di)
if err != nil {
t.Fatal(err)
}

m, err := ls.CreateRWLayer("fun-mount", layer.ChainID(), nil)
if err != nil {
t.Fatal(err)
}

r, err := diffLayer.TarStream()
if err != nil {
t.Fatal(err)
}

if _, err := m.ApplyDiff(r); err != nil {
t.Fatal(err)
}

pathFS, err := m.Mount("")
if err != nil {
t.Fatal(err)
}

f, err := pathFS.Open(pathFS.Join(pathFS.Path(), "newfile.txt"))
if err != nil {
t.Fatal(err)
}
defer f.Close()

b, err := ioutil.ReadAll(f)
if err != nil {
t.Fatal(err)
}

if expected := "new data!"; string(b) != expected {
t.Fatalf("Unexpected test file contents %q, expected %q", string(b), expected)
}
}

func assertChange(t *testing.T, actual, expected archive.Change) {
if actual.Path != expected.Path {
t.Fatalf("Unexpected change path %s, expected %s", actual.Path, expected.Path)
Expand Down
5 changes: 5 additions & 0 deletions layer/mounted_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ func (rl *referencedRWLayer) Mount(mountLabel string) (containerfs.ContainerFS,
func (rl *referencedRWLayer) Unmount() error {
return rl.layerStore.driver.Put(rl.mountedLayer.mountID)
}

// ApplyDiff applies specified diff to the layer
func (rl *referencedRWLayer) ApplyDiff(diff io.Reader) (int64, error) {
return rl.layerStore.driver.ApplyDiff(rl.mountID, rl.cacheParent(), diff)
}

0 comments on commit e516af6

Please sign in to comment.