Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 5f6f6ae

Browse files
author
priyawadhwa
authored
Merge pull request #231 from priyawadhwa/lstat
Check if symlinks are the same during file system diffing
2 parents b5c0512 + 43b918e commit 5f6f6ae

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

pkg/util/fs_utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ func CreateDirectoryEntries(root string, entryNames []string) (entries []Directo
130130
return entries
131131
}
132132

133+
func CheckSameSymlink(f1name, f2name string) (bool, error) {
134+
link1, err := os.Readlink(f1name)
135+
if err != nil {
136+
return false, err
137+
}
138+
link2, err := os.Readlink(f2name)
139+
if err != nil {
140+
return false, err
141+
}
142+
return (link1 == link2), nil
143+
}
144+
133145
func CheckSameFile(f1name, f2name string) (bool, error) {
134146
// Check first if files differ in size and immediately return
135147
f1stat, err := os.Stat(f1name)

util/diff_utils.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,30 @@ func GetModifiedEntries(d1, d2 pkgutil.Directory) []string {
194194
f1path := fmt.Sprintf("%s%s", d1.Root, f)
195195
f2path := fmt.Sprintf("%s%s", d2.Root, f)
196196

197-
f1stat, err := os.Stat(f1path)
197+
f1stat, err := os.Lstat(f1path)
198198
if err != nil {
199199
logrus.Errorf("Error checking directory entry %s: %s\n", f, err)
200200
continue
201201
}
202-
f2stat, err := os.Stat(f2path)
202+
f2stat, err := os.Lstat(f2path)
203203
if err != nil {
204204
logrus.Errorf("Error checking directory entry %s: %s\n", f, err)
205205
continue
206206
}
207207

208+
// If the directory entry is a symlink, make sure the symlinks point to the same place
209+
if f1stat.Mode()&os.ModeSymlink != 0 && f2stat.Mode()&os.ModeSymlink != 0 {
210+
same, err := pkgutil.CheckSameSymlink(f1path, f2path)
211+
if err != nil {
212+
logrus.Errorf("Error determining if symlink %s and %s are equivalent: %s\n", f1path, f2path, err)
213+
continue
214+
}
215+
if !same {
216+
modified = append(modified, f)
217+
}
218+
continue
219+
}
220+
208221
// If the directory entry in question is a tar, verify that the two have the same size
209222
if pkgutil.IsTar(f1path) {
210223
if f1stat.Size() != f2stat.Size() {

0 commit comments

Comments
 (0)