pub trait Workspace {
Show 19 methods
// Required methods
fn package(&self) -> Option<&str>;
fn current_version(&self) -> Option<&Version>;
fn parsed_control(&self) -> Result<Control, Error>;
fn parsed_changelog(&self) -> Result<ChangeLog, Error>;
fn parsed_copyright(&self) -> Result<Copyright, Error>;
fn parsed_upstream_metadata(&self) -> Result<YamlFile, Error>;
fn parsed_watch(&self) -> Result<ParsedWatchFile, Error>;
fn parsed_rules(&self) -> Result<Makefile, Error>;
fn source_format(&self) -> Result<Option<String>, Error>;
fn control(&self) -> Result<Box<dyn Editor<Control> + '_>, Error>;
fn changelog(&self) -> Result<Box<dyn Editor<ChangeLog> + '_>, Error>;
fn debcargo(
&self,
) -> Result<Option<Box<dyn Editor<DocumentMut> + '_>>, Error>;
fn read_file(&self, rel: &Path) -> Result<Option<Cow<'_, [u8]>>, Error>;
fn write_file(&self, rel: &Path, content: &[u8]) -> Result<(), Error>;
fn list_dir(&self, rel: &Path) -> Result<Option<Vec<String>>, Error>;
fn file_mode(&self, rel: &Path) -> Result<Option<u32>, Error>;
// Provided methods
fn parsed_debcargo(&self) -> Result<Option<DocumentMut>, Error> { ... }
fn walk_dir(&self, rel: &Path) -> Result<Option<Vec<PathBuf>>, Error> { ... }
fn base_path(&self) -> Option<&Path> { ... }
}Expand description
Access to a Debian source package, as seen by a fixer.
Each typed accessor returns an editor for a well-known file. Callers can
also reach less-common files via read_file /
write_file.
Required Methods§
Sourcefn package(&self) -> Option<&str>
fn package(&self) -> Option<&str>
The source package name, as read from debian/changelog.
Returns None when the changelog is missing or unreadable. Hosts
that legitimately don’t have a changelog (e.g. an LSP that lost
access to it) should return None rather than fabricating a name.
Sourcefn current_version(&self) -> Option<&Version>
fn current_version(&self) -> Option<&Version>
The current version of the package, as read from debian/changelog.
Returns None when the changelog is missing or unreadable.
Sourcefn parsed_control(&self) -> Result<Control, Error>
fn parsed_control(&self) -> Result<Control, Error>
Read debian/control and return a parsed value.
Returns Err(Error::NotFound) if the file is missing —
detectors typically want that exact response.
Parsing is relaxed: syntax errors are tolerated and the resulting
AST may have missing or partially-recovered nodes. Detectors that
need to reject malformed input should validate the structure they
care about (e.g. that the source paragraph or a particular field
exists) rather than expecting Err.
Implementations may cache the parse; the returned value is owned
(Control is cheap to clone — its rowan green nodes are shared
internally).
Sourcefn parsed_changelog(&self) -> Result<ChangeLog, Error>
fn parsed_changelog(&self) -> Result<ChangeLog, Error>
Read debian/changelog and return a parsed value.
Returns Err(Error::NotFound) if the file is missing. Parsing is
relaxed; see parsed_control for details
on what that means.
Sourcefn parsed_copyright(&self) -> Result<Copyright, Error>
fn parsed_copyright(&self) -> Result<Copyright, Error>
Read debian/copyright and return a parsed value.
Returns Err(Error::NotFound) if the file is missing, and
Err(Error::Parse) only when the file isn’t a machine-readable
DEP-5 document at all (i.e. doesn’t start with Format:).
Parsing is otherwise relaxed; see
parsed_control for details on what that
means.
Sourcefn parsed_upstream_metadata(&self) -> Result<YamlFile, Error>
fn parsed_upstream_metadata(&self) -> Result<YamlFile, Error>
Read debian/upstream/metadata and return its parsed YAML.
Returns Err(Error::NotFound) if the file is missing or
unparseable.
Sourcefn parsed_watch(&self) -> Result<ParsedWatchFile, Error>
fn parsed_watch(&self) -> Result<ParsedWatchFile, Error>
Read debian/watch and return a parsed value.
Returns Err(Error::NotFound) if the file is missing.
Sourcefn parsed_rules(&self) -> Result<Makefile, Error>
fn parsed_rules(&self) -> Result<Makefile, Error>
Read debian/rules and return the parsed Makefile.
Returns Err(Error::NotFound) if the file is missing. Uses
Makefile::read_relaxed, mirroring the behaviour every fixer
currently expects from debian/rules parsing.
Sourcefn source_format(&self) -> Result<Option<String>, Error>
fn source_format(&self) -> Result<Option<String>, Error>
Read the trimmed contents of debian/source/format.
Returns Ok(None) if the file is missing. The default format
(1.0) is not substituted — callers see exactly what is on
disk so they can distinguish “no file” from “explicit 1.0”.
Sourcefn control(&self) -> Result<Box<dyn Editor<Control> + '_>, Error>
fn control(&self) -> Result<Box<dyn Editor<Control> + '_>, Error>
Open debian/control for editing.
Takes &self so that fixers can hold an editor and still call
other workspace methods (read_file, …). Implementations
that need to record edits on the workspace itself should use interior
mutability.
Detectors don’t need this — they emit Actions for the appliers to
run. Use parsed_control instead.
Sourcefn changelog(&self) -> Result<Box<dyn Editor<ChangeLog> + '_>, Error>
fn changelog(&self) -> Result<Box<dyn Editor<ChangeLog> + '_>, Error>
Open debian/changelog for editing. See control.
Sourcefn debcargo(&self) -> Result<Option<Box<dyn Editor<DocumentMut> + '_>>, Error>
fn debcargo(&self) -> Result<Option<Box<dyn Editor<DocumentMut> + '_>>, Error>
Open debian/debcargo.toml for editing.
Returns Ok(None) if the file does not exist.
Returns Err if the file exists but cannot be parsed.
Sourcefn read_file(&self, rel: &Path) -> Result<Option<Cow<'_, [u8]>>, Error>
fn read_file(&self, rel: &Path) -> Result<Option<Cow<'_, [u8]>>, Error>
Read raw bytes of an arbitrary file relative to the package root.
Returns Ok(None) if the file does not exist.
The returned Cow is borrowed when the host has the bytes
already in memory (an LSP host with the file open in an editor
buffer) and owned when they had to be fetched (a disk read).
Detectors that need owned bytes can call .into_owned().
Sourcefn write_file(&self, rel: &Path, content: &[u8]) -> Result<(), Error>
fn write_file(&self, rel: &Path, content: &[u8]) -> Result<(), Error>
Write raw bytes to an arbitrary file relative to the package root.
Creates the file if it does not exist.
Sourcefn list_dir(&self, rel: &Path) -> Result<Option<Vec<String>>, Error>
fn list_dir(&self, rel: &Path) -> Result<Option<Vec<String>>, Error>
List the entries of a directory relative to the package root.
Returns the file (and subdirectory) names within rel, without any
path prefix. Returns Ok(None) if the directory does not exist.
The order of returned entries is unspecified — a non-Tree host
(an LSP) may not have a meaningful directory ordering.
Sourcefn file_mode(&self, rel: &Path) -> Result<Option<u32>, Error>
fn file_mode(&self, rel: &Path) -> Result<Option<u32>, Error>
Read the Unix file mode of rel, or None if the file is missing.
Hosts that don’t track a meaningful mode (e.g. an LSP serving an
in-memory buffer) may return Ok(None) even when the file exists.
Detectors that key off mode (e.g. checking that debian/rules is
executable) treat that the same as “not present” and skip.
Provided Methods§
Sourcefn parsed_debcargo(&self) -> Result<Option<DocumentMut>, Error>
fn parsed_debcargo(&self) -> Result<Option<DocumentMut>, Error>
Read debian/debcargo.toml and return a parsed TOML document.
Returns Ok(None) if the file does not exist (package is not a
debcargo-managed crate). Returns Err if the file exists but cannot
be parsed.
Sourcefn walk_dir(&self, rel: &Path) -> Result<Option<Vec<PathBuf>>, Error>
fn walk_dir(&self, rel: &Path) -> Result<Option<Vec<PathBuf>>, Error>
Recursively walk rel, returning the relative paths of every
regular file beneath it (paths are relative to the package root,
not to rel).
Symbolic links and other non-regular entries are skipped. Returns
Ok(None) if rel does not exist.
The order of returned paths is unspecified. Hosts that can’t meaningfully walk a tree (e.g. an LSP that only knows about open buffers) may return only the files they currently track.
Sourcefn base_path(&self) -> Option<&Path>
fn base_path(&self) -> Option<&Path>
On-disk root for hosts that have one.
Returns Some for the lintian-brush CLI ([FsWorkspace])
where the package has been materialised to disk. Returns None
for in-memory hosts (an LSP serving open buffers); detectors that
genuinely need to walk the source tree (e.g. an upstream-metadata
guesser, a license scanner) should treat None as “skip — we
can’t help here”.
Prefer the typed accessors (read_file,
list_dir, …) wherever possible. Reach for
this only when an external library insists on a &Path for the
whole tree.