From d69a6a20f0b6657821638ee591920d071a784b0e Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 14 Nov 2013 22:57:33 +0100 Subject: [PATCH] Use ExportChanges() in runtime.Diff() This code was duplicated in two places, one which was unused. This syncs the code and removes the unused version. --- archive/changes.go | 14 ++++++++------ runtime.go | 21 +-------------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/archive/changes.go b/archive/changes.go index d94d8bc33c..9305fe2311 100644 --- a/archive/changes.go +++ b/archive/changes.go @@ -280,11 +280,7 @@ func ChangesDirs(newDir, oldDir string) ([]Change, error) { return newRoot.Changes(oldRoot), nil } -func ExportChanges(root, rw string) (Archive, error) { - changes, err := ChangesDirs(root, rw) - if err != nil { - return nil, err - } +func ExportChanges(dir string, changes []Change) (Archive, error) { files := make([]string, 0) deletions := make([]string, 0) for _, change := range changes { @@ -297,5 +293,11 @@ func ExportChanges(root, rw string) (Archive, error) { deletions = append(deletions, filepath.Join(dir, ".wh."+base)) } } - return TarFilter(root, &TarOptions{Compression: Uncompressed, Recursive: false, Includes: files, CreateFiles: deletions}) + // FIXME: Why do we create whiteout files inside Tar code ? + return TarFilter(dir, &TarOptions{ + Compression: Uncompressed, + Includes: files, + Recursive: false, + CreateFiles: deletions, + }) } diff --git a/runtime.go b/runtime.go index 1429d54a37..6835be5ea2 100644 --- a/runtime.go +++ b/runtime.go @@ -18,7 +18,6 @@ import ( "os" "os/exec" "path" - "path/filepath" "sort" "strings" "time" @@ -763,25 +762,7 @@ func (runtime *Runtime) Diff(container *Container) (archive.Archive, error) { return nil, fmt.Errorf("Error getting container rootfs %s from driver %s: %s", container.ID, container.runtime.driver, err) } - files := make([]string, 0) - deletions := make([]string, 0) - for _, change := range changes { - if change.Kind == archive.ChangeModify || change.Kind == archive.ChangeAdd { - files = append(files, change.Path) - } - if change.Kind == archive.ChangeDelete { - base := filepath.Base(change.Path) - dir := filepath.Dir(change.Path) - deletions = append(deletions, filepath.Join(dir, ".wh."+base)) - } - } - // FIXME: Why do we create whiteout files inside Tar code ? - return archive.TarFilter(cDir, &archive.TarOptions{ - Compression: archive.Uncompressed, - Includes: files, - Recursive: false, - CreateFiles: deletions, - }) + return archive.ExportChanges(cDir, changes) } func linkLxcStart(root string) error {