1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Implement container.ExportRW() on device-mapper

This commit is contained in:
Alexander Larsson 2013-09-05 22:14:19 +02:00 committed by Victor Vieux
parent 223280f319
commit 94fa3c7bb5
2 changed files with 40 additions and 1 deletions

View file

@ -1110,7 +1110,15 @@ func (container *Container) Resize(h, w int) error {
}
func (container *Container) ExportRw() (Archive, error) {
return Tar(container.rwPath(), Uncompressed)
if err := container.EnsureMounted(); err != nil {
return nil, err
}
image, err := container.GetImage()
if err != nil {
return nil, err
}
return image.ExportChanges(container.runtime, container.RootfsPath(), container.rwPath(), container.ID)
}
func (container *Container) RwChecksum() (string, error) {

View file

@ -523,6 +523,37 @@ func (image *Image) Changes(runtime *Runtime, root, rw, id string) ([]Change, er
return nil, fmt.Errorf("No supported Changes implementation")
}
func (image *Image) ExportChanges(runtime *Runtime, root, rw, id string) (Archive, error) {
switch runtime.GetMountMethod() {
case MountMethodAUFS:
return Tar(rw, Uncompressed)
case MountMethodDeviceMapper:
changes, err := image.Changes(runtime, root, rw, id)
if err != nil {
return nil, err
}
files := make([]string, 0)
deletions := make([]string, 0)
for _, change := range changes {
if change.Kind == ChangeModify || change.Kind == ChangeAdd {
files = append(files, change.Path)
}
if change.Kind == ChangeDelete {
base := filepath.Base(change.Path)
dir := filepath.Dir(change.Path)
deletions = append(deletions, filepath.Join(dir, ".wh."+base))
}
}
return TarFilter(root, Uncompressed, files, false, deletions)
}
return nil, fmt.Errorf("No supported Changes implementation")
}
func (image *Image) ShortID() string {
return utils.TruncateID(image.ID)
}