Make changes to mode or owner show in UI (#142)
Previously, changes that did not affect the data in a file, such as a chmod or chown, would incorrectly show up as unmodified in the UI. This change makes it so that changes to the mode or owner (Mode, Gid, or Uid) of a file cause the file to appear modified in the UI.
This commit is contained in:
parent
a830f34c1f
commit
ad32c0a091
@ -11,3 +11,4 @@ RUN rm -rf /root/example/
|
||||
ADD .data/ /root/.data/
|
||||
RUN cp /root/saved.txt /tmp/saved.again1.txt
|
||||
RUN cp /root/saved.txt /root/.data/saved.again2.txt
|
||||
RUN chmod +x /root/saved.txt
|
||||
|
@ -122,7 +122,10 @@ func (data *FileInfo) Copy() *FileInfo {
|
||||
// Compare determines the DiffType between two FileInfos based on the type and contents of each given FileInfo
|
||||
func (data *FileInfo) Compare(other FileInfo) DiffType {
|
||||
if data.TypeFlag == other.TypeFlag {
|
||||
if data.hash == other.hash {
|
||||
if data.hash == other.hash &&
|
||||
data.Mode == other.Mode &&
|
||||
data.Uid == other.Uid &&
|
||||
data.Gid == other.Gid {
|
||||
return Unchanged
|
||||
}
|
||||
}
|
||||
|
@ -348,9 +348,9 @@ func TestCompareWithAdds(t *testing.T) {
|
||||
func TestCompareWithChanges(t *testing.T) {
|
||||
lowerTree := NewFileTree()
|
||||
upperTree := NewFileTree()
|
||||
paths := [...]string{"/etc", "/usr", "/etc/hosts", "/etc/sudoers", "/usr/bin"}
|
||||
changedPaths := []string{"/etc", "/usr", "/etc/hosts", "/etc/sudoers", "/usr/bin"}
|
||||
|
||||
for _, value := range paths {
|
||||
for _, value := range changedPaths {
|
||||
lowerTree.AddPath(value, FileInfo{
|
||||
Path: value,
|
||||
TypeFlag: 1,
|
||||
@ -363,13 +363,53 @@ func TestCompareWithChanges(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
chmodPath := "/etc/non-data-change"
|
||||
|
||||
lowerTree.AddPath(chmodPath, FileInfo{
|
||||
Path: chmodPath,
|
||||
TypeFlag: 1,
|
||||
hash: 123,
|
||||
Mode: 0,
|
||||
})
|
||||
|
||||
upperTree.AddPath(chmodPath, FileInfo{
|
||||
Path: chmodPath,
|
||||
TypeFlag: 1,
|
||||
hash: 123,
|
||||
Mode: 1,
|
||||
})
|
||||
|
||||
changedPaths = append(changedPaths, chmodPath)
|
||||
|
||||
chownPath := "/etc/non-data-change-2"
|
||||
|
||||
lowerTree.AddPath(chmodPath, FileInfo{
|
||||
Path: chownPath,
|
||||
TypeFlag: 1,
|
||||
hash: 123,
|
||||
Mode: 1,
|
||||
Gid: 0,
|
||||
Uid: 0,
|
||||
})
|
||||
|
||||
upperTree.AddPath(chmodPath, FileInfo{
|
||||
Path: chownPath,
|
||||
TypeFlag: 1,
|
||||
hash: 123,
|
||||
Mode: 1,
|
||||
Gid: 12,
|
||||
Uid: 12,
|
||||
})
|
||||
|
||||
changedPaths = append(changedPaths, chownPath)
|
||||
|
||||
lowerTree.Compare(upperTree)
|
||||
failedAssertions := []error{}
|
||||
asserter := func(n *FileNode) error {
|
||||
p := n.Path()
|
||||
if p == "/" {
|
||||
return nil
|
||||
} else if stringInSlice(p, []string{"/etc", "/usr", "/etc/hosts", "/etc/sudoers", "/usr/bin"}) {
|
||||
} else if stringInSlice(p, changedPaths) {
|
||||
if err := AssertDiffType(n, Changed); err != nil {
|
||||
failedAssertions = append(failedAssertions, err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user