Subject: 26.1; file-locked-p does not respect file-name-coding-system

From: Olli Helenius <[email-masked]>
Date: Sat, 6 Apr 2019 13:17:17 +0300 (EEST)

The ‘file-locked-p’ function does not call ‘ENCODE_FILE’ on its argument
and thus can end up looking for a different file name than that which
was generated by ‘lock-buffer’.  Below is an Elisp expression that
demonstrates the issue.

;; Returns string "file-locked-p buggy" if the result of file-locked-p
;; is `nil' even when the buffer should be locked.
(let ((file-name-coding-system 'latin-1-unix)
      (create-lockfiles t))
  (let ((file (make-temp-file "file-locked-p-éö-" nil ".txt" "test"))
	(result nil))
    (unwind-protect
	(progn
	  (find-file-existing file)
	  (insert "modification")
          (lock-buffer)
	  (if (eq nil (file-locked-p file))
	      (setq result "file-locked-p buggy")
	    (setq result "file-locked-p ok"))
	  (save-buffer)
	  (kill-buffer)
	  result)
      (delete-file file nil))))

See also:
  http://git.savannah.gnu.org/cgit/emacs.git/tree/src/filelock.c?h=emacs-26.1#n680
  http://git.savannah.gnu.org/cgit/emacs.git/tree/src/filelock.c?h=emacs-26.1#n829

In GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.5)
 of 2019-04-05 built on localhost
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Mark set [3 times]
current-kill: Kill ring is empty
Making completion list...

Configured using:
 'configure
 --prefix=/nix/store/1yj0jrwh9yr2h81nl50c88lqn254ylil-emacs-26.1
 --with-modules --with-x-toolkit=gtk3 --with-xft
 CFLAGS=-DMAC_OS_X_VERSION_MAX_ALLOWED=101200'

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND DBUS GSETTINGS NOTIFY LIBSELINUX GNUTLS
LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11
MODULES THREADS LIBSYSTEMD

Important settings:
  value of $EMACSLOADPATH: /nix/store/553k4fjrf5d523zrjvm7jmw6zx23cbmf-emacs-packages-deps/share/emacs/site-lisp:
  value of $LANG: fi_FI.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
/nix/store/553k4fjrf5d523zrjvm7jmw6zx23cbmf-emacs-packages-deps/share/emacs/site-lisp/elpa/treemacs-20181223.519/treemacs-evil hides /nix/store/553k4fjrf5d523zrjvm7jmw6zx23cbmf-emacs-packages-deps/share/emacs/site-lisp/elpa/treemacs-evil-20181227.747/treemacs-evil
/nix/store/553k4fjrf5d523zrjvm7jmw6zx23cbmf-emacs-packages-deps/share/emacs/site-lisp/elpa/treemacs-20181223.519/treemacs-projectile hides /nix/store/553k4fjrf5d523zrjvm7jmw6zx23cbmf-emacs-packages-deps/share/emacs/site-lisp/elpa/treemacs-projectile-20181227.747/treemacs-projectile
/nix/store/553k4fjrf5d523zrjvm7jmw6zx23cbmf-emacs-packages-deps/share/emacs/site-lisp/elpa/seq-2.20/seq hides /nix/store/1yj0jrwh9yr2h81nl50c88lqn254ylil-emacs-26.1/share/emacs/26.1/lisp/emacs-lisp/seq
/nix/store/553k4fjrf5d523zrjvm7jmw6zx23cbmf-emacs-packages-deps/share/emacs/site-lisp/elpa/let-alist-1.0.5/let-alist hides /nix/store/1yj0jrwh9yr2h81nl50c88lqn254ylil-emacs-26.1/share/emacs/26.1/lisp/emacs-lisp/let-alist

Features:
(shadow sort mail-extr emacsbug message rmc puny seq seq-25 byte-opt gv
bytecomp byte-compile cconv cl-loaddefs cl-lib dired dired-loaddefs
format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg
epg-config gnus-util rmail rmail-loaddefs mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils term/xterm xterm
time-date elec-pair mule-util tooltip eldoc electric uniquify ediff-hook
vc-hooks lisp-float-type mwheel term/x-win x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow isearch timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core term/tty-colors frame cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote dbusbind inotify
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 100753 4370)
 (symbols 48 20340 1)
 (miscs 40 41 143)
 (strings 32 28643 993)
 (string-bytes 1 782458)
 (vectors 16 12695)
 (vector-slots 8 452201 6174)
 (floats 8 55 766)
 (intervals 56 276 8)
 (buffers 992 13))