Skip to content

Commit

Permalink
Change: Split the function add_nvt. Now the duplicated oid check is p…
Browse files Browse the repository at this point in the history
…erformed in a private function
  • Loading branch information
jjnicola authored and ArnoStiefvater committed Dec 1, 2022
1 parent 4828d14 commit 5a1b30c
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions rust/nvtcache/src/nvtcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,10 @@ impl<'a> NvtCache<'a> {
Ok(filename)
}

pub fn add_nvt(&mut self, nvt: Nvt, filename: String) -> Result<()> {
let oid = nvt.get_oid();
let cached_nvt: String = self.get_nvt_filename(&oid)?;

// First check if there is a duplicate OID
// If it is in the cache, and are not the same filename
// we check if it is still in the filesystem.
/// First check if there is a duplicate OID
/// If it is in the cache, and are not the same filename
/// we check if it is still in the filesystem.
fn check_nvt_duplication(&self, oid: &str, cached_nvt: &String, filename: &String) {
if !cached_nvt.is_empty() && cached_nvt != filename {
let mut src_path: String = self.plugin_path.to_owned();
src_path.push_str(&cached_nvt);
Expand All @@ -105,6 +102,14 @@ impl<'a> NvtCache<'a> {
);
}
}
}

/// Add an NVT.
pub fn add_nvt(&mut self, nvt: Nvt, filename: String) -> Result<()> {
let oid = nvt.get_oid();
let cached_nvt: String = self.get_nvt_filename(&oid)?;

self.check_nvt_duplication(&oid, &cached_nvt, &filename);

// Remove the present NVT metadata
if !cached_nvt.is_empty() {
Expand Down

0 comments on commit 5a1b30c

Please sign in to comment.