mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Changes: Better metadata comparison
Change the comparison to better handle files that are copied during container creation but not actually changed: * Inode - this will change during a copy * ctime - this will change during a copy (as we can't set it back) * blocksize - this will change for sparse files during copy * size for directories - this can change anytime but doesn't necessarily reflect an actual contents change * Compare mtimes at microsecond precision (as this is what utimes has)
This commit is contained in:
parent
5d2ace3424
commit
ad402763e1
1 changed files with 13 additions and 6 deletions
19
changes.go
19
changes.go
|
@ -185,15 +185,22 @@ func (info *FileInfo)addChanges(oldInfo *FileInfo, changes *[]Change) {
|
||||||
// change?
|
// change?
|
||||||
oldStat := &oldChild.stat
|
oldStat := &oldChild.stat
|
||||||
newStat := &newChild.stat
|
newStat := &newChild.stat
|
||||||
if oldStat.Ino != newStat.Ino ||
|
// Note: We can't compare inode or ctime or blocksize here, because these change
|
||||||
oldStat.Mode != newStat.Mode ||
|
// when copying a file into a container. However, that is not generally a problem
|
||||||
|
// because any content change will change mtime, and any status change should
|
||||||
|
// be visible when actually comparing the stat fields. The only time this
|
||||||
|
// breaks down is if some code intentionally hides a change by setting
|
||||||
|
// back mtime
|
||||||
|
oldMtime := syscall.NsecToTimeval(oldStat.Mtim.Nano())
|
||||||
|
newMtime := syscall.NsecToTimeval(oldStat.Mtim.Nano())
|
||||||
|
if oldStat.Mode != newStat.Mode ||
|
||||||
oldStat.Uid != newStat.Uid ||
|
oldStat.Uid != newStat.Uid ||
|
||||||
oldStat.Gid != newStat.Gid ||
|
oldStat.Gid != newStat.Gid ||
|
||||||
oldStat.Rdev != newStat.Rdev ||
|
oldStat.Rdev != newStat.Rdev ||
|
||||||
oldStat.Size != newStat.Size ||
|
// Don't look at size for dirs, its not a good measure of change
|
||||||
oldStat.Blocks != newStat.Blocks ||
|
(oldStat.Size != newStat.Size && oldStat.Mode &syscall.S_IFDIR != syscall.S_IFDIR) ||
|
||||||
oldStat.Mtim != newStat.Mtim ||
|
oldMtime.Sec != newMtime.Sec ||
|
||||||
oldStat.Ctim != newStat.Ctim {
|
oldMtime.Usec != newMtime.Usec {
|
||||||
change := Change{
|
change := Change{
|
||||||
Path: newChild.path(),
|
Path: newChild.path(),
|
||||||
Kind: ChangeModify,
|
Kind: ChangeModify,
|
||||||
|
|
Loading…
Add table
Reference in a new issue