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

Change name of temporary files created. #613

Merged
merged 2 commits into from Aug 14, 2018

Conversation

jrnold
Copy link
Contributor

@jrnold jrnold commented Aug 12, 2018

Currently, during rending the code copies the backs up the R markdown file to a temporary file in the same directory with the a name like bookdown11b6326822f9c. This file should be cleaned up, but sometimes is not if the process is killed. If the file happens to not be cleaned up, it is hard to write a globbing expression for .gitignore and similar to match it that and wouldn't result in false positives; bookdown* is the best I can come up with. I propose

  1. Use a .bak extension to make it easier to match with globbing.
  2. Use the original filename as the base, since it is backing up a particular file. If the process is killed, then it is easier to restore the original file.

Alternatively, if the backup file never needs to be restored by the user, why not put it in the temporary directory?

Addresses #612

Currently, during rending the code copies the backs up the R markdown file to a temporary file in the same directory with the a name like `bookdown11b6326822f9c`. This file should be cleaned up, but sometimes is not if the process is killed. If the file happens to not be cleaned up, it is hard to write a globbing expression for `.gitignore` and similar to match it that and wouldn't result in false positives; `bookdown*` is the best I can come up with. I propose

1. Use a `.bak` extension to make it easier to match with globbing.
2. Use the original filename as the base, since it is backing up a particular file. If the process is killed, then it is easier to restore the original file.

Alternatively, if the backup file never needs to be restored by the user, why not put it in the temporary directory?

Addresses rstudio#612
Copy link
Member

@yihui yihui left a comment

Choose a reason for hiding this comment

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

This will assume that the .bak file does not exist or can be overridden. I think this is a fair assumption, but I hope not to override user's files by accident.

Will tempfile('bookdown', '.', '.bak') work for you?

Don't overwrite user filenames

See comment in rstudio#613
@jrnold
Copy link
Contributor Author

jrnold commented Aug 14, 2018

That's fine with me; the new commit makes that change. Is there a reason the backup file has to be in the working directory? It's only used for backup and not execution.

@yihui
Copy link
Member

yihui commented Aug 14, 2018

To make it easier to restore the file if anything goes wrong (e.g. R crashed). If it is in the tempdir(), I'm not sure it can always be preserved, and it is usually hard to find.

@jrnold
Copy link
Contributor Author

jrnold commented Aug 14, 2018

👍

@yihui yihui merged commit 869fd92 into rstudio:master Aug 14, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants