From tom@@@k@liber@ @ending from gm@il@com  Tue Jul  3 10:21:56 2018
From: tom@@@k@liber@ @ending from gm@il@com (Tomas Kalibera)
Date: Tue, 3 Jul 2018 10:21:56 +0200
Subject: [Rd] Bug in file.access on Windows when using network shares
In-Reply-To: <CADWT1NMxqSQ4Mf15cazp4Dnz9i7_GjNKWLo1fjPC_aFPXLRVVQ@mail.gmail.com>
References: <CADWT1NMxqSQ4Mf15cazp4Dnz9i7_GjNKWLo1fjPC_aFPXLRVVQ@mail.gmail.com>
Message-ID: <9119b59d-f679-021b-d35f-a6ea51cde3e2@gmail.com>


Dear Nick,

thank you for your report. In general one cannot know reliably in 
advance whether reading a file will work, if nothing else, there are 
possible race conditions with other applications and/or the system (e.g. 
a service may lock the file, move it away temporarily, etc). The only 
correct way to handle errors is try the read and catch errors. Please 
note there is a disclaimer in ?file.access to this effect.

If you still want to report a bug in file.access, please provide an 
example that does not require a package, and provide more details (what 
do you think would be the correct behavior, etc). From looking at the 
code, when winAccessW/GetFileSecurityW fails to retrieve information 
about the file, file.access would signal an error, which seems to be a 
fine behavior for me. It is not surprising to me that in some cases 
(like working on a local copy of a file in a distributed file-system), 
the OS would not know whether a file is readable/writeable before trying 
out on/syncing the distributed version.

Best
Tomas

On 07/03/2018 01:11 AM, Nick Kennedy wrote:
> Dear R-Devel,
>
> I've run into an issue with a package (vcfR) that uses file.access to check
> a file is readable before opening it. The issue is actually in base R
> though. I've looked into the package code, and it calls file.access(path,
> mode = 4). I've created a minimal working example of the code in winAccessW
> from src/gnuwin32/extra.c, and the problem arises when GetFileSecurityW is
> called on shared files under certain circumstances.
>
> One situation I've seen it in are when a file is shared from a non-Windows
> host (e.g. Linux), which is similar to the situation documented at
> https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f57928d3-d89b-426d-a174-d06d97355afc/how-to-check-if-a-filefolder-is-writable-or-not?forum=windowssdk
> .
>
> The other situation arises when a file is cached offline by Windows Offline
> files feature. The call to GetFileSecurityW works fine when the network is
> up (and so the file is being accessed from the share), but fails when the
> network is down and the file is being accessed from the offline files cache.
>
> Is there any reason that there is a custom function here? Windows supports
> the use of access (as is used on other OSes), although the ISO C++ _waccess
> would be preferred. This seems to work well even in situations where the
> current code does not.
>
> BW
>
> Nick
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Bug in file.access on Windows when using network shares
Tomas Kalibera