]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
sync: include size in binary "diff"
authorSimon Ruderich <simon@ruderich.org>
Sun, 9 May 2021 10:27:28 +0000 (12:27 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sun, 9 May 2021 13:15:43 +0000 (15:15 +0200)
cmd/safcm-remote/sync/files.go
cmd/safcm-remote/sync/files_test.go

index 119a3534239f68e2e5d10aee08ec2559590ada87..3e88be2b6f2ff78ead5af113846fc6cc302c1f0f 100644 (file)
@@ -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("<binary content>\n")
+               oldData = []byte(fmt.Sprintf("<binary content, %d bytes>\n",
+                       len(oldData)))
        }
        if newBin {
-               newData = []byte("<binary content>\n")
+               newData = []byte(fmt.Sprintf("<binary content, %d bytes>\n",
+                       len(newData)))
        }
 
        // TODO: difflib shows empty context lines at the end of the file
index 2e3ed3eb2bca67a994232a3a2d9dc2502d77d982..27011ac96c3e75bdd9f8fd3130e5bcceda887c20 100644 (file)
@@ -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 @@
--<binary content>
+-<binary content, 3 bytes>
 +content
  
 `,
@@ -2355,7 +2355,7 @@ file
                                                },
                                                DataDiff: `@@ -1,2 +1,2 @@
 -content
-+<binary content>
++<binary content, 4 bytes>
  
 `,
                                        },