Skip to content

Commit 61a8e41

Browse files
committed
Check the maven dirs for jvm vendor entries too
A jvm ledger entry is reverted by the maven backend, and maven-family entries can own files in the JVM repository tree under .socket/vendor/maven2. The linked-dir check only looked at .socket/vendor for jvm entries, so a linked maven or maven2 dir got past dispatch and the lock was restored before the delete was refused. The check now covers maven, maven/<uuid> and maven2 for both. Assisted-by: Claude Code:claude-opus-5-5
1 parent 42178db commit 61a8e41

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

  • crates/socket-patch-core/src/vendor

‎crates/socket-patch-core/src/vendor/path.rs‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ pub fn vendor_uuid_dir_rel(eco: &str, uuid: &str) -> Option<String> {
7373
/// The first of `.socket/vendor`, `.socket/vendor/<eco>` and
7474
/// `.socket/vendor/<eco>/<uuid>` under `project_root` that is a symlink (or
7575
/// a Windows junction), project-relative and forward-slashed; `None` when
76-
/// none is. The `<eco>` level is only checked for a known ecosystem dir and
77-
/// the `<uuid>` level only for a canonical uuid.
76+
/// none is. The `<eco>` level is only checked for a known ecosystem dir
77+
/// (`jvm` counts as `maven`, which also checks the JVM repository tree
78+
/// `.socket/vendor/maven2`) and the `<uuid>` level only for a canonical
79+
/// uuid.
7880
///
7981
/// Vendor staging creates these dirs itself and never writes symlinks, so a
8082
/// linked level is never ours: its target may be another project's vendor
@@ -83,12 +85,19 @@ pub fn vendor_uuid_dir_rel(eco: &str, uuid: &str) -> Option<String> {
8385
/// and revert dispatch refuses on this before touching anything, as
8486
/// [`sweep_vendor_dirs`] already skips a linked eco or uuid dir.
8587
pub fn vendor_dir_symlink(project_root: &Path, eco: &str, uuid: Option<&str>) -> Option<String> {
88+
// A `jvm` ledger entry is reverted by the maven backend, and every
89+
// maven-family entry may own files in the JVM repository tree
90+
// (`.socket/vendor/maven2`) as well as a `maven/<uuid>` unit.
91+
let eco = if eco == "jvm" { "maven" } else { eco };
8692
let mut levels = vec![VENDOR_DIR.to_string()];
8793
if ECOSYSTEM_DIRS.contains(&eco) {
8894
levels.push(format!("{VENDOR_DIR}/{eco}"));
8995
if let Some(rel) = uuid.and_then(|u| vendor_uuid_dir_rel(eco, u)) {
9096
levels.push(rel);
9197
}
98+
if eco == "maven" {
99+
levels.push(format!("{VENDOR_DIR}/maven2"));
100+
}
92101
}
93102
levels.into_iter().find(|rel| {
94103
std::fs::symlink_metadata(project_root.join(rel))
@@ -1004,6 +1013,26 @@ mod tests {
10041013
);
10051014
assert_eq!(vendor_dir_symlink(&unit, "npm", Some("not-a-uuid")), None);
10061015

1016+
// `jvm` entries are maven-backed: the maven unit and the JVM
1017+
// repository tree are both checked.
1018+
let jvm = tmp.path().join("jvm");
1019+
std::fs::create_dir_all(jvm.join(".socket/vendor")).unwrap();
1020+
symlink(&outside, jvm.join(".socket/vendor/maven")).unwrap();
1021+
assert_eq!(
1022+
vendor_dir_symlink(&jvm, "jvm", Some(UUID)).as_deref(),
1023+
Some(".socket/vendor/maven")
1024+
);
1025+
let tree = tmp.path().join("tree");
1026+
std::fs::create_dir_all(tree.join(".socket/vendor/maven")).unwrap();
1027+
symlink(&outside, tree.join(".socket/vendor/maven2")).unwrap();
1028+
for eco in ["jvm", "maven"] {
1029+
assert_eq!(
1030+
vendor_dir_symlink(&tree, eco, Some(UUID)).as_deref(),
1031+
Some(".socket/vendor/maven2"),
1032+
"{eco}"
1033+
);
1034+
}
1035+
10071036
let vendor = tmp.path().join("vendor");
10081037
std::fs::create_dir_all(vendor.join(".socket")).unwrap();
10091038
symlink(&outside, vendor.join(".socket/vendor")).unwrap();

0 commit comments

Comments
 (0)