Przeglądaj źródła

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 lat temu
rodzic
commit
d69a6a20f0
2 zmienionych plików z 9 dodań i 26 usunięć
  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
 }
 
-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,
+	})
 }

+ 1 - 20
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 {