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

Check if symlinks are the same during file system diffing #231

Merged
merged 1 commit into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/util/fs_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ func CreateDirectoryEntries(root string, entryNames []string) (entries []Directo
return entries
}

func CheckSameSymlink(f1name, f2name string) (bool, error) {
link1, err := os.Readlink(f1name)
if err != nil {
return false, err
}
link2, err := os.Readlink(f2name)
if err != nil {
return false, err
}
return (link1 == link2), nil
}

func CheckSameFile(f1name, f2name string) (bool, error) {
// Check first if files differ in size and immediately return
f1stat, err := os.Stat(f1name)
Expand Down
17 changes: 15 additions & 2 deletions util/diff_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,30 @@ func GetModifiedEntries(d1, d2 pkgutil.Directory) []string {
f1path := fmt.Sprintf("%s%s", d1.Root, f)
f2path := fmt.Sprintf("%s%s", d2.Root, f)

f1stat, err := os.Stat(f1path)
f1stat, err := os.Lstat(f1path)
if err != nil {
logrus.Errorf("Error checking directory entry %s: %s\n", f, err)
continue
}
f2stat, err := os.Stat(f2path)
f2stat, err := os.Lstat(f2path)
if err != nil {
logrus.Errorf("Error checking directory entry %s: %s\n", f, err)
continue
}

// If the directory entry is a symlink, make sure the symlinks point to the same place
if f1stat.Mode()&os.ModeSymlink != 0 && f2stat.Mode()&os.ModeSymlink != 0 {
same, err := pkgutil.CheckSameSymlink(f1path, f2path)
if err != nil {
logrus.Errorf("Error determining if symlink %s and %s are equivalent: %s\n", f1path, f2path, err)
continue
}
if !same {
modified = append(modified, f)
}
continue
}

// If the directory entry in question is a tar, verify that the two have the same size
if pkgutil.IsTar(f1path) {
if f1stat.Size() != f2stat.Size() {
Expand Down