@@ -167,24 +167,6 @@ pub fn symlink_refusal(linked: &str) -> Refusal {
167167 }
168168}
169169
170- /// The refusal for a candidate read through a link: the file itself
171- /// ([`symlink_refusal`]), or, on disk, a directory on its path that links
172- /// out of the repository root, so a rewrite would land outside it.
173- fn linked_read_refusal ( view : & ProjectView < ' _ > , rel : & str ) -> Refusal {
174- if matches ! ( view, ProjectView :: Memory ( _) ) || view. is_symlink ( rel) {
175- return symlink_refusal ( rel) ;
176- }
177- Refusal {
178- code : SYMLINK_REFUSAL . to_string ( ) ,
179- message : format ! (
180- "{rel} is reached through a symbolic link that leaves the repository root; \
181- socket-patch does not read or rewrite project files outside it — replace the \
182- link with a regular directory (or run socket-patch in the directory it points \
183- to) and re-run; nothing was written"
184- ) ,
185- }
186- }
187-
188170/// The refusal for a symlinked `bun.lockb` (checked before any takeover
189171/// changes wiring).
190172pub fn bun_lockb_symlink_refusal ( ) -> Refusal {
@@ -420,13 +402,11 @@ impl CandidateFiles {
420402 self . undecodable_reads . push ( rel. to_string ( ) ) ;
421403 None
422404 }
423- // A candidate whose real path leaves the repository root
424- // (the file itself, or a directory on its path, is a link
425- // out of it; a candidate name never climbs): the bound
426- // refuses the read, but the package manager still follows
427- // the link, so the guard refuses it, never takes it for
428- // absent.
429- Err ( e) if crate :: utils:: repo_root:: is_refused_read ( & e) => {
405+ // A candidate linked out of the repository root: the bound
406+ // refuses the read, but the package manager still honors
407+ // the file, so it is a symlinked rewrite target the guard
408+ // refuses, never an absent one.
409+ Err ( e) if crate :: utils:: repo_root:: is_refused_read ( & e) && view. is_symlink ( rel) => {
430410 self . symlinked_reads . push ( rel. to_string ( ) ) ;
431411 None
432412 }
@@ -3674,14 +3654,14 @@ pub fn guard(
36743654 . iter ( )
36753655 . map ( |c| c. dep . ecosystem . as_str ( ) )
36763656 . collect ( ) ;
3677- // In memory, every linked candidate; on disk, those whose real path
3678- // leaves the repository root, whose reads the bound refused.
3657+ // In memory, every linked candidate; on disk, those linked out of the
3658+ // repository root, whose reads the bound refused.
36793659 if let Some ( linked) = done
36803660 . symlinked_reads
36813661 . iter ( )
36823662 . find ( |rel| file_ecosystem ( rel) . is_some_and ( |eco| candidate_ecosystems. contains ( eco) ) )
36833663 {
3684- return Some ( linked_read_refusal ( view , linked) ) ;
3664+ return Some ( symlink_refusal ( linked) ) ;
36853665 }
36863666 let ProjectView :: Memory ( project) = view else {
36873667 return None ;
@@ -3746,44 +3726,6 @@ mod tests {
37463726 ) ;
37473727 }
37483728
3749- /// A disk candidate whose real path leaves the repository root, as
3750- /// the file itself or through a directory link on its path, is
3751- /// recorded as a linked read (refused by the guard), never as absent.
3752- #[ cfg( unix) ]
3753- #[ tokio:: test]
3754- async fn disk_candidates_linked_out_of_the_repository_are_refused ( ) {
3755- let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
3756- let repo = tmp. path ( ) . join ( "repo" ) ;
3757- let outside = tmp. path ( ) . join ( "outside" ) ;
3758- std:: fs:: create_dir_all ( repo. join ( ".git" ) ) . unwrap ( ) ;
3759- std:: fs:: create_dir_all ( outside. join ( "sub" ) ) . unwrap ( ) ;
3760- std:: fs:: write ( outside. join ( "uv.lock" ) , "version = 1\n " ) . unwrap ( ) ;
3761- std:: fs:: write ( outside. join ( "sub/package-lock.json" ) , "{}\n " ) . unwrap ( ) ;
3762- std:: os:: unix:: fs:: symlink ( outside. join ( "uv.lock" ) , repo. join ( "uv.lock" ) ) . unwrap ( ) ;
3763- std:: os:: unix:: fs:: symlink ( outside. join ( "sub" ) , repo. join ( "sub" ) ) . unwrap ( ) ;
3764- let view = ProjectView :: Disk ( & repo) ;
3765- let mut out = CandidateFiles :: default ( ) ;
3766- for rel in [ "uv.lock" , "sub/package-lock.json" ] {
3767- assert ! ( !out. read( & view, & BTreeSet :: new( ) , rel) . await , "{rel}" ) ;
3768- }
3769- assert_eq ! ( out. symlinked_reads, [ "uv.lock" , "sub/package-lock.json" ] ) ;
3770- assert ! ( out. files. is_empty( ) ) ;
3771- let file = linked_read_refusal ( & view, "uv.lock" ) ;
3772- assert_eq ! ( file. code, SYMLINK_REFUSAL ) ;
3773- assert ! (
3774- file. message. contains( "uv.lock is a symbolic link" ) ,
3775- "{}" ,
3776- file. message
3777- ) ;
3778- let dir = linked_read_refusal ( & view, "sub/package-lock.json" ) ;
3779- assert_eq ! ( dir. code, SYMLINK_REFUSAL ) ;
3780- assert ! (
3781- dir. message. contains( "leaves the repository root" ) ,
3782- "{}" ,
3783- dir. message
3784- ) ;
3785- }
3786-
37873729 fn no_cargo_outer ( ) -> CratesIoSource {
37883730 CratesIoSource :: Registry
37893731 }
0 commit comments