Skip to content

Commit ee91fbd

Browse files
author
Sandeep Bhardwaj
committed
Read report from the cache, bump version
1 parent f49e964 commit ee91fbd

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cake"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["Sandeep Bhardwaj <sb23007@gmail.com>"]
55
edition = "2018"
66

src/analyze.rs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,36 @@ use crate::packages::rpm::RPMPackageManager;
1616
use std::path::Path;
1717

1818
pub fn analyze_image(image: &str, pkgs: bool, tree: bool) {
19-
if image.is_empty() {
20-
panic!("No image file present")
19+
let report = match read_report(image) {
20+
Some(report) => report,
21+
None => {
22+
let overlayfs = create_ofs(image);
23+
create_analysis_report(overlayfs, image)
24+
}
25+
};
26+
27+
if tree {
28+
report.ofs.show_as_tree();
29+
return;
2130
}
2231

32+
if pkgs {
33+
report.show_packages();
34+
} else {
35+
report.show_report();
36+
}
37+
}
38+
39+
fn read_report(image: &str) -> Option<AnalysisReport> {
40+
let image_json = format!("{}_report.json", image);
41+
if Path::new(&image_json).exists() {
42+
trace!("Loaded analysis report from cache: {}_report", image);
43+
return Some(AnalysisReport::create_report_from_json(image));
44+
}
45+
None
46+
}
47+
48+
fn create_ofs(image: &str) -> OverlayFs {
2349
let mut overlayfs = OverlayFs::new();
2450
let image_json = format!("{}.json", image);
2551

@@ -46,18 +72,7 @@ pub fn analyze_image(image: &str, pkgs: bool, tree: bool) {
4672
overlayfs.update_sizes();
4773
overlayfs.save_tree_to_json(image);
4874
}
49-
50-
if tree {
51-
overlayfs.show_as_tree();
52-
return;
53-
}
54-
55-
let report = create_analysis_report(overlayfs, image);
56-
if pkgs {
57-
report.show_packages();
58-
} else {
59-
report.show_report();
60-
}
75+
overlayfs
6176
}
6277

6378
fn fetch(id: &str) {

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ fn main() {
3232
.short('p')
3333
.long("packages")
3434
.takes_value(false),
35-
).arg(
35+
)
36+
.arg(
3637
Arg::new("tree")
3738
.short('t')
3839
.long("tree")

0 commit comments

Comments
 (0)