Subject: bug#37202: shadowfile-tests: two failures on macOS

From: Paul Eggert <[email-masked]>
Date: Fri, 20 Sep 2019 12:04:41 -0700

On 9/20/19 5:35 AM, Michael Albinus wrote:
> That means, (file-attributes truename) returns nil although
> (file-exists-p truename) returns non-nil.

I don't see why the recent changes would cause file-attributes to return nil on 
a local file. If file-exists-p succeeds, the file has been confirmed to exist. 
In that case, when file-attributes uses fstatat (or openat+stat) the syscalls 
should either succeed, or should fail with an unusual errno value like 
EOVERFLOW, so file-attributes should either return non-nil or signal an error.

Perhaps the file in question has file handlers that are interposing themselves? 
That might explain the situation.

I should mention that under Emacs 26 file-attributes can return nil here, even 
for a local file: e.g., (file-exists-p F) uses faccessat which succeeds, then 
(file-attributes F) uses fstatat (or openat+fstat) which fails with 
errno==EOVERFLOW because F's timestamp or inode number is out of range for the 
kernel.

Also, of course using two calls suffers from a race if the filesystem changes 
between the calls.

So, regardless of the the recent access changes, it appears that this code in 
tramp-handle-file-modes:

     (when (file-exists-p truename)
       (tramp-mode-string-to-int
        (tramp-compat-file-attribute-modes (file-attributes truename))))

should be rewritten to be something like this:

     (when-let ((attrs (file-attributes truename)))
       (tramp-mode-string-to-int
        (tramp-compat-file-attribute-modes attrs)))