diff options
author | Eli Zaretskii <eliz@gnu.org> | 2021-12-19 17:29:40 +0200 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2021-12-19 17:29:40 +0200 |
commit | cc63704815ee4ae686a0cf86e12f7f2596dd22a3 (patch) | |
tree | f0d6215f0f35bf3538ec3601e49bc54f0d91f0fa | |
parent | 8f82a83caec9ad48a6d4abc4dc26bed67f0e89e3 (diff) | |
download | emacs-cc63704815ee4ae686a0cf86e12f7f2596dd22a3.tar.gz |
New error symbol 'permission-denied'
* src/fileio.c (syms_of_fileio) <permission-denied>: Define the
symbol and its 'err-conditions' and 'error-message' properties.
(get_file_errno_data): Return permission-denied on EACCES.
* test/src/filelock-tests.el (filelock-tests-file-locked-p-spoiled)
(filelock-tests-unlock-spoiled)
(filelock-tests-kill-buffer-spoiled): Adapt the tests to the new
error symbol.
* doc/lispref/errors.texi (Standard Errors):
* etc/NEWS: Document 'permission-denied' error.
-rw-r--r-- | doc/lispref/errors.texi | 4 | ||||
-rw-r--r-- | etc/NEWS | 6 | ||||
-rw-r--r-- | src/fileio.c | 12 | ||||
-rw-r--r-- | test/src/filelock-tests.el | 6 |
4 files changed, 24 insertions, 4 deletions
diff --git a/doc/lispref/errors.texi b/doc/lispref/errors.texi index f848218e267..9dd052c5235 100644 --- a/doc/lispref/errors.texi +++ b/doc/lispref/errors.texi @@ -98,6 +98,10 @@ Lisp reader, not to file I/O@. @xref{Input Functions}. @item file-already-exists This is a subcategory of @code{file-error}. @xref{Writing to Files}. +@item permission-denied +This is a subcategory of @code{file-error}, which occurs when the OS +doesn't allow Emacs to access a file or a directory for some reason. + @item file-date-error This is a subcategory of @code{file-error}. It occurs when @code{copy-file} tries and fails to set the last-modification time of @@ -1186,6 +1186,12 @@ The events 'touchscreen-begin, 'touchscreen-update', and 'touchscreen-end' have been added to take better advantage of touch-capable display panels. ++++ +** New error symbol 'permission-denied'. +This is a subcategory of 'file-error', and is signaled when some file +operation fails because the OS doesn't allow Emacs to access a file or +a directory. + * Changes in Emacs 29.1 on Non-Free Operating Systems diff --git a/src/fileio.c b/src/fileio.c index a0563ccba4b..f802e4e4184 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -195,7 +195,11 @@ get_file_errno_data (char const *string, Lisp_Object name, int errorno) if (errorno == EEXIST) return Fcons (Qfile_already_exists, errdata); else - return Fcons (errorno == ENOENT ? Qfile_missing : Qfile_error, + return Fcons (errorno == ENOENT + ? Qfile_missing + : (errorno == EACCES + ? Qpermission_denied + : Qfile_error), Fcons (build_string (string), errdata)); } @@ -6380,6 +6384,7 @@ syms_of_fileio (void) DEFSYM (Qfile_already_exists, "file-already-exists"); DEFSYM (Qfile_date_error, "file-date-error"); DEFSYM (Qfile_missing, "file-missing"); + DEFSYM (Qpermission_denied, "permission-denied"); DEFSYM (Qfile_notify_error, "file-notify-error"); DEFSYM (Qremote_file_error, "remote-file-error"); DEFSYM (Qexcl, "excl"); @@ -6438,6 +6443,11 @@ behaves as if file names were encoded in `utf-8'. */); Fput (Qfile_missing, Qerror_message, build_pure_c_string ("File is missing")); + Fput (Qpermission_denied, Qerror_conditions, + Fpurecopy (list3 (Qpermission_denied, Qfile_error, Qerror))); + Fput (Qpermission_denied, Qerror_message, + build_pure_c_string ("Cannot access file or directory")); + Fput (Qfile_notify_error, Qerror_conditions, Fpurecopy (list3 (Qfile_notify_error, Qfile_error, Qerror))); Fput (Qfile_notify_error, Qerror_message, diff --git a/test/src/filelock-tests.el b/test/src/filelock-tests.el index ba001679639..2d682e2e789 100644 --- a/test/src/filelock-tests.el +++ b/test/src/filelock-tests.el @@ -123,7 +123,7 @@ the case)." (filelock-tests--spoil-lock-file buffer-file-truename) (let ((err (should-error (file-locked-p (buffer-file-name))))) (should (equal (seq-subseq err 0 2) - '(file-error "Testing file lock"))))))) + '(permission-denied "Testing file lock"))))))) (ert-deftest filelock-tests-unlock-spoiled () "Check that `unlock-buffer' fails if the lockfile is \"spoiled\"." @@ -144,7 +144,7 @@ the case)." (lambda (err) (push err errors)))) (unlock-buffer)) (should (consp errors)) - (should (equal '(file-error "Unlocking file") + (should (equal '(permission-denied "Unlocking file") (seq-subseq (car errors) 0 2))) (should (equal (length errors) 1)))))) @@ -174,7 +174,7 @@ the case)." (lambda (err) (push err errors)))) (kill-buffer)) (should (consp errors)) - (should (equal '(file-error "Unlocking file") + (should (equal '(permission-denied "Unlocking file") (seq-subseq (car errors) 0 2))) (should (equal (length errors) 1)))))) |