Skip to content

remove overwrite arg from moveInstalledPackageToCache#757

Merged
karawoo merged 5 commits into
mainfrom
kara-remove-overwrite-arg
Jul 16, 2026
Merged

remove overwrite arg from moveInstalledPackageToCache#757
karawoo merged 5 commits into
mainfrom
kara-remove-overwrite-arg

Conversation

@karawoo

@karawoo karawoo commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

See #756 (comment). That comment flagged that moveInstalledPackageToCache's backup/overwrite path (renaming an existing cache entry aside before replacing it) can race with another process populating that same entry. This function is called in two places in installPkg and neither passes fatal = TRUE. This path was only reachable if fatal = TRUE and overwrite = TRUE so removing it should be safe avoids a potential trap in the future.

@karawoo
karawoo requested a review from aronatkins July 15, 2026 17:37
Comment thread R/cache.R
#
# If the package already exists inside the cache, overwrite=TRUE causes
# replacement of the cached content while overwrite=FALSE with fatal=FALSE
# uses the cached package. Using overwrite=TRUE with fatal=TRUE will err.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just a note because it threw me off briefly, I believe this comment was inaccurate and the combination that errors is fatal = TRUE and overwrite = FALSE

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks. This comment was either incorrect when originally written or grew stale as the implementation evolved.

Should we remove fatal as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also: overwrite was a lie. Maybe always?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure I'll remove fatal too

Comment thread R/cache.R
#
# If the package already exists inside the cache, overwrite=TRUE causes
# replacement of the cached content while overwrite=FALSE with fatal=FALSE
# uses the cached package. Using overwrite=TRUE with fatal=TRUE will err.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks. This comment was either incorrect when originally written or grew stale as the implementation evolved.

Should we remove fatal as well?

Comment thread R/cache.R
)
}
on.exit(unlink(backupPackagePath, recursive = TRUE), add = TRUE)
return(symlinkPackageToCache(packagePath, cachedPackagePath))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are a number of paths through moveInstalledPackageToCache which discard the just-built package. Should we add logging for these situations? The computed type in installPkg is also misleading.

built source but i lost the race. discarded the build and symlinked cache.

Too wordy, but saying something more could help subsequent debugging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I updated to take the cacheCopyStatus argument that other related functions use, so that we can report the right info back to installPkg. Added some messaging as well.

Comment thread R/cache.R
#
# If the package already exists inside the cache, overwrite=TRUE causes
# replacement of the cached content while overwrite=FALSE with fatal=FALSE
# uses the cached package. Using overwrite=TRUE with fatal=TRUE will err.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also: overwrite was a lie. Maybe always?

@karawoo
karawoo requested a review from aronatkins July 16, 2026 16:10
Comment thread R/cache.R Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it worth enumerating the reasons why the rename might fail? Other than OS errors (full disk, no permissions):

  1. library and cache are on different file systems.
  2. cached location exists (created by another)

@karawoo

karawoo commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

lintr released today and is objecting to <<-, going to just bypass with # nolint since it's unrelated to this PR.

@aronatkins

Copy link
Copy Markdown
Contributor

lintr released today and is objecting to <<-, going to just bypass with # nolint since it's unrelated to this PR.

😭 Thanks. They haven't published updated release notes, yet. https://github.com/r-lib/lintr/blob/main/NEWS.md#lintr-340

@karawoo
karawoo merged commit f8e19b5 into main Jul 16, 2026
10 checks passed
@karawoo
karawoo deleted the kara-remove-overwrite-arg branch July 16, 2026 19:43
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.

2 participants