New error file-missing

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>
This commit is contained in:
Paul Eggert 2016-10-21 13:04:02 -07:00
parent 76b08a35bb
commit 897998291f
14 changed files with 64 additions and 43 deletions

View 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

View 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

View 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}.

View file

@ -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

View 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)

View 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))

View 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.

View 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.

View 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))

View 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.

View 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)))))
;;;; ------------------------------------------------------------
;;;; 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.

View 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

View 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)))

View 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,