From 4a8b23c43bc2659940169a873a838210dc46a3cf Mon Sep 17 00:00:00 2001 From: Bo Lu Date: Tue, 4 Jun 2019 23:14:08 +1000 Subject: [PATCH] add zbox_version() function --- src/base/mod.rs | 20 ++++++++++++++------ src/base/version.rs | 7 +++---- src/lib.rs | 2 +- src/volume/storage/zbox/http_client.rs | 2 +- src/volume/volume.rs | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/base/mod.rs b/src/base/mod.rs index 55f5583..e34f8e8 100644 --- a/src/base/mod.rs +++ b/src/base/mod.rs @@ -31,6 +31,14 @@ use wasm_logger; #[cfg(all(not(target_os = "android"), not(target_arch = "wasm32")))] use env_logger; +/// Get ZboxFS version string. +/// +/// This method return ZboxFS version as a string, e.g. "ZboxFS 0.8.0". +#[inline] +pub fn zbox_version() -> String { + format!("ZboxFS {}", Version::lib_version()) +} + static INIT: Once = ONCE_INIT; cfg_if! { @@ -48,8 +56,8 @@ cfg_if! { ); crypto::Crypto::init().expect("Initialise crypto failed"); debug!( - "ZboxFS v{} - Zero-details, privacy-focused in-app file system", - Version::current_lib_version() + "{} - Zero-details, privacy-focused in-app file system", + zbox_version() ); }); } @@ -59,8 +67,8 @@ cfg_if! { wasm_logger::init(wasm_logger::Config::new(Level::Trace)); crypto::Crypto::init().expect("Initialise crypto failed"); debug!( - "ZboxFS v{} - Zero-details, privacy-focused in-app file system", - Version::current_lib_version() + "{} - Zero-details, privacy-focused in-app file system", + zbox_version() ); }); } @@ -80,8 +88,8 @@ cfg_if! { env_logger::try_init().ok(); crypto::Crypto::init().expect("Initialise crypto failed"); debug!( - "ZboxFS v{} - Zero-details, privacy-focused in-app file system", - Version::current_lib_version() + "{} - Zero-details, privacy-focused in-app file system", + zbox_version() ); }); } diff --git a/src/base/version.rs b/src/base/version.rs index 6f58657..cb646a3 100644 --- a/src/base/version.rs +++ b/src/base/version.rs @@ -12,7 +12,7 @@ pub struct Version { impl Version { #[inline] - pub fn current_repo_version() -> Self { + pub fn repo_version() -> Self { Version { major: version::REPO_MAJOR_VERSION, minor: version::REPO_MINOR_VERSION, @@ -20,9 +20,8 @@ impl Version { } } - #[allow(dead_code)] #[inline] - pub fn current_lib_version() -> Self { + pub fn lib_version() -> Self { Version { major: version::LIB_MAJOR_VERSION, minor: version::LIB_MINOR_VERSION, @@ -31,7 +30,7 @@ impl Version { } pub fn match_repo_version(&self) -> bool { - let curr = Version::current_repo_version(); + let curr = Version::repo_version(); self.major == curr.major && self.minor == curr.minor } } diff --git a/src/lib.rs b/src/lib.rs index 4b4fd09..c9ce4f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -138,7 +138,7 @@ mod version; mod volume; pub use self::base::crypto::{Cipher, MemLimit, OpsLimit}; -pub use self::base::init_env; +pub use self::base::{init_env, zbox_version}; pub use self::error::{Error, Result}; pub use self::file::{File, VersionReader}; pub use self::fs::fnode::{DirEntry, FileType, Metadata, Version}; diff --git a/src/volume/storage/zbox/http_client.rs b/src/volume/storage/zbox/http_client.rs index f8a9c28..d18a65c 100644 --- a/src/volume/storage/zbox/http_client.rs +++ b/src/volume/storage/zbox/http_client.rs @@ -74,7 +74,7 @@ struct Headers { impl Headers { fn new() -> Self { let mut map = HeaderMap::new(); - let ver = Version::current_lib_version().to_string(); + let ver = Version::lib_version().to_string(); // add zbox version header let version_header = HeaderName::from_static("zbox-version"); diff --git a/src/volume/volume.rs b/src/volume/volume.rs index cf6ffc0..1d71629 100644 --- a/src/volume/volume.rs +++ b/src/volume/volume.rs @@ -59,7 +59,7 @@ impl Volume { // initialise info self.info.id = Eid::new(); - self.info.ver = Version::current_repo_version(); + self.info.ver = Version::repo_version(); self.info.compress = cfg.compress; self.info.cost = cfg.cost; self.info.cipher = cfg.cipher;