summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2019-09-21 11:27:46 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2019-09-21 11:38:36 -0700
commitd49d6ea9677eea1d30aae4244934b1c7336e35a3 (patch)
treec671f33693f458a7ba992a2a97250f620aec861d /src
parent56213b15e65a350f3f8cd9426a97691d8ff217ee (diff)
downloademacs-d49d6ea9677eea1d30aae4244934b1c7336e35a3.tar.gz
Revert too-picky file-access tests
Problem reported by Andreas Schwab (Bug#37475). * doc/lispref/files.texi (Writing to Files) (Testing Accessibility, Kinds of Files): Document that accessibility and file-type predicates return nil if there is trouble determining accessibility or type. * etc/NEWS: Adjust, and list the affected primitives. * src/callproc.c (init_callproc): Go back to Ffile_exists_p. * src/fileio.c (PICKY_EACCES, file_test_errno): Remove. All uses removed. (Ffile_name_case_insensitive_p, Ffile_exists_p, Ffile_symlink_p) (Ffile_directory_p, Ffile_regular_p): Document that these functions return nil if there is trouble. (Ffile_name_case_insensitive_p, check_file_access) (Ffile_writable_p, Ffile_symlink_p, Ffile_directory_p) (Ffile_accessible_directory_p, Ffile_regular_p) * src/lread.c (Fload): Go back to treating trouble in determining the answer as if the file were missing. * src/fileio.c (Ffile_newer_than_file_p): Use file_attribute_errno not file_test_errno, since returning nil is not appropriate when there are two files to test; e.g., in the rare cases where both file timestamps have overflowed then neither t nor nil is correct.
Diffstat (limited to 'src')
-rw-r--r--src/callproc.c4
-rw-r--r--src/fileio.c108
-rw-r--r--src/lisp.h1
-rw-r--r--src/lread.c14
4 files changed, 32 insertions, 95 deletions
diff --git a/src/callproc.c b/src/callproc.c
index dbbf15c792a..007465cd405 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1567,12 +1567,12 @@ init_callproc (void)
tem = Fexpand_file_name (build_string ("NEWS"), Vdata_directory);
if (!NILP (Fequal (srcdir, Vinvocation_directory))
- || !file_access_p (SSDATA (tem), F_OK))
+ || NILP (Ffile_exists_p (tem)))
{
Lisp_Object newdir;
newdir = Fexpand_file_name (build_string ("../etc/"), lispdir);
tem = Fexpand_file_name (build_string ("NEWS"), newdir);
- if (file_access_p (SSDATA (tem), F_OK))
+ if (!NILP (Ffile_exists_p (tem)))
Vdata_directory = newdir;
}
}
diff --git a/src/fileio.c b/src/fileio.c
index b2896c1fe1e..b510d48dbaa 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -253,30 +253,6 @@ file_attribute_errno (Lisp_Object file, int err)
return file_metadata_errno ("Getting attributes", file, err);
}
-/* In theory, EACCES errors for predicates like file-readable-p should
- be checked further because they may be problems with an ancestor
- directory instead of with the file itself, which means that we
- don't have reliable info about the requested file. In practice,
- though, DOS_NT platforms set errno to EACCES for missing files like
- "/var/mail", so signaling EACCES errors would be a mistake there.
- So return nil for EACCES unless PICKY_EACCES, which is false by
- default on DOS_NT. */
-#ifndef PICKY_EACCES
-# ifdef DOS_NT
-enum { PICKY_EACCES = false };
-# else
-enum { PICKY_EACCES = true };
-# endif
-#endif
-
-Lisp_Object
-file_test_errno (Lisp_Object file, int err)
-{
- if (!PICKY_EACCES && err == EACCES)
- return Qnil;
- return file_metadata_errno ("Testing file", file, err);
-}
-
void
close_file_unwind (int fd)
{
@@ -2453,7 +2429,9 @@ file_name_case_insensitive_err (Lisp_Object file)
DEFUN ("file-name-case-insensitive-p", Ffile_name_case_insensitive_p,
Sfile_name_case_insensitive_p, 1, 1, 0,
doc: /* Return t if file FILENAME is on a case-insensitive filesystem.
-The arg must be a string. */)
+Return nil if FILENAME does not exist or is not on a case-insensitive
+filesystem, or if there was trouble determining whether the filesystem
+is case-insensitive. */)
(Lisp_Object filename)
{
Lisp_Object handler;
@@ -2467,19 +2445,16 @@ The arg must be a string. */)
if (!NILP (handler))
return call2 (handler, Qfile_name_case_insensitive_p, filename);
- /* If the file doesn't exist, move up the filesystem tree until we
- reach an existing directory or the root. */
+ /* If the file doesn't exist or there is trouble checking its
+ filesystem, move up the filesystem tree until we reach an
+ existing, trouble-free directory or the root. */
while (true)
{
int err = file_name_case_insensitive_err (filename);
- switch (err)
- {
- case -1: return Qt;
- default: return file_test_errno (filename, err);
- case ENOENT: case ENOTDIR: break;
- }
+ if (err <= 0)
+ return err < 0 ? Qt : Qnil;
Lisp_Object parent = file_name_directory (filename);
- /* Avoid infinite loop if the root is reported as non-existing
+ /* Avoid infinite loop if the root has trouble
(impossible?). */
if (!NILP (Fstring_equal (parent, filename)))
return Qnil;
@@ -2739,8 +2714,7 @@ file_name_absolute_p (char const *filename)
}
/* Return t if FILE exists and is accessible via OPERATION and AMODE,
- nil (setting errno) if not. Signal an error if the result cannot
- be determined. */
+ nil (setting errno) if not. */
static Lisp_Object
check_file_access (Lisp_Object file, Lisp_Object operation, int amode)
@@ -2758,22 +2732,13 @@ check_file_access (Lisp_Object file, Lisp_Object operation, int amode)
}
char *encoded_file = SSDATA (ENCODE_FILE (file));
- bool ok = file_access_p (encoded_file, amode);
- if (ok)
- return Qt;
- int err = errno;
- if (err == EROFS || err == ETXTBSY
- || (PICKY_EACCES && err == EACCES && amode != F_OK
- && file_access_p (encoded_file, F_OK)))
- {
- errno = err;
- return Qnil;
- }
- return file_test_errno (file, err);
+ return file_access_p (encoded_file, amode) ? Qt : Qnil;
}
DEFUN ("file-exists-p", Ffile_exists_p, Sfile_exists_p, 1, 1, 0,
doc: /* Return t if file FILENAME exists (whether or not you can read it).
+Return nil if FILENAME does not exist, or if there was trouble
+determining whether the file exists.
See also `file-readable-p' and `file-attributes'.
This returns nil for a symlink to a nonexistent file.
Use `file-symlink-p' to test for such links. */)
@@ -2834,16 +2799,7 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0,
should check ACLs though, which do affect this. */
return file_directory_p (encoded) ? Qt : Qnil;
#else
- if (file_access_p (SSDATA (encoded), W_OK | X_OK))
- return Qt;
- int err = errno;
- if (err == EROFS
- || (err == EACCES && file_access_p (SSDATA (encoded), F_OK)))
- {
- errno = err;
- return Qnil;
- }
- return file_test_errno (absname, err);
+ return file_access_p (SSDATA (encoded), W_OK | X_OK) ? Qt : Qnil;
#endif
}
@@ -2919,7 +2875,8 @@ check_emacs_readlinkat (int fd, Lisp_Object file, char const *encoded_file)
DEFUN ("file-symlink-p", Ffile_symlink_p, Sfile_symlink_p, 1, 1, 0,
doc: /* Return non-nil if file FILENAME is the name of a symbolic link.
The value is the link target, as a string.
-Otherwise it returns nil.
+Return nil if FILENAME does not exist or is not a symbolic link,
+of there was trouble determining whether the file is a symbolic link.
This function does not check whether the link target exists. */)
(Lisp_Object filename)
@@ -2935,12 +2892,13 @@ This function does not check whether the link target exists. */)
if (!NILP (handler))
return call2 (handler, Qfile_symlink_p, filename);
- return check_emacs_readlinkat (AT_FDCWD, filename,
- SSDATA (ENCODE_FILE (filename)));
+ return emacs_readlinkat (AT_FDCWD, SSDATA (ENCODE_FILE (filename)));
}
DEFUN ("file-directory-p", Ffile_directory_p, Sfile_directory_p, 1, 1, 0,
doc: /* Return t if FILENAME names an existing directory.
+Return nil if FILENAME does not name a directory, or if there
+was trouble determining whether FILENAME is a directory.
Symbolic links to directories count as directories.
See `file-symlink-p' to distinguish symlinks. */)
(Lisp_Object filename)
@@ -2953,9 +2911,7 @@ See `file-symlink-p' to distinguish symlinks. */)
if (!NILP (handler))
return call2 (handler, Qfile_directory_p, absname);
- if (file_directory_p (absname))
- return Qt;
- return file_test_errno (absname, errno);
+ return file_directory_p (absname) ? Qt : Qnil;
}
/* Return true if FILE is a directory or a symlink to a directory.
@@ -3040,12 +2996,7 @@ really is a readable and searchable directory. */)
}
Lisp_Object encoded_absname = ENCODE_FILE (absname);
- if (file_accessible_directory_p (encoded_absname))
- return Qt;
- int err = errno;
- if (err == EACCES && file_access_p (SSDATA (encoded_absname), F_OK))
- return Qnil;
- return file_test_errno (absname, err);
+ return file_accessible_directory_p (encoded_absname) ? Qt : Qnil;
}
/* If FILE is a searchable directory or a symlink to a
@@ -3108,6 +3059,8 @@ file_accessible_directory_p (Lisp_Object file)
DEFUN ("file-regular-p", Ffile_regular_p, Sfile_regular_p, 1, 1, 0,
doc: /* Return t if FILENAME names a regular file.
This is the sort of file that holds an ordinary stream of data bytes.
+Return nil if FILENAME does not exist or is not a regular file,
+or there was trouble determining whether FILENAME is a regular file.
Symbolic links to regular files count as regular files.
See `file-symlink-p' to distinguish symlinks. */)
(Lisp_Object filename)
@@ -3133,9 +3086,7 @@ See `file-symlink-p' to distinguish symlinks. */)
Vw32_get_true_file_attributes = true_attributes;
#endif
- if (stat_result == 0)
- return S_ISREG (st.st_mode) ? Qt : Qnil;
- return file_test_errno (absname, errno);
+ return stat_result == 0 && S_ISREG (st.st_mode) ? Qt : Qnil;
}
DEFUN ("file-selinux-context", Ffile_selinux_context,
@@ -3541,20 +3492,15 @@ otherwise, if FILE2 does not exist, the answer is t. */)
{
err1 = errno;
if (err1 != EOVERFLOW)
- return file_test_errno (absname1, err1);
+ return file_attribute_errno (absname1, err1);
}
-
if (stat (SSDATA (ENCODE_FILE (absname2)), &st2) != 0)
{
- file_test_errno (absname2, errno);
+ file_attribute_errno (absname2, errno);
return Qt;
}
-
if (err1)
- {
- file_test_errno (absname1, err1);
- eassume (false);
- }
+ file_attribute_errno (absname1, err1);
return (timespec_cmp (get_stat_mtime (&st2), get_stat_mtime (&st1)) < 0
? Qt : Qnil);
diff --git a/src/lisp.h b/src/lisp.h
index b081ae1cee8..e68d2732e21 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4315,7 +4315,6 @@ extern AVOID report_file_errno (const char *, Lisp_Object, int);
extern AVOID report_file_error (const char *, Lisp_Object);
extern AVOID report_file_notify_error (const char *, Lisp_Object);
extern Lisp_Object file_attribute_errno (Lisp_Object, int);
-extern Lisp_Object file_test_errno (Lisp_Object, int);
extern bool internal_delete_file (Lisp_Object);
extern Lisp_Object check_emacs_readlinkat (int, Lisp_Object, char const *);
extern bool file_directory_p (Lisp_Object);
diff --git a/src/lread.c b/src/lread.c
index 4f3446b09db..151731a81d9 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1343,26 +1343,18 @@ Return t if the file exists and loads successfully. */)
/* openp already checked for newness, no point doing it again.
FIXME would be nice to get a message when openp
ignores suffix order due to load_prefer_newer. */
- Lisp_Object notfound = found;
if (!load_prefer_newer && is_elc)
{
result = stat (SSDATA (efound), &s1);
- int err = errno;
if (result == 0)
{
SSET (efound, SBYTES (efound) - 1, 0);
result = stat (SSDATA (efound), &s2);
- err = errno;
SSET (efound, SBYTES (efound) - 1, 'c');
- if (result != 0)
- notfound = Fsubstring (found, make_fixnum (0),
- make_fixnum (-1));
}
- if (result != 0)
- file_test_errno (notfound, err);
- else if (timespec_cmp (get_stat_mtime (&s1),
- get_stat_mtime (&s2))
- < 0)
+
+ if (result == 0
+ && timespec_cmp (get_stat_mtime (&s1), get_stat_mtime (&s2)) < 0)
{
/* Make the progress messages mention that source is newer. */
newer = 1;