diff --git a/libimagentryfilter/Cargo.toml b/libimagentryfilter/Cargo.toml index 6aa89527..80c0cff9 100644 --- a/libimagentryfilter/Cargo.toml +++ b/libimagentryfilter/Cargo.toml @@ -9,6 +9,7 @@ itertools = "0.4.7" log = "0.3.4" regex = "0.1.48" toml = "0.1.27" +semver = "0.2.1" [dependencies.libimagstore] path = "../libimagstore" diff --git a/libimagentryfilter/src/builtin/header/mod.rs b/libimagentryfilter/src/builtin/header/mod.rs index baece9f6..0d27f5b4 100644 --- a/libimagentryfilter/src/builtin/header/mod.rs +++ b/libimagentryfilter/src/builtin/header/mod.rs @@ -7,3 +7,4 @@ pub mod field_istype; pub mod field_lt; pub mod field_path; pub mod field_predicate; +pub mod version; diff --git a/libimagentryfilter/src/builtin/header/version/eq.rs b/libimagentryfilter/src/builtin/header/version/eq.rs new file mode 100644 index 00000000..f2be5a28 --- /dev/null +++ b/libimagentryfilter/src/builtin/header/version/eq.rs @@ -0,0 +1,44 @@ +use semver::Version; +use toml::Value; + +use libimagstore::store::Entry; + +use builtin::header::field_path::FieldPath; +use filter::Filter; + +pub struct VersionEq { + version: Version, +} + +impl VersionEq { + + pub fn new(version: Version) -> VersionEq { + VersionEq { version: version } + } + +} + +impl Filter for VersionEq { + + fn filter(&self, e: &Entry) -> bool { + e.get_header() + .read("imag.version") + .map(|val| { + val.map(|v| { + match v { + Value::String(s) => { + match Version::parse(&s[..]) { + Ok(v) => v == self.version, + _ => false + } + }, + _ => false, + } + }) + .unwrap_or(false) + }) + .unwrap_or(false) + } + +} + diff --git a/libimagentryfilter/src/builtin/header/version/gt.rs b/libimagentryfilter/src/builtin/header/version/gt.rs new file mode 100644 index 00000000..69f5da67 --- /dev/null +++ b/libimagentryfilter/src/builtin/header/version/gt.rs @@ -0,0 +1,46 @@ +use semver::Version; +use toml::Value; + +use libimagstore::store::Entry; + +use builtin::header::field_path::FieldPath; +use filter::Filter; + +pub struct VersionGt { + version: Version, +} + +impl VersionGt { + + pub fn new(version: Version) -> VersionGt { + VersionGt { version: version } + } + +} + +impl Filter for VersionGt { + + fn filter(&self, e: &Entry) -> bool { + e.get_header() + .read("imag.version") + .map(|val| { + val.map(|v| { + match v { + Value::String(s) => { + match Version::parse(&s[..]) { + Ok(v) => v > self.version, + _ => false + } + }, + _ => false, + } + }) + .unwrap_or(false) + }) + .unwrap_or(false) + } + +} + + + diff --git a/libimagentryfilter/src/builtin/header/version/lt.rs b/libimagentryfilter/src/builtin/header/version/lt.rs new file mode 100644 index 00000000..fd815475 --- /dev/null +++ b/libimagentryfilter/src/builtin/header/version/lt.rs @@ -0,0 +1,45 @@ +use semver::Version; +use toml::Value; + +use libimagstore::store::Entry; + +use builtin::header::field_path::FieldPath; +use filter::Filter; + +pub struct VersionLt { + version: Version, +} + +impl VersionLt { + + pub fn new(version: Version) -> VersionLt { + VersionLt { version: version } + } + +} + +impl Filter for VersionLt { + + fn filter(&self, e: &Entry) -> bool { + e.get_header() + .read("imag.version") + .map(|val| { + val.map(|v| { + match v { + Value::String(s) => { + match Version::parse(&s[..]) { + Ok(v) => v < self.version, + _ => false + } + }, + _ => false, + } + }) + .unwrap_or(false) + }) + .unwrap_or(false) + } + +} + + diff --git a/libimagentryfilter/src/builtin/header/version/mod.rs b/libimagentryfilter/src/builtin/header/version/mod.rs new file mode 100644 index 00000000..a2e86826 --- /dev/null +++ b/libimagentryfilter/src/builtin/header/version/mod.rs @@ -0,0 +1,4 @@ +pub mod eq; +pub mod gt; +pub mod lt; +pub mod range; diff --git a/libimagentryfilter/src/builtin/header/version/range.rs b/libimagentryfilter/src/builtin/header/version/range.rs new file mode 100644 index 00000000..9dffe5d6 --- /dev/null +++ b/libimagentryfilter/src/builtin/header/version/range.rs @@ -0,0 +1,50 @@ +use semver::Version; + +use libimagstore::store::Entry; + +use builtin::header::version::gt::VersionGt; +use builtin::header::version::lt::VersionLt; +use filter::Filter; +use ops::and::And; +use ops::not::Not; + +pub struct VersionInRange { + and: And, +} + +impl VersionInRange { + + pub fn new(lowerbound: Version, upperbound: Version) -> VersionInRange { + VersionInRange { and: VersionGt::new(lowerbound).and(Box::new(VersionLt::new(upperbound))) } + } + +} + +impl Filter for VersionInRange { + + fn filter(&self, e: &Entry) -> bool { + self.and.filter(e) + } + +} + +pub struct VersionOutOfRange { + not: Not +} + +impl VersionOutOfRange { + + pub fn new(lowerbound: Version, upperbound: Version) -> VersionOutOfRange { + VersionOutOfRange { not: VersionInRange::new(lowerbound, upperbound).not() } + } + +} + +impl Filter for VersionOutOfRange { + + fn filter(&self, e: &Entry) -> bool { + self.not.filter(e) + } + +} + diff --git a/libimagentryfilter/src/lib.rs b/libimagentryfilter/src/lib.rs index 6234c1ac..277bff42 100644 --- a/libimagentryfilter/src/lib.rs +++ b/libimagentryfilter/src/lib.rs @@ -3,6 +3,7 @@ extern crate itertools; extern crate regex; extern crate toml; +extern crate semver; extern crate libimagstore; extern crate libimagtag;