浏览代码

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.
Alexander Larsson 11 年之前
父节点
当前提交
d69a6a20f0
共有 2 个文件被更改,包括 9 次插入26 次删除
  1. 8 6
      archive/changes.go
  2. 1 20
      runtime.go

+ 8 - 6
archive/changes.go

@@ -280,11 +280,7 @@ func ChangesDirs(newDir, oldDir string) ([]Change, error) {
 	return newRoot.Changes(oldRoot), nil
 	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)
 	files := make([]string, 0)
 	deletions := make([]string, 0)
 	deletions := make([]string, 0)
 	for _, change := range changes {
 	for _, change := range changes {
@@ -297,5 +293,11 @@ func ExportChanges(root, rw string) (Archive, error) {
 			deletions = append(deletions, filepath.Join(dir, ".wh."+base))
 			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,
+	})
 }
 }

+ 1 - 20
runtime.go

@@ -18,7 +18,6 @@ import (
 	"os"
 	"os"
 	"os/exec"
 	"os/exec"
 	"path"
 	"path"
-	"path/filepath"
 	"sort"
 	"sort"
 	"strings"
 	"strings"
 	"time"
 	"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)
 		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 {
 func linkLxcStart(root string) error {