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

Include directories that contain changes inside them when calculating diff. Fixes #6722

Docker-DCO-1.1-Signed-off-by: Leszek Kowalski <github@leszekkowalski.pl> (github: ljk)
This commit is contained in:
Leszek Kowalski 2014-07-12 23:28:04 +01:00 committed by unclejack
parent 8f0034c3ee
commit 691bbf6a29

View file

@ -136,6 +136,7 @@ type FileInfo struct {
stat syscall.Stat_t stat syscall.Stat_t
children map[string]*FileInfo children map[string]*FileInfo
capability []byte capability []byte
added bool
} }
func (root *FileInfo) LookUp(path string) *FileInfo { func (root *FileInfo) LookUp(path string) *FileInfo {
@ -169,6 +170,9 @@ func (info *FileInfo) isDir() bool {
} }
func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) { func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) {
sizeAtEntry := len(*changes)
if oldInfo == nil { if oldInfo == nil {
// add // add
change := Change{ change := Change{
@ -176,6 +180,7 @@ func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) {
Kind: ChangeAdd, Kind: ChangeAdd,
} }
*changes = append(*changes, change) *changes = append(*changes, change)
info.added = true
} }
// We make a copy so we can modify it to detect additions // We make a copy so we can modify it to detect additions
@ -213,6 +218,7 @@ func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) {
Kind: ChangeModify, Kind: ChangeModify,
} }
*changes = append(*changes, change) *changes = append(*changes, change)
newChild.added = true
} }
// Remove from copy so we can detect deletions // Remove from copy so we can detect deletions
@ -230,6 +236,19 @@ func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) {
*changes = append(*changes, change) *changes = append(*changes, change)
} }
// If there were changes inside this directory, we need to add it, even if the directory
// itself wasn't changed. This is needed to properly save and restore filesystem permissions.
if len(*changes) > sizeAtEntry && info.isDir() && !info.added && info.path() != "/" {
change := Change{
Path: info.path(),
Kind: ChangeModify,
}
// Let's insert the directory entry before the recently added entries located inside this dir
*changes = append(*changes, change) // just to resize the slice, will be overwritten
copy((*changes)[sizeAtEntry+1:], (*changes)[sizeAtEntry:])
(*changes)[sizeAtEntry] = change
}
} }
func (info *FileInfo) Changes(oldInfo *FileInfo) []Change { func (info *FileInfo) Changes(oldInfo *FileInfo) []Change {