Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to save file from Rstudio 1.2.5033 and 1.3.036 (Windows 10) on network shares (UNC paths) #6587

Closed
3 tasks done
gwd666 opened this issue Apr 3, 2020 · 22 comments · Fixed by #6598
Closed
3 tasks done
Assignees

Comments

@gwd666
Copy link

@gwd666 gwd666 commented Apr 3, 2020

RStudio 1.2.5033 cannot save files (.R, .Rmd, etc) to Users home folder or any of its subfolders which is located on "\\server/path/to/USER/Daten" (Daten == Documents)

System details

  • RStudio Edition: Desktop
  • RStudio Version: 1.2.5033 AS WELL AS 1.3.936
  • OS Version: MS WINdows 10 Enterprise - Version: 10.0.17763 Build 17763
  • R Version: 3.5.3 and 3.6.3

Description of issue
RStudio (1.2.5033 and 1.3.936) cannot save files (.R, .Rmd, etc) to Users home folder if is located on Windows UNC path "\\server/path/to/USER/Daten" (Daten == Documents)

Steps to reproduce the problem

Open RStudio 1.2.5033
Create New (empty) file - optionally write some content into it.
Try to "Save As" ... anywhere on the (UNC path) Users home folder

Describe the problem in detail

Not possible to save any files on a UNC path "out of the box" (see also 'Attempted steps taken to fix' below)

Error Information:

image

Describe the behavior you expected

Ability to save files - just like with RStudio 1.1.463 under UNC-PATH USER home folder or its subfolders.

Attempted steps taken to fix

  • Replace UNC \\server/some/path/to/User/Documents with mapped drive letter eg: "L:/USER/Documents"; this works temporarily but is not a feasible permanent solution since after every login respectively even after restart of RStudio 1.2.5033 the same bug reappears!

  • Output of diagnostics report (if possible):
    see attached .pdf file - interesting sidenote RStudio managed to create (the rstudio-diagnostics folder) and write the diagnostic-report.txt file to the users (UNC path) document folder w/o applying any fixes (eg as mentioned above mapping to drive letter etc.)
    diagnostics-report.txt

"Interesting" sidenote RStudio 1.2.5033 managed to create (the rstudio-diagnostics folder) and write the diagnostic-report file to the users (UNC path) document folder w/o applying any prior fixes (eg as mentioned above mapping to drive letter etc.) before that action.
So it seems that UNC path access / write ability is hidden somewhere in there?

@gwd666 gwd666 changed the title Cannot save file from Rstudio 1.2.5033 and 1.3.036 (w Windows 10) on network shares (UNC paths) Not possible to save file from Rstudio 1.2.5033 and 1.3.036 (Windows 10) on network shares (UNC paths) Apr 3, 2020
@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 4, 2020

Here's a few things that might help us better debug this issue:

  1. With the file open that cannot be saved, what does:
context <- .rs.api.getSourceEditorContext()
context$path
path.expand(context$path)

print? Does it run successfully? Does the path look correct?

  1. Does it work if attempt to edit a file using a different naming scheme for the path? For example:
file.edit("\\\\?\\server\\path\\to\\USER\\Daten\\test-1.txt")
file.edit("\\\\?\\UNC\\server\\path\\to\\USER\\Daten\\test-2.txt")

Do those files successfully open? Are you able to modify + save them?

  1. If you're able, can you try using the Windows process monitor to monitor the rsession.exe process as it attempts to open these files? Does the rsession.exe process appear to be using the correct paths?

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 4, 2020

I'd also be curious to know what path.expand("~/") returns, in case this is somehow related to an incorrect tilde expansion happening for some UNC paths.

@gwd666
Copy link
Author

@gwd666 gwd666 commented Apr 4, 2020

Hi, will do - hope latest on Monday is ok? Thanks for quick reaction.
Here is the result of
> path.expand("~/")
[1] "//server/path/to/USER/Daten/"

@gwd666
Copy link
Author

@gwd666 gwd666 commented Apr 5, 2020

Here is the remaining outputs:

> context <- .rs.api.getSourceEditorContext()
> context$path
[1] ""
> path.expand(context$path)
[1] ""

This first attempt of .rs.api.getSourceEditorContext() is an expected result since I cannot save anything to the described UNC path with a fresh start of RStudio 1.2.5033, correct?

Here are further results - I was so free to adjust your first test1.txt example a little bit ...
TESTING test1.txt:
> file.edit(paste(path.expand('~/'), "test-1.txt"))
works - including modifying test1.txt and saving the modified file.

