~rgrjr/rgr-hacks

6d4ca6f8323306d7954e6364cdbe735ebd6d3851 — Bob Rogers 8 months ago 2c3cbba emacs-29-compat
Fix rgr-check-backup-md5sums "quit early" bug

* rgr-backup-hacks.el:
   + (rgr-check-backup-md5sums):  Bug fix:  Use forward-paragraph to
     skip back before the checksums, and just ignore anything that isn't
     a checksum line.  Since the last change (more than 3 years ago), if
     search for the start ended on other than bobp or a blank line, the
     forward loop would terminate prematurely -- with no problems found.
     Also added a "no checksums" error, so we are not fooled again, and
     a check for odd numbers of checksums (in case a file appears twice
     in each checksum set), plus detailed doc.
1 files changed, 28 insertions(+), 20 deletions(-)

M rgr-backup-hacks.el
M rgr-backup-hacks.el => rgr-backup-hacks.el +28 -20
@@ 9,32 9,40 @@

;;;###AUTOLOAD
(defun rgr-check-backup-md5sums ()
  "With point at the end of md5sum output, make sure all are paired."
  "With point at the end of md5sum output, make sure all are paired.
Checks the md5sum output in the previous paragraph, ignoring
indentation, and reporting individual file names that show up
only under a single checksum.  Normally, one pastes two sets of
checksums together to check that (e.g.) a file copy worked."
  (interactive)
  (let ((files-from-md5 nil)
	(n-errors 0))
	(n-errors 0)
	(end (point)))
    (save-excursion
      ;; Skip backward past blank and checksum lines.
      (while (and (not (bobp))
		  (looking-at "^ *\\($\\|[0-9a-f]\\)"))
	(forward-line -1))
      ;; Move forward past blank lines.
      (while (looking-at "^$")
	(forward-line 1))
      (forward-paragraph -1)
      ;; Scarf checksum-and-file lines.
      (while (looking-at "^ *\\([0-9a-f]+\\)  \\(.*\\)$")
	(let* ((md5sum (match-string-no-properties 1))
	       (file (match-string-no-properties 2))
	       (entry (assoc md5sum files-from-md5)))
	  (unless entry
	    (setq entry (list md5sum))
	    (push entry files-from-md5))
	  (push file (cdr entry)))
      (while (< (point) end)
	(when (looking-at "^ *\\([0-9a-f]+\\)  \\(.*\\)$")
	  (let* ((md5sum (match-string-no-properties 1))
		 (file (match-string-no-properties 2))
		 (entry (assoc md5sum files-from-md5)))
	    (unless entry
	      (setq entry (list md5sum))
	      (push entry files-from-md5))
	    (push file (cdr entry))))
	(forward-line 1))
      (unless files-from-md5
	;; In case the user is in the wrong place, or the regexp isn't hitting
	;; the checksum lines right.
	(error "Found no checksums to compare."))
      ;; Look for odd correspondences.
      (dolist (set files-from-md5)
	(when (null (cddr set))
	  (message "Found singleton %S" (car (cdr set)))
	  (cl-incf n-errors)))
	(cond ((null (cddr set))
	        (message "Found singleton %S" (car (cdr set)))
	        (cl-incf n-errors))
	      ((= 1 (logand 1 (length (cdr set))))
	        (message "Found odd collision for %S" (car set))
	        (cl-incf n-errors))))
      (if (= n-errors 0)
	  (message "No mismatches.")
	  (message "Found %d mismatches, check *Messages* for singletons."