Skip to content

Commit d69a6a2

Browse files
committed
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.
1 parent 006e2a6 commit d69a6a2

2 files changed

Lines changed: 9 additions & 26 deletions

File tree

archive/changes.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,7 @@ func ChangesDirs(newDir, oldDir string) ([]Change, error) {
280280
return newRoot.Changes(oldRoot), nil
281281
}
282282

283-
func ExportChanges(root, rw string) (Archive, error) {
284-
changes, err := ChangesDirs(root, rw)
285-
if err != nil {
286-
return nil, err
287-
}
283+
func ExportChanges(dir string, changes []Change) (Archive, error) {
288284
files := make([]string, 0)
289285
deletions := make([]string, 0)
290286
for _, change := range changes {
@@ -297,5 +293,11 @@ func ExportChanges(root, rw string) (Archive, error) {
297293
deletions = append(deletions, filepath.Join(dir, ".wh."+base))
298294
}
299295
}
300-
return TarFilter(root, &TarOptions{Compression: Uncompressed, Recursive: false, Includes: files, CreateFiles: deletions})
296+
// FIXME: Why do we create whiteout files inside Tar code ?
297+
return TarFilter(dir, &TarOptions{
298+
Compression: Uncompressed,
299+
Includes: files,
300+
Recursive: false,
301+
CreateFiles: deletions,
302+
})
301303
}

runtime.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"os"
1919
"os/exec"
2020
"path"
21-
"path/filepath"
2221
"sort"
2322
"strings"
2423
"time"
@@ -763,25 +762,7 @@ func (runtime *Runtime) Diff(container *Container) (archive.Archive, error) {
763762
return nil, fmt.Errorf("Error getting container rootfs %s from driver %s: %s", container.ID, container.runtime.driver, err)
764763
}
765764

766-
files := make([]string, 0)
767-
deletions := make([]string, 0)
768-
for _, change := range changes {
769-
if change.Kind == archive.ChangeModify || change.Kind == archive.ChangeAdd {
770-
files = append(files, change.Path)
771-
}
772-
if change.Kind == archive.ChangeDelete {
773-
base := filepath.Base(change.Path)
774-
dir := filepath.Dir(change.Path)
775-
deletions = append(deletions, filepath.Join(dir, ".wh."+base))
776-
}
777-
}
778-
// FIXME: Why do we create whiteout files inside Tar code ?
779-
return archive.TarFilter(cDir, &archive.TarOptions{
780-
Compression: archive.Uncompressed,
781-
Includes: files,
782-
Recursive: false,
783-
CreateFiles: deletions,
784-
})
765+
return archive.ExportChanges(cDir, changes)
785766
}
786767

787768
func linkLxcStart(root string) error {

0 commit comments

Comments
 (0)