pub async fn read_lockfile_content(
path: &Path,
file_type: &str,
) -> Result<String>Expand description
Reads a lock file’s contents, wrapping any I/O failure into a DepsError::ParseError
tagged with the ecosystem’s file_type label and the file’s path.
Every LockFileProvider::parse_lockfile implementation reads its lock file the same
way; this shares that boilerplate and keeps the error message format consistent
across ecosystems.
Bounded by MAX_LOCKFILE_BYTES via fs_probe::read_to_string_capped — a lock file
is discovered by an unauthenticated ancestor walk (locate_lockfile_for_manifest) over
a possibly hostile cloned repository, so nothing here may assume it is reasonably sized
or a regular file before reading it in full (CWE-400). The capped read itself runs on
the blocking-thread pool via [tokio::task::spawn_blocking], not on the calling tokio
worker thread: it is synchronous I/O with no .await of its own, and every
LockFileProvider::parse_lockfile call site sits on the LSP request path, where a
worker thread blocked on an 8+ MiB read — or indefinitely, on a FIFO — would violate the
project’s non-blocking-handler rule.
§Errors
Returns DepsError::ParseError if the file cannot be read (e.g. missing, not a
regular file, unreadable, invalid UTF-8), exceeds MAX_LOCKFILE_BYTES, or the
blocking read task panicked.
§Examples
use deps_core::lockfile::read_lockfile_content;
use std::path::Path;
let content = read_lockfile_content(Path::new("Cargo.lock"), "Cargo.lock").await?;
println!("{} bytes read", content.len());