From bacf1f2d844cd8b917ad0d38e0d3ba01d74dcae8 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 9 May 2021 12:27:28 +0200 Subject: [PATCH] sync: include size in binary "diff" --- cmd/safcm-remote/sync/files.go | 9 ++++++--- cmd/safcm-remote/sync/files_test.go | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmd/safcm-remote/sync/files.go b/cmd/safcm-remote/sync/files.go index 119a353..3e88be2 100644 --- a/cmd/safcm-remote/sync/files.go +++ b/cmd/safcm-remote/sync/files.go @@ -452,13 +452,16 @@ func diffData(oldData []byte, newData []byte) (string, error) { oldBin := !strings.HasPrefix(http.DetectContentType(oldData), "text/") newBin := !strings.HasPrefix(http.DetectContentType(newData), "text/") if oldBin && newBin { - return "Binary files differ, cannot show diff", nil + return fmt.Sprintf("Binary files differ (%d -> %d bytes), "+ + "cannot show diff", len(oldData), len(newData)), nil } if oldBin { - oldData = []byte("\n") + oldData = []byte(fmt.Sprintf("\n", + len(oldData))) } if newBin { - newData = []byte("\n") + newData = []byte(fmt.Sprintf("\n", + len(newData))) } // TODO: difflib shows empty context lines at the end of the file diff --git a/cmd/safcm-remote/sync/files_test.go b/cmd/safcm-remote/sync/files_test.go index 2e3ed3e..27011ac 100644 --- a/cmd/safcm-remote/sync/files_test.go +++ b/cmd/safcm-remote/sync/files_test.go @@ -2239,7 +2239,7 @@ file Group: group, Gid: gid, }, - DataDiff: "Binary files differ, cannot show diff", + DataDiff: "Binary files differ (3 -> 4 bytes), cannot show diff", }, }, }, @@ -2295,7 +2295,7 @@ file Gid: gid, }, DataDiff: `@@ -1,2 +1,2 @@ -- +- +content `, @@ -2355,7 +2355,7 @@ file }, DataDiff: `@@ -1,2 +1,2 @@ -content -+ ++ `, }, -- 2.45.2