TESTING test2.txt:
> file.edit("\\\\server-unc-path/to/USER/Daten/test2.txt")
works - including modifying test2.txt and saving the modified file.

TESTING test3.txt:
> file.edit("\\\\server-unc-path\\to\\USER\\Daten\\test3.txt")
works - including modifying test3.txt and saving the modified file.

After this exercise the .rs.api.getSourceEditorContext() command now gives:

> context <- .rs.api.getSourceEditorContext()
> context$path
[1] "~/test3.txt"
> path.expand(context$path)
[1] "//server/path/to/USER/Daten/test3.txt"

So basically as soon as I do something similar to this
file.edit("\\\\server\\path\\to\\USER\\Daten\\test.txt") the context$path gets refreshed to "~/", which brings me to the additional comment that if I open a file via right-clicking and choosing 'Open with ... ' RStudio in the respective drop-down menu this error also does not show up.

Further information
When trying to set or modify the 'default working directory' under Tools -> Global Options -> General it looks like this - pls pay attention to the initial setting of: ~/. (take note of slash and dot at th end) plus it also will NOT allow a change to another UNC path to be made to this setting, I am talking about selecting a subfolder of the UNC-PATH USER "~" homefolder.
image

Adjusting this path to some (local) folder on the C-drive works and that setting change also remains intact after restarting RStudio.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 5, 2020

This first attempt of .rs.api.getSourceEditorContext() is an expected result since I cannot save anything to the described UNC path with a fresh start of RStudio 1.2.5033, correct?

Sorry, that's correct.

This might be more useful. After attempting to save the new document, you should be able to view the RStudio event log by typing:

Ctrl + `

You should see an event called save_document_diff. Clicking on that should give more information about the event; e.g.

Screen Shot 2020-04-05 at 9 34 24 AM

Do you see the correct path there? (I wonder if it's being malformed in a similar way to what you're seeing with the default working directory)

@kevinushey kevinushey added this to the v1.4 milestone Apr 5, 2020
@gwd666
Copy link
Author

@gwd666 gwd666 commented Apr 5, 2020

  1. Editing also works with file.edit("~/test4.txt")
  2. When hovering above the tab it shows ~/test4.txt
  3. Opening a file is not a problem
  4. Ctrl + ` output below
    image

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 5, 2020

Good news! I've finally been able to reproduce this error locally. The issue does indeed occur if your home directory is set to a UNC path. I initially was not able to reproduce as I was setting the home directory but not matching the case of the UNC path correctly.

Here are some steps to reproduce the issue:

  1. Set the R_USER environment variable to \\path\to\server\home. Be careful to make sure the case matches that of the server + filesystem.

  2. Open RStudio, create a file, and then try to save it within the home directory.

That save fails, and it looks like it's because the path isn't constructed correctly:

Screen Shot 2020-04-05 at 9 45 57 AM

Now that we can reproduce locally, we should be able to get to the bottom of this issue. Thank you for all your help!

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 5, 2020

And here's a way to reproduce locally without requiring a separate network share: just use a UNC path to the local home directory.

R_USER = \\localhost\c$%HOMEPATH%

Will try to get to the bottom of this soon.

@gwd666
Copy link
Author

@gwd666 gwd666 commented Apr 5, 2020

Just a reminder comment - as mentioned in the issue title this also happens with RStudio 1.3.036.
Really looking fwd to the solution. Pls, if I may ask, keep me updated on the progress.
Stay safe, stay home!

@kevinushey kevinushey self-assigned this Apr 5, 2020
@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 5, 2020

For what it's worth, I believe one workaround would be to set R_USER to the same server path (as UNC), but with different casing -- e.g. with the server name capitalized. (This affects how RStudio tries to perform tilde expansion / path aliasing, which I believe is the root cause of the issue here)

If that works, would that suffice as a workaround in the interim?

@gwd666
Copy link
Author

@gwd666 gwd666 commented Apr 5, 2020

If that works, would that suffice as a workaround in the interim?

I will give it a shot tomorrow - thanks a lot for this workaround suggestion. I'm definitely thankful for [workaround] until you come up with a fix.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 5, 2020

Note to self: the error is here:

path_t relativePath =
m_impl->Path.lexically_normal().lexically_relative(
in_parentPath.m_impl->Path.lexically_normal());

It looks like the file separators aren't normalized the same way in each path, and this causes the attempt to compute a lexically relative path to fail.

