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

Overwrite files if they exist #84

Merged
merged 3 commits into from
Oct 19, 2018

Conversation

jimhester
Copy link
Member

The default behavior of file.copy() is not to overwrite files
(without an error or warning) if they already exist. So if there was
already a built tarball in the check directory it would not be updated.

cc @jennybc

@jimhester jimhester requested a review from gaborcsardi October 18, 2018 12:42
Copy link
Member

@gaborcsardi gaborcsardi left a comment

Choose a reason for hiding this comment

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

Thanks!

@jimhester
Copy link
Member Author

Do you want me to add a note to NEWS or anything?

@gaborcsardi
Copy link
Member

yes, please.

The default behavior of `file.copy()` is _not_ to overwrite files
(without an error or warning) if they already exist. So if there was
already a built tarball in the check directory it would not be updated.

cc @jennybc
@jimhester jimhester force-pushed the file.copy-overwrite branch from bbaae61 to 21f9732 Compare October 18, 2018 12:58
@codecov-io
Copy link

codecov-io commented Oct 18, 2018

Codecov Report

Merging #84 into master will decrease coverage by 0.05%.
The diff coverage is 75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #84      +/-   ##
==========================================
- Coverage   79.83%   79.78%   -0.06%     
==========================================
  Files          17       17              
  Lines         749      752       +3     
==========================================
+ Hits          598      600       +2     
- Misses        151      152       +1
Impacted Files Coverage Δ
R/build.R 100% <100%> (ø) ⬆️
R/package.R 95.23% <66.66%> (-1.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a3afa2...8c7613e. Read the comment docs.

@jimhester
Copy link
Member Author

Ok, I think this is good to go then!

@kevinushey
Copy link
Contributor

This affects attempts to use devtools::check() in RStudio since we invoke the command with

devtools::check(check_dir = dirname(getwd()))

and if an old tarball exists from a prior build attempt, that old tarball will be used. In effect, a user can get into this state if they run Check inside RStudio while the package has R CMD check errors, since we don't clean up the old tarball in that case. (We leave the build tarball behind if the build process exits with a non-zero status code, which rcmdcheck does if any check errors are discovered)

@gaborcsardi after this fix comes in, would you be willing to push a patch-fix release to CRAN?

@gaborcsardi
Copy link
Member

@gaborcsardi sure, np.

@gaborcsardi
Copy link
Member

So, one issue with this is that it potentially leaves some old files behind. I think if we are already overwriting, we should unlink(recursive = TRUE) the check directory before running the new check.

@jimhester
Copy link
Member Author

jimhester commented Oct 19, 2018

Yeah that is true, we should probably clean out the check directory first. I actually tried that first, because that was what I thought the problem was initially, I will resurrect the code (1e70510)

R/package.R Outdated
@@ -117,6 +117,12 @@ do_check <- function(targz, package, args, libpath, repos,
profile <- make_fake_profile(session_output = session_output)
on.exit(unlink(profile), add = TRUE)

# if the pkg.Rcheck directory already exists, unlink it
check_dir <- paste0(package, ".Rcheck")
if (file.exists(check_dir)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need to check for this, just unlink, it will do nothing if it does not exist, anyway. IMO checking for the existence of a file, is almost always an anti-pattern.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure that is fair, race conditions.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it might even make sense to filelock::filelock() the check dir, in case you call multiple checks from multiple sessions, and unlock() in on.exit. But we don't have to do that in this PR.

@@ -1,6 +1,9 @@

# devel

* `rcmdcheck()` now correctly overwrites existing tarballs if they already
exist in the check directory (#84 @jimhester).
Copy link
Member

Choose a reason for hiding this comment

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

This is not just the tarballs, right? But overwrites (well, replaces) the whole check directory, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

No it is just the tarballs, if it is a directory it uses the other part of the conditional that is unchanged.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, OK, got it.

Copy link
Member

@gaborcsardi gaborcsardi left a comment

Choose a reason for hiding this comment

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

Thanks much!

@@ -1,6 +1,9 @@

# devel

* `rcmdcheck()` now correctly overwrites existing tarballs if they already
exist in the check directory (#84 @jimhester).
Copy link
Member

Choose a reason for hiding this comment

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

Oh, OK, got it.

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 this pull request may close these issues.

4 participants