mirror of
https://github.com/veeso/termscp.git
synced 2026-09-27 06:21:22 -07:00
fix: Issues with update checks (#363)
Removed error popup message if failed to check for updates. Prevent long timeouts when checking for updates if the network is down or the DNS is not working. closes #354
This commit is contained in:
@@ -50,6 +50,9 @@ Released on 20/09/2025
|
|||||||
- [Issue 334](https://github.com/veeso/termscp/issues/334): SMB support for MacOS with vendored build of libsmbclient.
|
- [Issue 334](https://github.com/veeso/termscp/issues/334): SMB support for MacOS with vendored build of libsmbclient.
|
||||||
- [Issue 337](https://github.com/veeso/termscp/issues/337): Migrated to libssh.org on Linux and MacOS for better ssh agent support.
|
- [Issue 337](https://github.com/veeso/termscp/issues/337): Migrated to libssh.org on Linux and MacOS for better ssh agent support.
|
||||||
- [Issue 361](https://github.com/veeso/termscp/issues/361): Report a message while calculating total size of files to transfer.
|
- [Issue 361](https://github.com/veeso/termscp/issues/361): Report a message while calculating total size of files to transfer.
|
||||||
|
- [Issue 354](https://github.com/veeso/termscp/issues/354):
|
||||||
|
- Removed error popup message if failed to check for updates.
|
||||||
|
- Prevent long timeouts when checking for updates if the network is down or the DNS is not working.
|
||||||
|
|
||||||
## 0.18.0
|
## 0.18.0
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
//!
|
//!
|
||||||
//! Automatic update module. This module is used to upgrade the current version of termscp to the latest available on Github
|
//! Automatic update module. This module is used to upgrade the current version of termscp to the latest available on Github
|
||||||
|
|
||||||
|
use std::net::ToSocketAddrs as _;
|
||||||
|
|
||||||
use self_update::backends::github::Update as GithubUpdater;
|
use self_update::backends::github::Update as GithubUpdater;
|
||||||
pub use self_update::errors::Error as UpdateError;
|
pub use self_update::errors::Error as UpdateError;
|
||||||
use self_update::update::Release as UpdRelease;
|
use self_update::update::Release as UpdRelease;
|
||||||
@@ -67,6 +69,9 @@ impl Update {
|
|||||||
/// otherwise if no version is available, return None
|
/// otherwise if no version is available, return None
|
||||||
/// In case of error returns Error with the error description
|
/// In case of error returns Error with the error description
|
||||||
pub fn is_new_version_available() -> Result<Option<Release>, UpdateError> {
|
pub fn is_new_version_available() -> Result<Option<Release>, UpdateError> {
|
||||||
|
// check if api.github.com is reachable before doing anything
|
||||||
|
Self::check_github_api_reachable()?;
|
||||||
|
|
||||||
info!("Checking whether a new version is available...");
|
info!("Checking whether a new version is available...");
|
||||||
GithubUpdater::configure()
|
GithubUpdater::configure()
|
||||||
// Set default options
|
// Set default options
|
||||||
@@ -83,6 +88,27 @@ impl Update {
|
|||||||
.map(Self::check_version)
|
.map(Self::check_version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if api.github.com is reachable
|
||||||
|
/// This is useful to avoid long timeouts when the network is down
|
||||||
|
/// or the DNS is not working
|
||||||
|
fn check_github_api_reachable() -> Result<(), UpdateError> {
|
||||||
|
let Some(socket_addr) = ("api.github.com", 443)
|
||||||
|
.to_socket_addrs()
|
||||||
|
.ok()
|
||||||
|
.and_then(|mut i| i.next())
|
||||||
|
else {
|
||||||
|
error!("Could not resolve api.github.com");
|
||||||
|
return Err(UpdateError::Network(
|
||||||
|
"Could not resolve api.github.com".into(),
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
|
// just try to open a connection to api.github.com with a timeout of 5 seconds with tcp
|
||||||
|
std::net::TcpStream::connect_timeout(&socket_addr, std::time::Duration::from_secs(5))
|
||||||
|
.map(|_| ())
|
||||||
|
.map_err(|e| UpdateError::Network(format!("Could not reach api.github.com: {e}")))
|
||||||
|
}
|
||||||
|
|
||||||
/// In case received version is newer than current one, version as Some is returned; otherwise None
|
/// In case received version is newer than current one, version as Some is returned; otherwise None
|
||||||
fn check_version(r: Release) -> Option<Release> {
|
fn check_version(r: Release) -> Option<Release> {
|
||||||
debug!("got version from GitHub: {}", r.version);
|
debug!("got version from GitHub: {}", r.version);
|
||||||
@@ -212,4 +238,9 @@ mod test {
|
|||||||
assert!(!Update::is_new_version_higher("0.9.9", "0.10.1"));
|
assert!(!Update::is_new_version_higher("0.9.9", "0.10.1"));
|
||||||
assert!(!Update::is_new_version_higher("0.10.9", "0.11.0"));
|
assert!(!Update::is_new_version_higher("0.10.9", "0.11.0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_should_check_whether_github_api_is_reachable() {
|
||||||
|
assert!(Update::check_github_api_reachable().is_ok());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,10 +223,7 @@ impl AuthActivity {
|
|||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Report error
|
// Report error
|
||||||
error!("Failed to get latest version: {}", err);
|
error!("Failed to get latest version: {err}",);
|
||||||
self.mount_error(
|
|
||||||
format!("Could not check for new updates: {err}").as_str(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user