Skip to main content

weavatrix_scan/report/
compact.rs

1use super::{CompactScanReport, CompactScannedFile, FileVersion, PathBuf, ScanReport, ScannedFile};
2
3impl CompactScanReport {
4    /// Materializes an absolute path for one compact entry.
5    #[must_use]
6    pub fn absolute_path(&self, file: &CompactScannedFile) -> PathBuf {
7        self.root.join(file.relative.as_ref())
8    }
9
10    /// Materializes the compatibility report without reading file contents
11    /// again.
12    #[must_use]
13    pub fn into_scan_report(self) -> ScanReport {
14        let root = self.root;
15        let files = self
16            .files
17            .into_iter()
18            .map(|file| {
19                let content = file.content.map(|content| *content);
20                ScannedFile {
21                    absolute: root.join(file.relative.as_ref()),
22                    relative: file.relative.into(),
23                    bytes: file.bytes,
24                    content_hash: content
25                        .as_ref()
26                        .and_then(|value| value.content_hash.as_deref())
27                        .map(str::to_owned),
28                    content_fingerprint: content
29                        .as_ref()
30                        .and_then(|value| value.content_fingerprint.as_deref())
31                        .map(str::to_owned),
32                    version: content
33                        .as_ref()
34                        .map_or_else(FileVersion::default, |value| value.version),
35                    binary_checked: content.is_some_and(|value| value.binary_checked),
36                }
37            })
38            .collect();
39        ScanReport {
40            root,
41            files,
42            skipped: self.skipped,
43            warnings: self.warnings,
44            ignore_sources: self.ignore_sources,
45            revision: self.revision,
46            complete: self.complete,
47            termination: self.termination,
48            portable: self.portable,
49            cache: self.cache,
50            record_skipped: true,
51        }
52    }
53}