Bug 17159 - recursive dir.create() fails on windows shares due to permissions
Summary: recursive dir.create() fails on windows shares due to permissions
Alias: None
Product: R
Classification: Unclassified
Component: Windows GUI / Window specific (show other bugs)
Version: R 3.3.*
Hardware: x86_64/x64/amd64 (64-bit) Windows 64-bit
: P5 major
Assignee: R-core
Depends on:
Reported: 2016-09-24 23:50 UTC by Evan Cortens
Modified: 2016-09-26 21:22 UTC (History)
0 users

See Also:

A patch that will skip both the server and the share (532 bytes, patch)
2016-09-26 21:22 UTC, Evan Cortens
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Evan Cortens 2016-09-24 23:50:05 UTC
On Windows, dir.create() with recursive=TRUE attempts to create each directory in the path, even if it already exists. This is problematic when the user has restricted write access, for instance, on a network share. For example:

> dir.create('\\\\sharename\\Empl\\Home1\\active\\e\\ecortens\\thisisatest', recursive = TRUE)
Warning message:
In dir.create("\\\\sharename\\Empl\\Home1\\active\\e\\ecortens\\thisisatest",  :
  cannot create dir '\\ad.mtroyal.ca\Empl', reason 'Permission denied'

I have write access within "ecortens", but, naturally, not within the root of the network share, so it's erroring because it's trying to create "Empl" in a directory that I can't write to.

This is problematic, for instance, in the creation of the 00LOCK directory in install.packages(), which is a call to dir.create() with recursive=TRUE.

I'm not comfortable enough with my C abilities to submit a patch, but the fix, I think, is around line 2170 of src/main.c (in the latest R-devel, checked out from subversion). I know that errno of EEXIST isn't supposed to trigger an exit, but for whatever reason, the Windows API is not setting errno to EEXIST, even though the directory does exist. 

The solution, I think, would be to call _wstat() and check that the directory exists, and is a directory, and if so, move to the next chunk of the path, rather than trying to _wmkdir().


> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.3.1     withr_1.0.2     memoise_1.0.0   digest_0.6.10   devtools_1.12.0
Comment 1 Evan Cortens 2016-09-26 21:22:20 UTC
Created attachment 2167 [details]
A patch that will skip both the server and the share

I'm not sure if this is the correct behaviour for all versions of windows. It solves the problem for me, however.