Subject: Re: bug#8954: 23.3.50; flymake handles read-only directories badly
From: Stefan Monnier <[email-masked]>
To: Reuben Thomas <[email-masked]>
Cc: [email-masked]
Date: Tue, 10 Apr 2012 20:22:20 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

> If I open a system include file, and have flymake-mode in my
> c-mode-hook, I get:

> Note: file is write protected
> flymake-save-buffer-in-file: Opening output file: permission denied, /usr/include/regex_flymake.h

> and (the actual bug) the buffer displayed is not regex.h

I've installed the patch below which should fix the worst part of
this bug.

        Stefan

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-04-10 23:34:25 +0000
+++ lisp/ChangeLog	2012-04-11 00:20:36 +0000
@@ -1,3 +1,7 @@
+2012-04-11  Stefan Monnier  <[email-masked]>
+
+	* progmodes/flymake.el (flymake-mode): Beware read-only dirs (bug#8954).
+
 2012-04-10  Sébastien Gross  <[email-masked]>  (tiny change)
 
 	* progmodes/hideshow.el (hs-hide-all): Don't infloop on comments

=== modified file 'lisp/progmodes/flymake.el'
--- lisp/progmodes/flymake.el	2012-02-08 02:12:24 +0000
+++ lisp/progmodes/flymake.el	2012-04-10 23:06:08 +0000
@@ -1356,8 +1356,12 @@
       (setq flymake-timer
             (run-at-time nil 1 'flymake-on-timer-event (current-buffer)))
 
-      (when flymake-start-syntax-check-on-find-file
-        (flymake-start-syntax-check)))))
+      (when (and flymake-start-syntax-check-on-find-file
+                 ;; Since we write temp files in current dir, there's no point
+                 ;; trying if the directory is read-only (bug#8954).
+                 (file-writable-p (file-name-directory buffer-file-name)))
+        (with-demoted-errors
+          (flymake-start-syntax-check))))))
 
    ;; Turning the mode OFF.
    (t