Re: [Rd] Bug in file.access on Windows when using network shares

2018-10-24 Thread Tomas Kalibera
Dear Nick,

I've updated the implementation of file.access() on Windows to fall back 
to _waccess() when the security descriptor is not available. It now 
works on my system with files selected for offline use even when the 
underlying samba share (on a non-Windows host) becomes unavailable. As I 
wrote earlier, checking access permissions using file.access() before 
actually trying to access the file is subject to a race condition and 
should be avoided. On Windows, in addition, the behavior is complicated, 
not fully documented, and particularly with remote shares, offline 
files, and possibly read-only mounts it is unlikely that file.access() 
will always match the real permission check one gets then trying to 
access the file. One should instead just try to access the file and be 
prepared to handle errors.

R's implementation of file.access() for Windows does not just call 
_waccess(), because _waccess() does not take ACLs into account. This is 
a known and documented limitation of Windows API, and hence as fix for 
PR#7234 R uses GetFileSecurity/CheckAccess instead.

Best
Tomas

On 7/3/18 11:08 PM, Nick Kennedy wrote:
> Dear Tomas,
>
> Thanks for your email. This can be easily reproduced if there is 
> access to a shared folder. I've reproduced this behaviour on both 
> Windows 7 and Windows 10.
>
> Steps to reproduce:
>
> 1. Ensure Offline Files is turned on within Windows
> 2. Using Windows Explorer, browse to a folder shared on a network 
> using a UNC path, e.g. \\mypc\myshare\
> 3. Create a test file, e.g. test.txt
> 4. Within R, try the following:
>
> file.access("//mypc/myshare/test.txt",0)
> # Returns 0
> file.access("//mypc/myshare/test.txt",4)
> # Returns -1 if the share is on a non-Windows host, 0 if it is on a 
> Windows host
>
> 5. Right click on the file within Windows Explorer and ensure 'always 
> available offline' is checked.
> 6. Wait for the sync to take place.
> 7. Disconnect from the network.
> 8. Within R, try the same commands again
>
> file.access("//mypc/myshare/test.txt",0)
> # Returns 0
> file.access("//mypc/myshare/test.txt",4)
> # Returns -1 regardless of whether the original host was Windows or 
> non-Windows
>
> In all cases the file is actually readable.
>
> I've created my own version of winAccessW in extra.c at 
> https://github.com/NikNakk/r-source/commit/0a82f6d23b8a2ace44e43a28cb6eb923145a13c8
>
> Almost all of the code in here can be replaced with a simple call to 
> _waccess, other than the check for executable. This seems to work as 
> expected. Since _waccess exists as a system call within Windows and 
> has the same syntax (other than wide characters) as access in POSIX, 
> why not use it?
>
> BW
>
> Nick
>
> On 3 July 2018 at 09:21, Tomas Kalibera  > wrote:
>
>
> 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
> 
> 

Re: [Rd] Suggestion: Make CRAN source URLs immutable

2018-10-24 Thread Kurt Hornik
> Kurt Wheeler writes:

Try e.g.

https://cran.r-project.org/package=httr&version=1.3.1
https://cran.r-project.org/package=httr&version=1.3.0

-k

> Hello, I hope the is the right list to send this suggestion to.
> I was wondering if it might be possible to have CRAN store the most current
> version of a package's source tarball at a location that does not change.
> As an example, the source tarball for `httr` is stored at
> https://cran.r-project.org/src/contrib/httr_1.3.1.tar.gz. However, once the
> next version of `httr` is released, the URL for version 1.3.1 of `httr`
> will change to
> https://cran.r-project.org/src/contrib/Archive/httr_1.3.1.tar.gz.

> The implications of this are that if I want to write a script which
> installs version 1.3.1 of `httr`, I need to do so like this:

> ```
> httr_url <- "https://cran.r-project.org/src/contrib/httr_1.3.1.tar.gz";

> curl_result <- system(paste0("curl --head ", httr_url), intern=TRUE)
> if (grepl("404", curl_result[1])) {
>   httr_url <- "
> https://cran.r-project.org/src/contrib/Archive/httr_1.3.1.tar.gz";
> }

> install.packages(httr_url)
> ```

> I think there are two obvious ways of remedying this issue. The first would
> be to simply archive the most recent version along with all the old
> versions. Then to install a specific version of a package, it would just be:

> ```
> install.packages("
> https://cran.r-project.org/src/contrib/Archive/httr_1.3.1.tar.gz";)
> ```

> even if 1.3.1 is the most recent version of `httr`.


> The other way to remedy this issue would be to simply not use the
> `/Archive/` sub-directory. So if I wanted to install an old version of
> `httr` it would be:

> ```
> install.packages("https://cran.r-project.org/src/contrib/httr_1.3.0.tar.gz";)
> ```

> despite the fact that version 1.3.0 is not the most recent version.


> I believe the first way would be a better choice because then any existing
> scripts which reference URLs which include `/Archive/` would still work.
> However I do not have strong opinions on how this should be implemented, I
> would just like a URL which points to a certain version of a package that
> will never change.

> Thank you,

> - Kurt

>   [[alternative HTML version deleted]]

> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Suggestion: Make CRAN source URLs immutable

2018-10-24 Thread Kurt Wheeler
Hello, I hope the is the right list to send this suggestion to.

I was wondering if it might be possible to have CRAN store the most current
version of a package's source tarball at a location that does not change.
As an example, the source tarball for `httr` is stored at
https://cran.r-project.org/src/contrib/httr_1.3.1.tar.gz. However, once the
next version of `httr` is released, the URL for version 1.3.1 of `httr`
will change to
https://cran.r-project.org/src/contrib/Archive/httr_1.3.1.tar.gz.

The implications of this are that if I want to write a script which
installs version 1.3.1 of `httr`, I need to do so like this:

```
httr_url <- "https://cran.r-project.org/src/contrib/httr_1.3.1.tar.gz";

curl_result <- system(paste0("curl --head ", httr_url), intern=TRUE)
if (grepl("404", curl_result[1])) {
  httr_url <- "
https://cran.r-project.org/src/contrib/Archive/httr_1.3.1.tar.gz";
}

install.packages(httr_url)
```

I think there are two obvious ways of remedying this issue. The first would
be to simply archive the most recent version along with all the old
versions. Then to install a specific version of a package, it would just be:

```
install.packages("
https://cran.r-project.org/src/contrib/Archive/httr_1.3.1.tar.gz";)
```

even if 1.3.1 is the most recent version of `httr`.


The other way to remedy this issue would be to simply not use the
`/Archive/` sub-directory. So if I wanted to install an old version of
`httr` it would be:

```
install.packages("https://cran.r-project.org/src/contrib/httr_1.3.0.tar.gz";)
```

despite the fact that version 1.3.0 is not the most recent version.


I believe the first way would be a better choice because then any existing
scripts which reference URLs which include `/Archive/` would still work.
However I do not have strong opinions on how this should be implemented, I
would just like a URL which points to a certain version of a package that
will never change.

Thank you,

- Kurt

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel