-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Check that the daemon version is correct post-upgrade
- Loading branch information
1 parent
b30555e
commit 0fa7a6d
Showing
5 changed files
with
58 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,44 @@ | ||
use regex::Regex; | ||
use std::str::FromStr; | ||
|
||
/// The Mullvad VPN app product version | ||
pub const VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/product-version.txt")); | ||
|
||
const VERSION_REGEX: &str = r"^20([0-9]{2})\.([1-9][0-9]?)(-beta([1-9][0-9]?))?(-dev-[0-9a-f]+)?$"; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct Version { | ||
pub year: String, | ||
pub incremental: String, | ||
pub beta: Option<String>, | ||
} | ||
|
||
impl Version { | ||
pub fn parse(version: &str) -> Version { | ||
Version::from_str(version).unwrap() | ||
} | ||
} | ||
|
||
impl FromStr for Version { | ||
type Err = &'static str; | ||
|
||
fn from_str(version: &str) -> Result<Self, Self::Err> { | ||
let re = Regex::new(VERSION_REGEX).unwrap(); | ||
let captures = re | ||
.captures(version) | ||
.ok_or("Version does not match expected format")?; | ||
let year = captures.get(1).expect("Missing year").as_str().to_owned(); | ||
let incremental = captures | ||
.get(2) | ||
.ok_or("Missing incremental")? | ||
.as_str() | ||
.to_owned(); | ||
let beta = captures.get(4).map(|m| m.as_str().to_owned()); | ||
|
||
Ok(Version { | ||
year, | ||
incremental, | ||
beta, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters