Skip to content

Copy code to temporary file during Source as Local Job - #7871

Merged
jmcphers merged 1 commit into
masterfrom
bugfix/source-local-job
Sep 29, 2020
Merged

jmcphers merged 1 commit into
masterfrom
bugfix/source-local-job

Conversation

@melissa-barca

Copy link
Copy Markdown
Contributor

Intent

Fixes #6701

Source as Local Job was failing on Windows when the file's path had a non ASCII character in it on Windows. This PR executes the source as it does on other operating systems today.

Approach

Rather than attempting to source from the file the user is working in, copy the contents of that file to a temporary file. This avoids us needing to encode and re-encode files paths.

QA Notes

The original ticket gives a good repro. We should also make sure functionality hasn't regressed on other OSes. We should also ensure that non-ascii encoded characters run without issue (they may produce a warning which is ok).

@jmcphers

Copy link
Copy Markdown
Member

I'm not sure about this approach. Some R scripts use the name and/or path of the currently executing script to compute resource paths, etc. Executing the script from a temporary file (even though the working directory is the same) may break some scripts.

It looks like we correctly convert to the system encoding when creating the command that invokes the job, so maybe all we need is to decode correctly here?

statements <- parse(file = script, keep.source = TRUE, encoding = encoding)

@melissa-barca

Copy link
Copy Markdown
Contributor Author

@jmcphers I'm not exactly sure what you mean. Are you suggesting we decode from the system encoding to utf8 before parsing the file? In that case, do we need to encode the path when creating the command?
I tested out removing our call to utfToSystem when we create the command and the file is able to source properly. Is there a reason we need to do this?
https://github.com/rstudio/rstudio/blob/master/src/cpp/session/modules/jobs/ScriptJob.cpp#L151-L152

@melissa-barca
melissa-barca force-pushed the bugfix/source-local-job branch from e6639ad to b1bc4bb Compare September 28, 2020 21:14
@melissa-barca

Copy link
Copy Markdown
Contributor Author

I updated the code to remove the second utf8ToSystem call referenced above. This is ready for review again.

@jmcphers jmcphers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, glad this turned out to be simple!

@jmcphers
jmcphers merged commit c112fc2 into master Sep 29, 2020
@jmcphers

Copy link
Copy Markdown
Member

Also deserves a NEWS entry (feel free to update on master)

@melissa-barca
melissa-barca deleted the bugfix/source-local-job branch September 29, 2020 16:48
@melissa-barca

Copy link
Copy Markdown
Contributor Author

Also deserves a NEWS entry (feel free to update on master)

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sourcing an open script file as a job fails if the path contains non-ASCII characters on Windows

2 participants