Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip directory from NordVPN filenames #63

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "vopono"
description = "Launch applications via VPN tunnels using temporary network namespaces"
version = "0.6.6"
version = "0.6.7"
authors = ["James McMurray <[email protected]>"]
edition = "2018"
license = "GPL-3.0-or-later"
Expand Down
20 changes: 14 additions & 6 deletions src/providers/nordvpn/openvpn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ impl OpenVpnProvider for NordVPN {
.extension()
.map(|x| x.to_str().expect("Could not convert OsStr"))
{
let fname = file.name();
let fname = file
.enclosed_name()
.and_then(|x| x.file_name())
.and_then(|x| x.to_str());
if fname.is_none() {
debug!("Could not parse filename: {}", file.name().to_string());
continue;
}
let fname = fname.unwrap();
let server_name = fname.to_lowercase().replace(' ', "_");
let server_name = server_name.split('.').next().unwrap();

Expand All @@ -92,24 +100,24 @@ impl OpenVpnProvider for NordVPN {
let country = country_map.get(code.as_str());
if country.is_none() {
debug!("Could not map country code to name: {}", code.as_str());
file.name().to_string()
fname.to_string()
} else {
let server_name = server_name.replace("-", "_");
format!("{}-{}.ovpn", country.unwrap(), server_name)
}
} else {
debug!(
"Filename did not match established pattern: {}",
file.name().to_string()
fname.to_string()
);
file.name().to_string()
fname.to_string()
}
} else {
debug!(
"Filename did not match established pattern: {}",
file.name().to_string()
fname.to_string()
);
file.name().to_string()
fname.to_string()
}
} else {
file.name().to_string()
Expand Down