Skip to content

Commit

Permalink
Replace custom inode-based file comparison with os.SameFile.
Browse files Browse the repository at this point in the history
Remove inode.go, inode_freebsd.go, and inode_windows.go, eliminating platform-specific inode lookup logic.
Replace sameFile function with os.SameFile, simplifying file comparison logic.
  • Loading branch information
Gofastasf committed Feb 21, 2025
1 parent 85db226 commit a6b6db8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 96 deletions.
44 changes: 10 additions & 34 deletions internal/configs/configload/copy_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ func copyDir(dst, src string) error {
// destination with the path without the src on it.
dstPath := filepath.Join(dst, path[len(src):])

// we don't want to try and copy the same file over itself.
if eq, err := sameFile(path, dstPath); eq {
// Call os.Lstat on dstPath to obtain os.FileInfo since os.SameFile
// requires FileInfo objects for comparison.
dstInfo, err := os.Lstat(dstPath)
if err != nil {
if !os.IsNotExist(err) {
return err
}
} else if os.SameFile(info, dstInfo) {
// The destination file exists and is the same as the source file;
// skip copying.
return nil
} else if err != nil {
return err
}

// If we have a directory, make that subdirectory, then continue
Expand Down Expand Up @@ -86,33 +92,3 @@ func copyDir(dst, src string) error {

return filepath.Walk(src, walkFn)
}

// sameFile tried to determine if to paths are the same file.
// If the paths don't match, we lookup the inode on supported systems.
func sameFile(a, b string) (bool, error) {
if a == b {
return true, nil
}

aIno, err := inode(a)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}

bIno, err := inode(b)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}

if aIno > 0 && aIno == bIno {
return true, nil
}

return false, nil
}
25 changes: 0 additions & 25 deletions internal/configs/configload/inode.go

This file was deleted.

25 changes: 0 additions & 25 deletions internal/configs/configload/inode_freebsd.go

This file was deleted.

12 changes: 0 additions & 12 deletions internal/configs/configload/inode_windows.go

This file was deleted.

0 comments on commit a6b6db8

Please sign in to comment.