-
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.
Merge branch 'prevent-apt-and-dnf-from-being-confused-about-package-d…
…es-1412'
- Loading branch information
Showing
14 changed files
with
143 additions
and
44 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,63 @@ | ||
use std::fmt::Display; | ||
use std::str::FromStr; | ||
use std::sync::LazyLock; | ||
|
||
use regex::Regex; | ||
|
||
/// The Mullvad VPN app product version | ||
pub const VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/product-version.txt")); | ||
|
||
#[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 Display for Version { | ||
/// Format Version as a string: year.incremental{-beta} | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let Version { | ||
year, | ||
incremental, | ||
beta, | ||
} = &self; | ||
match beta { | ||
Some(beta) => write!(f, "{year}.{incremental}-{beta}"), | ||
None => write!(f, "{year}.{incremental}"), | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for Version { | ||
type Err = String; | ||
|
||
fn from_str(version: &str) -> Result<Self, Self::Err> { | ||
const VERSION_REGEX: &str = | ||
r"^20([0-9]{2})\.([1-9][0-9]?)(-beta([1-9][0-9]?))?(-dev-[0-9a-f]+)?$"; | ||
static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(VERSION_REGEX).unwrap()); | ||
|
||
let captures = RE | ||
.captures(version) | ||
.ok_or_else(|| format!("Version does not match expected format: {version}"))?; | ||
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
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
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
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
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
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