]> git.eshelyaron.com Git - emacs.git/commitdiff
New error file-missing
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 21 Oct 2016 20:04:02 +0000 (13:04 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 21 Oct 2016 20:06:03 +0000 (13:06 -0700)
This fixes a recently-introduced bug in delete-directory,
where the code assumes the C locale when determining
whether a file-error corresponds to a missing file (Bug#24714).
* doc/lispref/errors.texi (Standard Errors):
* doc/lispref/files.texi (Changing Files):
* etc/NEWS:
Document this.
* doc/lispref/loading.texi (How Programs Do Loading):
Say "a file-error" rather than "the error file-error" since
it might be a file-missing now.
* lisp/emacs-lisp/bytecomp.el (byte-compile-file):
* lisp/epa-file.el (epa-file--find-file-not-found-function):
(epa-file-insert-file-contents, epa-file-write-region):
* lisp/ffap.el (find-file-at-point, dired-at-point):
* lisp/jka-compr.el (jka-compr-insert-file-contents)
(jka-compr-insert-file-contents):
* lisp/net/ange-ftp.el (ange-ftp-barf-if-not-directory)
(ange-ftp-insert-file-contents, ange-ftp-copy-file-internal):
* lisp/progmodes/etags.el (visit-tags-table):
* lisp/url/url-handlers.el (url-copy-file):
* src/fileio.c (report_file_errno):
Signal file-missing if appropriate.
* lisp/epa-file.el (epa-file-insert-file-contents):
* lisp/jka-compr.el (jka-compr-insert-file-contents):
Don't assume file-error is a leaf in the error hierarchy.
* lisp/files.el (files--force):
* lisp/gnus/nnmaildir.el (nnmaildir--enoent-p):
* lisp/jka-compr.el (jka-compr-insert-file-contents):
Use file-missing to detect whether the file is missing.
* lisp/url/url-handlers.el (url-copy-file):
Signal file-already-exists if appropriate.
* src/fileio.c (syms_of_fileio): Define file-missing.

2016-10-18  Paul Eggert  <eggert@cs.ucla.edu>

14 files changed:
doc/lispref/errors.texi
doc/lispref/files.texi
doc/lispref/loading.texi
etc/NEWS
lisp/emacs-lisp/bytecomp.el
lisp/epa-file.el
lisp/ffap.el
lisp/files.el
lisp/gnus/nnmaildir.el
lisp/jka-compr.el
lisp/net/ange-ftp.el
lisp/progmodes/etags.el
lisp/url/url-handlers.el
src/fileio.c

index 03aea4ef44518a227629f25ab12c30675116b1c6..4a0e38c782f048a5ac2f6095235c96b3688fbb8f 100644 (file)
@@ -107,6 +107,11 @@ the error-strings are not very relevant.  However, these error symbols
 do have @code{error-message} properties, and if no data is provided,
 the @code{error-message} property @emph{is} used.  @xref{Files}.
 
+@item file-missing
+This is a subcategory of @code{file-error}.  It occurs when an
+operation attempts to act on a file that is missing.  @xref{Changing
+Files}.
+
 @c jka-compr.el
 @item compression-error
 This is a subcategory of @code{file-error}, which results from
index 62e0199f1ff091e492c1a5e15a15f50777e4457f..ecc3e03967cda71ceade1773d21257c50e1f67e7 100644 (file)
@@ -1501,10 +1501,11 @@ in @code{exec-path}, and tries all the file-name extensions in
 @cindex setting modes of files
 
   The functions in this section rename, copy, delete, link, and set
-the modes (permissions) of files.  They all signal a @code{file-error}
-error if they fail to perform their function, reporting the
-system-dependent error message that describes the reason for the
-failure.
+the modes (permissions) of files.  Typically, they signal a
+@code{file-error} error if they fail to perform their function,
+reporting the system-dependent error message that describes the reason
+for the failure.  If they fail because a file is missing, they signal
+a @code{file-missing} error instead.
 
   For performance, the operating system may cache or alias changes
 made by these functions instead of writing them immediately to
index 81a1922d71c7b4785c3630d3131e5b9d1df04473..a73ae596e0da05126a6d282e329f997c816fe86d 100644 (file)
@@ -161,8 +161,8 @@ load was done for the sake of @code{autoload}, any function definitions
 made during the loading are undone.
 
 @kindex file-error
-If @code{load} can't find the file to load, then normally it signals the
-error @code{file-error} (with @samp{Cannot open load file
+If @code{load} can't find the file to load, then normally it signals a
+@code{file-error} (with @samp{Cannot open load file
 @var{filename}}).  But if @var{missing-ok} is non-@code{nil}, then
 @code{load} just returns @code{nil}.
 
index 4e41dbb39a84500cbde3fb8bed79fe7d50ecf2c6..d9973c0fd486126ec6075c9c60a0031c7f94ddda 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -624,6 +624,11 @@ collection).
 ** The new functions 'make-nearby-temp-file' and 'temporary-file-directory'
 can be used for creation of temporary files of remote or mounted directories.
 
++++
+** The new error 'file-missing', a subcategory of 'file-error', is now
+signaled instead of 'file-error' if a file operation acts on a file
+that does not exist.
+
 +++
 ** The function 'delete-directory' no longer signals an error when
 operating recursively and when some other process deletes the directory
index c34ec5cae0df109a42bb637bd587c7e9048a2602..428e21c7a393a1b9dddfa897f0e78a0fa10cddcc 100644 (file)
@@ -1892,12 +1892,13 @@ The value is non-nil if there were no errors, nil if errors."
                (rename-file tempfile target-file t)
                (or noninteractive (message "Wrote %s" target-file)))
            ;; This is just to give a better error message than write-region
-           (signal 'file-error
-                   (list "Opening output file"
-                         (if (file-exists-p target-file)
-                             "Cannot overwrite file"
-                           "Directory not writable or nonexistent")
-                         target-file)))
+           (let ((exists (file-exists-p target-file)))
+             (signal (if exists 'file-error 'file-missing)
+                     (list "Opening output file"
+                           (if exists
+                               "Cannot overwrite file"
+                             "Directory not writable or nonexistent")
+                           target-file))))
          (kill-buffer (current-buffer)))
        (if (and byte-compile-generate-call-tree
                 (or (eq t byte-compile-generate-call-tree)
index ee502ef64a3262fc6dc15b9243cb4545672e6ffb..2303a085909e24e30741d04f93125e138396048b 100644 (file)
@@ -120,7 +120,7 @@ encryption is used."
   (let ((error epa-file-error))
     (save-window-excursion
       (kill-buffer))
-    (signal 'file-error
+    (signal (car error)
            (cons "Opening input file" (cdr error)))))
 
 (defvar last-coding-system-used)
@@ -161,7 +161,7 @@ encryption is used."
             ;; signal that as a non-file error
             ;; so that find-file-noselect-1 won't handle it.
             ;; Borrowed from jka-compr.el.
-            (if (and (eq (car error) 'file-error)
+            (if (and (memq 'file-error (get (car error) 'error-conditions))
                      (equal (cadr error) "Searching for program"))
                 (error "Decryption program `%s' not found"
                        (nth 3 error)))
@@ -175,7 +175,7 @@ encryption is used."
                         'epa-file--find-file-not-found-function
                         nil t)
               (epa-display-error context))
-            (signal 'file-error
+            (signal (car error)
                     (cons "Opening input file" (cdr error)))))
           (set-buffer buf) ;In case timer/filter changed/killed it (bug#16029)!
          (setq-local epa-file-encrypt-to
@@ -272,7 +272,7 @@ If no one is selected, symmetric encryption will be performed.  "
        (epa-display-error context)
        (if (setq entry (assoc file epa-file-passphrase-alist))
           (setcdr entry nil))
-       (signal 'file-error (cons "Opening output file" (cdr error)))))
+       (signal (car error) (cons "Opening output file" (cdr error)))))
     (epa-file-run-real-handler
      #'write-region
      (list string nil file append visit lockname mustbenew))
index 7013e6e8ba4e106e7e0058207a02710d48314087..3d7cebadcf66beb5ea13b40808b56af591a20102 100644 (file)
@@ -1510,9 +1510,9 @@ and the functions `ffap-file-at-point' and `ffap-url-at-point'."
                 ;; expand-file-name fixes "~/~/.emacs" bug sent by CHUCKR.
                 (expand-file-name filename)))
        ;; User does not want to find a non-existent file:
-       ((signal 'file-error (list "Opening file buffer"
-                                 "No such file or directory"
-                                 filename)))))))
+       ((signal 'file-missing (list "Opening file buffer"
+                                   "No such file or directory"
+                                   filename)))))))
 
 ;; Shortcut: allow {M-x ffap} rather than {M-x find-file-at-point}.
 ;;;###autoload
