Skip to content

Commit 2bad8b0

Browse files
committed
Create MissingBlobs struct
1 parent 82f22d8 commit 2bad8b0

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

src/lib.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,35 @@ use std::collections::HashMap;
44
use std::fs;
55
use std::path::{Path, PathBuf};
66

7-
pub struct Config {
8-
pub recursive: bool,
7+
pub struct MissingBlobs {
8+
recursive: bool,
99
}
1010

11-
pub fn run(paths: &[&str], config: Config) {
12-
let file_paths: Vec<PathBuf> = if config.recursive {
13-
find_files_recursively(&paths)
14-
} else {
15-
find_files(&paths)
16-
};
17-
18-
let blob_paths: Vec<&PathBuf> = file_paths
19-
.iter()
20-
.filter(|path| match path.extension() {
21-
// Assume that valid blobs have ".so" extension.
22-
Some(ext) => ext == "so",
23-
None => false,
24-
})
25-
.collect();
11+
impl MissingBlobs {
12+
pub fn new(recursive: bool) -> Self {
13+
Self { recursive }
14+
}
2615

27-
let blobs_to_dependencies = get_dependencies(&blob_paths);
28-
let missing_blobs = identify_missing(&blobs_to_dependencies);
29-
display_missing_blobs(&missing_blobs);
16+
pub fn run(&self, paths: &[&str]) {
17+
let file_paths: Vec<PathBuf> = if self.recursive {
18+
find_files_recursively(&paths)
19+
} else {
20+
find_files(&paths)
21+
};
22+
23+
let blob_paths: Vec<&PathBuf> = file_paths
24+
.iter()
25+
.filter(|path| match path.extension() {
26+
// Assume that valid blobs have ".so" extension.
27+
Some(ext) => ext == "so",
28+
None => false,
29+
})
30+
.collect();
31+
32+
let blobs_to_dependencies = get_dependencies(&blob_paths);
33+
let missing_blobs = identify_missing(&blobs_to_dependencies);
34+
display_missing_blobs(&missing_blobs);
35+
}
3036
}
3137

3238
fn find_files(paths: &[&str]) -> Vec<PathBuf> {

src/main.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use aosp_missing_blobs::{run, Config};
1+
use aosp_missing_blobs::MissingBlobs;
22
use clap::{crate_description, crate_name, crate_version, App, Arg};
33

44
fn main() {
@@ -20,11 +20,7 @@ fn main() {
2020
.get_matches();
2121

2222
let paths = matches.values_of("PATHS").unwrap().collect::<Vec<_>>();
23+
let recursive = matches.is_present("recursive");
2324

24-
run(
25-
&paths,
26-
Config {
27-
recursive: matches.is_present("recursive"),
28-
},
29-
);
25+
MissingBlobs::new(recursive).run(&paths);
3026
}

0 commit comments

Comments
 (0)