Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,39 @@ lookup of `get` / `scan` do not judge the ruby-platform record on that copy eith
other installed copy to match, that record is `package_not_installed` in `apply` and in
`apply --check` alike, and `vex` omits it as not installed.

**A platform record that brings its binaries.** A record for a precompiled copy's own platform
that replaces or adds a shared library (`.so`, `.bundle`, `.dylib`, `.dll`) is the diff of the
platform gem itself: the sources the gem packs and the binaries built from them, one per Ruby the
gem supports. It has no build inputs on that copy. `apply` writes its files and starts no build,
and leaves no build marker and no backup, so the copy holds the files of the patched platform gem,
which is what hosted mode installs. `apply --check`, `vex` and `rollback` judge the copy by the
record's files alone. A record for the copy's platform that changes a build input and brings no
library is built like the ruby-platform record: no binary in it was built from that input. So is
one that brings a library kept per Ruby (`lib/a/3.4/a.so`) and leaves out the same library of
another Ruby the copy ships it for: that Ruby would go on loading the unpatched code. Such a
record is handled as 5.2.0 handled every platform record, with the failure described next when the
build lands on a binary the record brings, and that copy is not repaired.

5.2.0 built the source gem for such a record too, and put that build over the record's binary for
the Ruby that ran `apply`. That file then held neither content of the record, so `apply`,
`apply --check`, `vex` and `rollback` failed on the copy (`hash_mismatch`). `apply` and
`rollback` now put the binary that build replaced back first, from the backup that run took, and
drop its marker and backup. They do so only when the record can then be applied, or rolled back:

- `apply`: with the replaced binaries left out, the rest of the record passes a dry run under the
run's own mismatch policy (so files an earlier Socket patch wrote count as they do in any
apply), and every blob the record writes is stored and holds the content the record names.
- `rollback`: every other file of the record holds its original or its patched content.
- Neither puts anything back when the backup holds content the record does not know or a file
that is not the record's, or lists files the patch added to the copy.

Any other copy is left as it is, with the build that runs the patched source in place, and fails
as before. A dry run of either command puts nothing back and reports what the run does:
`apply --dry-run` counts the copy as one that can be patched, not as already patched. A put-back
that fails partway is `native_extension_restore_failed`, and names `gem pristine`.
After `apply` writes such a record whole, a marker or backup an earlier graft left on the copy is
dropped when every file it names is one the record wrote.

**Without a build from the source gem.** Whatever keeps a gem RubyGems built from being rebuilt
from its source gem, before anything of the installed copy is written, leaves it the rebuild it
had in 5.1.0: in place, from its own tree. That is: no archive (offline and not cached, a private
Expand Down
38 changes: 23 additions & 15 deletions crates/socket-patch-cli/src/commands/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4098,23 +4098,31 @@ pub(crate) async fn rollback_patches_inner(
None => {
use socket_patch_core::patch::gem_ext;
let is_gem = Ecosystem::from_purl(purl) == Some(Ecosystem::Gem);
// A build input `apply` added to a gem copy that did not
// hold it (a precompiled gem never shipped it; a build
// removed it) is removed, not restored.
let gem_files = if is_gem {
Some(gem_ext::rollback_files(pkg_path, purl, &patch.files).await)
// A gem's files go back through `rollback_gem_patch`,
// which first puts back a build an earlier release made
// over a binary the record itself brings, and removes a
// build input `apply` added rather than restoring it.
let mut result = if is_gem {
gem_ext::rollback_gem_patch(
common.read_scope(),
purl,
pkg_path,
&patch.files,
&blobs_path,
common.dry_run,
)
.await
} else {
None
rollback_package_patch(
common.read_scope(),
purl,
pkg_path,
&patch.files,
&blobs_path,
common.dry_run,
)
.await
};
let mut result = rollback_package_patch(
common.read_scope(),
purl,
pkg_path,
gem_files.as_ref().unwrap_or(&patch.files),
&blobs_path,
common.dry_run,
)
.await;
// A gem whose native extension `apply` rebuilt gets its
// original compiled extension back with its sources
// (#1996).
Expand Down
Loading
Loading