@@ -1888,7 +1888,10 @@ If `dired-at-point-require-prefix' is set, the prefix meaning is reversed."
             (y-or-n-p "Directory does not exist, create it? "))
        (make-directory filename)
        (funcall ffap-directory-finder filename))
-       ((error "No such file or directory `%s'" filename))))))
+       (t
+       (signal 'file-missing (list "Opening directory"
+                                   "No such file or directory"
+                                   filename)))))))
 
 (defun dired-at-point-prompter (&optional guess)
   ;; Does guess and prompt step for find-file-at-point.
index 12c6c14d53424897bd59fb98a7e82b3445562ee2..8277877dee089fea923ccdc651fa5f8ce6b176ab 100644 (file)
@@ -5342,9 +5342,7 @@ This acts like (apply FN ARGS) except it returns NO-SUCH if it is
 non-nil and if FN fails due to a missing file or directory."
   (condition-case err
       (apply fn args)
-    (file-error
-     (or (pcase err (`(,_ ,_ "No such file or directory" . ,_) no-such))
-        (signal (car err) (cdr err))))))
+    (file-missing (or no-such (signal (car err) (cdr err))))))
 
 (defun delete-directory (directory &optional recursive trash)
   "Delete the directory named DIRECTORY.  Does not follow symlinks.
index 21c83751e708039e18437abd30f46d1936f5c3b1..03cb445675ce80ca6a33fc2a7c34a9088329e64b 100644 (file)
@@ -371,8 +371,7 @@ This variable is set by `nnmaildir-request-article'.")
        (string= (downcase (caddr err)) "too many links")))
 
 (defun nnmaildir--enoent-p (err)
-  (and (eq (car err) 'file-error)
-       (string= (downcase (caddr err)) "no such file or directory")))
+  (eq (car err) 'file-missing))
 
 (defun nnmaildir--eexist-p (err)
   (eq (car err) 'file-already-exists))
index a5556743eb341adfbcaeaed1ff77b11a49c03e0f..d8137b1052865c6af36ed53decf1f10b3c195bf8 100644 (file)
@@ -444,17 +444,18 @@ There should be no more than seven characters after the final `/'."
                  ;; If the file we wanted to uncompress does not exist,
                  ;; handle that according to VISIT as `insert-file-contents'
                  ;; would, maybe signaling the same error it normally would.
-                 (if (and (eq (car error-code) 'file-error)
+                 (if (and (eq (car error-code) 'file-missing)
                           (eq (nth 3 error-code) local-file))
                      (if visit
                          (setq notfound error-code)
-                       (signal 'file-error
+                       (signal 'file-missing
                                (cons "Opening input file"
                                      (nthcdr 2 error-code))))
                    ;; If the uncompression program can't be found,
                    ;; signal that as a non-file error
                    ;; so that find-file-noselect-1 won't handle it.
-                   (if (and (eq (car error-code) 'file-error)
+                   (if (and (memq 'file-error (get (car error-code)
+                                                   'error-conditions))
                             (equal (cadr error-code) "Searching for program"))
                        (error "Uncompression program `%s' not found"
                               (nth 3 error-code)))
@@ -487,7 +488,7 @@ There should be no more than seven characters after the final `/'."
         (and
          visit
          notfound
-         (signal 'file-error
+         (signal 'file-missing
                  (cons "Opening input file" (nth 2 notfound))))
 
         ;; This is done in insert-file-contents after we return.
index d5c03e3f4ae00b75f85f43e729257b8e45abeb9f..9ff9997e7285aea34e2b53b0c65b445f303cb970 100644 (file)
@@ -1533,12 +1533,11 @@ then kill the related FTP process."
 
 (defun ange-ftp-barf-if-not-directory (directory)
   (or (file-directory-p directory)
-      (signal 'file-error
-             (list "Opening directory"
-                   (if (file-exists-p directory)
-                       "Not a directory"
-                     "No such file or directory")
-                   directory))))
+      (let ((exists (file-exists-p directory)))
+       (signal (if exists 'file-error 'file-missing)
+               (list "Opening directory"
+                     (if exists "Not a directory" "No such file or directory")
+                     directory)))))
 \f
 ;;;; ------------------------------------------------------------
 ;;;; FTP process filter support.
@@ -3352,9 +3351,10 @@ system TYPE.")
                      (setq buffer-file-name filename)))
                (setq last-coding-system-used coding-system-used)
                (list filename size))
-           (signal 'file-error
+           (signal 'file-missing
                    (list
                     "Opening input file"
+                    "No such file or directory"
                     filename))))
       (ange-ftp-real-insert-file-contents filename visit beg end replace))))
 
@@ -3663,7 +3663,7 @@ so return the size on the remote host exactly. See RFC 3659."
        newname (expand-file-name newname))
 
   (or (file-exists-p filename)
-      (signal 'file-error
+      (signal 'file-missing
              (list "Copy file" "No such file or directory" filename)))
 
   ;; canonicalize newname if a directory.
index d37ab8a98171480435b0b0539fa23a044a8bec9e..7d4521c148d1cfeec9a398108d861c3b6f25b375 100644 (file)
@@ -307,9 +307,9 @@ file the tag was in."
   (let ((tags-file-name file))
     (save-excursion
       (or (visit-tags-table-buffer file)
-         (signal 'file-error (list "Visiting tags table"
-                                   "No such file or directory"
-                                   file)))
+         (signal 'file-missing (list "Visiting tags table"
+                                     "No such file or directory"
+                                     file)))
       ;; Set FILE to the expanded name.
       (setq file tags-file-name)))
   (if local
index d3be880b3822c5ef83228f8f360e8aead20a382b..0fada8d49d7301a9f584f276a6a8dc60a28616d9 100644 (file)
@@ -262,11 +262,12 @@ Fifth arg PRESERVE-UID-GID is ignored.
 A prefix arg makes KEEP-TIME non-nil."
   (if (and (file-exists-p newname)
           (not ok-if-already-exists))
-      (error "Opening output file: File already exists, %s" newname))
+      (signal 'file-already-exists (list "File exists" newname)))
   (let ((buffer (url-retrieve-synchronously url))
        (handle nil))
     (if (not buffer)
-       (error "Opening input file: No such file or directory, %s" url))
+        (signal 'file-missing (list "Opening URL" "No such file or directory"
+                                    url)))
     (with-current-buffer buffer
       (setq handle (mm-dissect-buffer t)))
     (let ((mm-attachment-file-modes (default-file-modes)))
index 6026d8ebad407fab281551fed4fe12a1b41f9fa2..ea6e4aef9be5abfc1f5d92890c31324fccf7e83a 100644 (file)
@@ -203,7 +203,8 @@ report_file_errno (char const *string, Lisp_Object name, int errorno)
   if (errorno == EEXIST)
     xsignal (Qfile_already_exists, errdata);
   else
-    xsignal (Qfile_error, Fcons (build_string (string), errdata));
+    xsignal (errorno == ENOENT ? Qfile_missing : Qfile_error,
+            Fcons (build_string (string), errdata));
 }
 
 /* Signal a file-access failure that set errno.  STRING describes the
@@ -5874,6 +5875,7 @@ syms_of_fileio (void)
   DEFSYM (Qfile_error, "file-error");
   DEFSYM (Qfile_already_exists, "file-already-exists");
   DEFSYM (Qfile_date_error, "file-date-error");
+  DEFSYM (Qfile_missing, "file-missing");
   DEFSYM (Qfile_notify_error, "file-notify-error");
   DEFSYM (Qexcl, "excl");
 
@@ -5926,6 +5928,11 @@ behaves as if file names were encoded in `utf-8'.  */);
   Fput (Qfile_date_error, Qerror_message,
        build_pure_c_string ("Cannot set file date"));
 
+  Fput (Qfile_missing, Qerror_conditions,
+       Fpurecopy (list3 (Qfile_missing, Qfile_error, Qerror)));
+  Fput (Qfile_missing, Qerror_message,
+       build_pure_c_string ("File is missing"));
+
   Fput (Qfile_notify_error, Qerror_conditions,
        Fpurecopy (list3 (Qfile_notify_error, Qfile_error, Qerror)));
   Fput (Qfile_notify_error, Qerror_message,