changeset 76629:50806525e635

(basic-save-buffer): Do not set visited filename when the corresponding directory does not exist or the specified filename is that of an existing directory.
author Martin Rudalics <rudalics@gmx.at>
date Tue, 20 Mar 2007 09:35:42 +0000
parents 04b7ffb4f622
children 6823b593cd75
files lisp/files.el
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Tue Mar 20 08:51:41 2007 +0000
+++ b/lisp/files.el	Tue Mar 20 09:35:42 2007 +0000
@@ -3595,10 +3595,21 @@
 	      (let ((filename
 		     (expand-file-name
 		      (read-file-name "File to save in: ") nil)))
-		(and (file-exists-p filename)
-		     (or (y-or-n-p (format "File `%s' exists; overwrite? "
-					   filename))
-			 (error "Canceled")))
+		(if (file-exists-p filename)
+		    (if (file-directory-p filename)
+			;; Signal an error if the user specified the name of an
+			;; existing directory.
+			(error "%s is a directory" filename)
+		      (unless (y-or-n-p (format "File `%s' exists; overwrite? "
+						filename))
+			(error "Canceled")))
+		  ;; Signal an error if the specified name refers to a
+		  ;; non-existing directory.
+		  (let ((dir (file-name-directory filename)))
+		    (unless (file-directory-p dir)
+		      (if (file-exists-p dir)
+			  (error "%s is not a directory" dir)
+			(error "%s: no such directory" dir)))))
 		(set-visited-file-name filename)))
 	  (or (verify-visited-file-modtime (current-buffer))
 	      (not (file-exists-p buffer-file-name))