Skip to content

Commit d99f96e

Browse files
committed
fix(launch): check cancellation before reporting trigger scan degradation
1 parent a60dcce commit d99f96e

1 file changed

Lines changed: 49 additions & 11 deletions

File tree

‎backend/src/launch.rs‎

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,6 @@ fn workspace_folders(host: &Host, workspace: &WorkspaceContext) -> Result<Vec<Pa
648648
.unwrap_or_default())
649649
}
650650

651-
/// The `triggerFiles` of a launch: `file:` URIs of up to
652-
/// [`TRIGGER_FILE_LIMIT`] `.java` files found under `folders`, folders and
653-
/// entries in sorted order so the same workspace always names the same files.
654-
/// The scan stops at [`TRIGGER_SCAN_DEPTH`] levels, skips hidden directories
655-
/// and [`TRIGGER_SCAN_SKIPPED_DIRECTORIES`], does not follow symbolic links,
656-
/// and reads at most [`TRIGGER_SCAN_ENTRY_BUDGET`] entries. Optional missing
657-
/// folders contribute nothing; other I/O failures preserve partial results and
658-
/// are counted once at the launch boundary without including file paths.
659651
// A native DirEntry is intentionally classified only after the per-entry budget
660652
// check. Tests can substitute entries and failures without changing permissions
661653
// or relying on host-specific directory iteration behavior.
@@ -792,8 +784,15 @@ fn report_trigger_scan(scan: &TriggerScan, report: &dyn Fn(&str, u64)) {
792784
}
793785
}
794786

795-
/// Collects optional JDT LS trigger files with the same scan boundaries as a
796-
/// launch. Only a launch reports diagnostic degradation, not this helper.
787+
/// The `triggerFiles` of a launch: `file:` URIs of up to
788+
/// [`TRIGGER_FILE_LIMIT`] `.java` files found under `folders`, folders and
789+
/// entries in sorted order so the same workspace always names the same files.
790+
/// The scan stops at [`TRIGGER_SCAN_DEPTH`] levels, skips hidden directories
791+
/// and [`TRIGGER_SCAN_SKIPPED_DIRECTORIES`], does not follow symbolic links,
792+
/// and reads at most [`TRIGGER_SCAN_ENTRY_BUDGET`] entries. Optional missing
793+
/// folders contribute nothing; other I/O failures preserve partial results and
794+
/// are counted once at the launch boundary without including file paths. Only
795+
/// a launch reports diagnostic degradation, not this helper.
797796
pub fn trigger_files(folders: &[PathBuf]) -> Result<Vec<String>, PluginError> {
798797
Ok(scan_trigger_files(folders, TRIGGER_SCAN_ENTRY_BUDGET, native_trigger_entries)?.files)
799798
}
@@ -873,8 +872,8 @@ pub fn resolve_launch_function(
873872
None => (Vec::new(), Vec::new()),
874873
};
875874
let scan = scan_trigger_files(&folders, TRIGGER_SCAN_ENTRY_BUDGET, native_trigger_entries)?;
876-
report_trigger_scan(&scan, &report);
877875
context.check_cancelled()?;
876+
report_trigger_scan(&scan, &report);
878877
let mut answer = resolve(
879878
&request,
880879
&server,
@@ -1463,6 +1462,20 @@ mod tests {
14631462
});
14641463
assert_eq!(calls.get(), 1);
14651464
report_trigger_scan(&vanished, &|_, _| panic!("missing folders are normal"));
1465+
1466+
let disappeared_entries =
1467+
scan_trigger_files::<TriggerFixtureEntry>(&roots, TRIGGER_SCAN_ENTRY_BUDGET, |_| {
1468+
Ok(vec![
1469+
Err(io::Error::from(io::ErrorKind::NotFound)),
1470+
Ok(TriggerFixtureEntry {
1471+
path: roots[0].join("Gone.java"),
1472+
kind: Err(io::ErrorKind::NotFound),
1473+
}),
1474+
])
1475+
})
1476+
.unwrap();
1477+
assert!(disappeared_entries.files.is_empty());
1478+
assert_eq!(disappeared_entries.unreadable, 0);
14661479
}
14671480

14681481
#[test]
@@ -1584,6 +1597,31 @@ mod tests {
15841597
assert!(trigger_files(&[]).unwrap().is_empty());
15851598
}
15861599

1600+
#[cfg(unix)]
1601+
#[test]
1602+
fn trigger_scan_does_not_follow_symlinks_or_report_them_unreadable() {
1603+
let fixture = Fixture::new();
1604+
let workspace = fixture.root.join("workspace");
1605+
let outside = fixture.root.join("outside");
1606+
fs::create_dir_all(&workspace).unwrap();
1607+
fs::create_dir_all(&outside).unwrap();
1608+
let real = workspace.join("Real.java");
1609+
let outside_file = outside.join("Outside.java");
1610+
fs::write(&real, b"").unwrap();
1611+
fs::write(&outside_file, b"").unwrap();
1612+
std::os::unix::fs::symlink(&outside_file, workspace.join("Link.java")).unwrap();
1613+
std::os::unix::fs::symlink(&outside, workspace.join("linked_dir")).unwrap();
1614+
1615+
let scan = scan_trigger_files(
1616+
std::slice::from_ref(&workspace),
1617+
TRIGGER_SCAN_ENTRY_BUDGET,
1618+
native_trigger_entries,
1619+
)
1620+
.unwrap();
1621+
assert_eq!(scan.files, vec![file_uri(&real).unwrap()]);
1622+
assert_eq!(scan.unreadable, 0);
1623+
}
1624+
15871625
#[test]
15881626
fn trigger_files_stop_at_the_limit() {
15891627
let fixture = Fixture::new();

0 commit comments

Comments
 (0)