diff --git a/CHANGELOG.md b/CHANGELOG.md index d0f40c9..d2ca7c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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 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 diff --git a/src/system/auto_update.rs b/src/system/auto_update.rs index f66e9ff..a0b618e 100644 --- a/src/system/auto_update.rs +++ b/src/system/auto_update.rs @@ -2,6 +2,8 @@ //! //! 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; pub use self_update::errors::Error as UpdateError; use self_update::update::Release as UpdRelease; @@ -67,6 +69,9 @@ impl Update { /// otherwise if no version is available, return None /// In case of error returns Error with the error description pub fn is_new_version_available() -> Result, UpdateError> { + // check if api.github.com is reachable before doing anything + Self::check_github_api_reachable()?; + info!("Checking whether a new version is available..."); GithubUpdater::configure() // Set default options @@ -83,6 +88,27 @@ impl Update { .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 fn check_version(r: Release) -> Option { 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.10.9", "0.11.0")); } + + #[test] + fn test_should_check_whether_github_api_is_reachable() { + assert!(Update::check_github_api_reachable().is_ok()); + } } diff --git a/src/ui/activities/auth/misc.rs b/src/ui/activities/auth/misc.rs index 7de6194..e011d7e 100644 --- a/src/ui/activities/auth/misc.rs +++ b/src/ui/activities/auth/misc.rs @@ -223,10 +223,7 @@ impl AuthActivity { } Err(err) => { // Report error - error!("Failed to get latest version: {}", err); - self.mount_error( - format!("Could not check for new updates: {err}").as_str(), - ); + error!("Failed to get latest version: {err}",); } } } else {