I think we can fix this by fixing the path separators before attempting to form a lexically relative path.

@gwd666
Copy link
Author

@gwd666 gwd666 commented Apr 10, 2020

For what it's worth, I believe one workaround would be to set R_USER to the same server path (as UNC), but with different casing -- e.g. with the server name capitalized. (This affects how RStudio tries to perform tilde expansion / path aliasing, which I believe is the root cause of the issue here)

If that works, would that suffice as a workaround in the interim?

This work around (at least when applied via Sys.setenv(...) in .Rprofile) does not make 'Save As' to the Users (UNC) home directory work, when Save As is done from the File menu drop-down in RStudio.
Maybe you could be a bit more precise on how to set this work-around up? Do you mean via .Rprofile (Sys.setenv()) or in .Renviron or all together outside of R eg defining R_USER in the Users WINDOWS ENV variables? Would appreciate a small hint to spare myself trying out all possible combinations.

Note: Defining "R_USER" (ie adding it) to the Users WINDOWS ENV variables, worked! Just setting it up via ~/.Rprofile was not enough, same for ~/.Renviron ... Rprofile.site modification I haven't tried yet.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 10, 2020

Note: Defining "R_USER" (ie adding it) to the Users WINDOWS ENV variables, worked!

I think that's what I would expect -- RStudio reads the environment variable pretty early on during initialization, so it needs to be set when RStudio is launched (that is, before R itself is initialized).

@gwd666
Copy link
Author

@gwd666 gwd666 commented Apr 10, 2020

Note: Defining "R_USER" (ie adding it) to the Users WINDOWS ENV variables, worked!

I think that's what I would expect -- RStudio reads the environment variable pretty early on during initialization, so it needs to be set when RStudio is launched (that is, before R itself is initialized).

Thanks (again) for clarifying that ... so I won't invest any time into modifying Rprofile.site, I guess.

@gwd666
Copy link
Author

@gwd666 gwd666 commented Apr 24, 2020

I downloaded preview RStudio-1.3.947.zip and tried to save to a UNC (HOME) folder-> still problem to save file.
image

The Tools -> Global Options -> 'default working directory' does look better now
image

As well as the output of the follwing commands

> .rs.api.getSourceEditorContext()$path
[1] "~/"
> path.expand(.rs.api.getSourceEditorContext()$path)
[1] "//UNC-Path/to/Server/USERS/SomeUSERNAME/Daten/"

@gwd666
Copy link
Author

@gwd666 gwd666 commented Apr 24, 2020

Again the save_document_diff details

== REQUEST ======
{
"method": "save_document_diff",
"params": [
"2ADD2ADE",
null,
null,
null,
"",
[],
"\n",
937,
1,
true,
"4218041572"
],
"clientId": "33e600bb-c1b1-46bf-b562-ab5cba070b0e",
"clientVersion": ""
}

== RESPONSE ======
{
"result": "4218041572",
"ep": "false"
}

A whole lot of 'null' up there - guess that is not good?

@gtritchie
Copy link
Member

@gtritchie gtritchie commented Apr 24, 2020

The Initial 1.3 release will not contain this fix. It was made in 1.3-patch which will be the first bugfix release of 1.3 but is not yet being built. That will start happening once 1.3 has been released.

@R-Hannibal
Copy link

@R-Hannibal R-Hannibal commented Jun 3, 2020

Hey @gwd666, thanks again for finding and reporting this issue. We have a fix in place in our latest preview build (available HERE).

If you get the chance will you let us know if the issue is resolved for you in that build?

@gwd666
Copy link
Author

@gwd666 gwd666 commented Jun 3, 2020

@R-Hannibal - will do test - expect info from me by tomorrow

@gwd666
Copy link
Author

@gwd666 gwd666 commented Jun 3, 2020

Hey @gwd666, thanks again for finding and reporting this issue. We have a fix in place in our latest preview build (available HERE).

If you get the chance will you let us know if the issue is resolved for you in that build?

@R-Hannibal first 'plain vanilla' attempts of saving files in RStudio to the Users UNC path home folder worked. I will probably do a couple more variations (eg with modifications in Global Options etc) some time later - but for now it looks very promising.
Thanks a lot - nice job.

@R-Hannibal
Copy link

@R-Hannibal R-Hannibal commented Jun 12, 2020

Thanks so much for confirming the fix @gwd666 , and for the kind words (I'm in Quality Assurance but will definitely pass your compliments on to the development team).

Please let us know if you see any variations or re-occurrences of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants