forked from docker-archive/v1.10-migrator
/
overlay.go
51 lines (41 loc) · 973 Bytes
/
overlay.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"io"
"os"
"path/filepath"
"github.com/docker/docker/pkg/archive"
)
type overlay struct {
root string
}
func NewOverlayChecksums(root string) Mounter {
return &overlay{root}
}
func (c *overlay) Mount(id string) (string, func(), error) {
path := filepath.Join(c.root, id, "root")
if _, err := os.Lstat(path); err != nil {
return "", nil, err
}
return path, nil, nil
}
func (c *overlay) TarStream(id, parent string) (io.ReadCloser, error) {
mainPath, _, err := c.Mount(id)
if err != nil {
return nil, err
}
if parent == "" {
return archive.Tar(mainPath, archive.Uncompressed)
}
parentPath, _, err := c.Mount(parent)
if err != nil {
return nil, err
}
return Diff(mainPath, parentPath)
}
func Diff(mainPath, parentPath string) (arch io.ReadCloser, err error) {
changes, err := archive.ChangesDirs(mainPath, parentPath)
if err != nil {
return nil, err
}
return archive.ExportChanges(mainPath, changes, nil, nil)
}