Function: userlock--check-content-unchanged
userlock--check-content-unchanged is a byte-compiled function defined
in userlock.el.gz.
Signature
(userlock--check-content-unchanged FILENAME)
Source Code
;; Defined in /usr/src/emacs/lisp/userlock.el.gz
(defun userlock--check-content-unchanged (filename)
(with-demoted-errors "Unchanged content check: %S"
;; Even tho we receive `filename', we know that `filename' refers
;; to the current buffer's file.
(cl-assert (or (null buffer-file-truename) ; temporary buffer
(equal (expand-file-name filename)
(expand-file-name buffer-file-truename))))
;; Note: rather than read the file and compare to the buffer, we could save
;; the buffer and compare to the file, but for encrypted data this
;; wouldn't work well (and would risk exposing the data).
(save-restriction
(widen)
(let ((buf (current-buffer))
(cs buffer-file-coding-system)
(start (point-min))
(end (point-max)))
;; FIXME: To avoid a slow `insert-file-contents' on large or
;; remote files, it'd be good to include file size in the
;; "visited-modtime" check.
(when (with-temp-buffer
(let ((coding-system-for-read cs)
(non-essential t))
(insert-file-contents filename))
(when (= (buffer-size) (- end start)) ;Minor optimization.
(= 0 (let ((case-fold-search nil))
(compare-buffer-substrings
buf start end
(current-buffer) (point-min) (point-max))))))
;; We know that some buffer visits FILENAME, because our
;; caller (see lock_file) verified that. Thus, we set the
;; modtime in that buffer, to cater to use case where the
;; file is about to be written to from some buffer that
;; doesn't visit any file, like a temporary buffer.
(let ((buf (get-file-buffer (file-truename filename))))
(when buf ; If we cannot find the visiting buffer, punt.
(with-current-buffer buf
(set-visited-file-modtime))))
'unchanged)))))