aboutsummaryrefslogtreecommitdiff
path: root/internal/dup/dup.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-12 12:58:14 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-12 12:58:14 +0200
commit24a84671ace373ae331fa83a1ff484990f4dff0e (patch)
treea6b6e3949d7dd241f1d13e079dfb982d758c89a2 /internal/dup/dup.go
parent3b36a48b7ce5a53a9366f3b31f94311f178e2553 (diff)
downloadkrino-24a84671ace373ae331fa83a1ff484990f4dff0e.tar.gz
krino-24a84671ace373ae331fa83a1ff484990f4dff0e.zip
krino: planning — chains, placeholders, conflicts, JSON
Diffstat (limited to 'internal/dup/dup.go')
-rw-r--r--internal/dup/dup.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/dup/dup.go b/internal/dup/dup.go
index 502ef31..e3c7424 100644
--- a/internal/dup/dup.go
+++ b/internal/dup/dup.go
@@ -381,6 +381,47 @@ func readAt(f *os.File, off int64) ([]byte, error) {
return buf[:n], nil
}
+// SameContent reports whether a and b hold identical content: a stat and
+// size check first, then the same partial/full hash comparison Lookup uses
+// for scanned candidates. Neither file needs to have been scanned or
+// indexed; this is the one place content identity is decided, so callers
+// outside this package must not hash a second way.
+func SameContent(a, b string) (bool, error) {
+ ai, err := os.Stat(a)
+ if err != nil {
+ return false, err
+ }
+ bi, err := os.Stat(b)
+ if err != nil {
+ return false, err
+ }
+ if ai.Size() != bi.Size() {
+ return false, nil
+ }
+
+ aPartial, err := computePartialHash(a)
+ if err != nil {
+ return false, err
+ }
+ bPartial, err := computePartialHash(b)
+ if err != nil {
+ return false, err
+ }
+ if aPartial != bPartial {
+ return false, nil
+ }
+
+ aFull, err := computeFullHash(a)
+ if err != nil {
+ return false, err
+ }
+ bFull, err := computeFullHash(b)
+ if err != nil {
+ return false, err
+ }
+ return aFull == bFull, nil
+}
+
// computeFullHash hashes the whole file.
func computeFullHash(path string) ([sha256.Size]byte, error) {
f, err := os.Open(path)