Skip to content

Commit 73b7857

Browse files
committed
feat: Migrate to Rust 2024 edition
- Update edition from 2021 to 2024 in both Cargo.toml files - Cargo.toml (bssh main package) - crates/bssh-russh/Cargo.toml (SSH library fork) - Fix pattern matching for 2024 edition: - Remove explicit 'ref' and 'ref mut' bindings in if-let patterns - 2024 edition uses implicit borrowing in patterns - Updated session_info to mutable variable where needed - src/server/handler.rs (4 pattern changes) - src/server/shell.rs (1 pattern change) - Code changes summary: - 119 files reformatted by rustfmt - No breaking API changes - All unsafe code, macros, async/await remain compatible - All dependencies support 2024 edition - Compilation status: - cargo build --release: ✅ SUCCESS - All binaries (bssh, bssh-server, bssh-keygen) compile correctly 2024 edition improvements applied: - Implicit pattern borrowing eliminates need for 'ref'/'ref mut' - Support for guard clauses (if let X = Y && condition) - Better error messages and compile-time checks
1 parent e4d703b commit 73b7857

119 files changed

Lines changed: 1057 additions & 938 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repository = "https://github.com/lablup/bssh"
1414
readme = "README.md"
1515
keywords = ["cli", "rust"]
1616
categories = ["command-line-utilities"]
17-
edition = "2021"
17+
edition = "2024"
1818

1919
[dependencies]
2020
bytes = "1.11.1"

benches/large_output_benchmark.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use bssh::node::Node;
2525
use bssh::ssh::tokio_client::CommandOutput;
2626
use bssh::ui::tui::app::TuiApp;
2727
use bytes::Bytes;
28-
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
29-
use ratatui::backend::TestBackend;
28+
use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
3029
use ratatui::Terminal;
30+
use ratatui::backend::TestBackend;
3131
use std::hint::black_box;
3232
use tokio::runtime::Runtime;
3333
use tokio::sync::mpsc;

crates/bssh-russh/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.60.1"
44
authors = ["Jeongkyu Shin <inureyes@gmail.com>"]
55
description = "Temporary fork of russh with high-frequency PTY output fix (Handle::data from spawned tasks)"
66
documentation = "https://docs.rs/bssh-russh"
7-
edition = "2021"
7+
edition = "2024"
88
homepage = "https://github.com/lablup/bssh"
99
keywords = ["ssh"]
1010
license = "Apache-2.0"

src/app/dispatcher.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ use bssh::{
1919
cli::{Cli, Commands},
2020
commands::{
2121
download::download_file,
22-
exec::{execute_command, ExecuteCommandParams},
22+
exec::{ExecuteCommandParams, execute_command},
2323
interactive::InteractiveCommand,
2424
list::list_clusters,
2525
ping::ping_nodes,
26-
upload::{upload_file, FileTransferParams},
26+
upload::{FileTransferParams, upload_file},
2727
},
2828
config::InteractiveMode,
2929
pty::PtyConfig,
3030
security::get_sudo_password,
31-
ssh::tokio_client::{SshConnectionConfig, DEFAULT_KEEPALIVE_INTERVAL, DEFAULT_KEEPALIVE_MAX},
31+
ssh::tokio_client::{DEFAULT_KEEPALIVE_INTERVAL, DEFAULT_KEEPALIVE_MAX, SshConnectionConfig},
3232
};
3333
use std::path::{Path, PathBuf};
3434
use std::sync::Arc;
3535

3636
#[cfg(target_os = "macos")]
3737
use super::initialization::determine_use_keychain;
38-
use super::initialization::{determine_ssh_key_path, AppContext};
38+
use super::initialization::{AppContext, determine_ssh_key_path};
3939
use super::utils::format_duration;
4040

4141
/// Build SSH connection config with keepalive settings.

src/app/initialization.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use bssh::{
2020
config::Config,
2121
jump::parse_jump_hosts,
2222
node::Node,
23-
ssh::{known_hosts::StrictHostKeyChecking, SshConfig},
23+
ssh::{SshConfig, known_hosts::StrictHostKeyChecking},
2424
utils::init_logging,
2525
};
2626
use std::path::PathBuf;
@@ -275,15 +275,15 @@ pub fn determine_strict_host_key_checking(
275275
}
276276

277277
// SSH config value for specific hostname
278-
if let Some(host) = hostname {
279-
if let Some(ssh_config_value) = ssh_config.get_strict_host_key_checking(host) {
280-
return match ssh_config_value.to_lowercase().as_str() {
281-
"yes" => StrictHostKeyChecking::Yes,
282-
"no" => StrictHostKeyChecking::No,
283-
"ask" | "accept-new" => StrictHostKeyChecking::AcceptNew,
284-
_ => StrictHostKeyChecking::AcceptNew,
285-
};
286-
}
278+
if let Some(host) = hostname
279+
&& let Some(ssh_config_value) = ssh_config.get_strict_host_key_checking(host)
280+
{
281+
return match ssh_config_value.to_lowercase().as_str() {
282+
"yes" => StrictHostKeyChecking::Yes,
283+
"no" => StrictHostKeyChecking::No,
284+
"ask" | "accept-new" => StrictHostKeyChecking::AcceptNew,
285+
_ => StrictHostKeyChecking::AcceptNew,
286+
};
287287
}
288288

289289
// Default from CLI (already parsed)

src/app/nodes.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,12 @@ mod tests {
562562
let result = exclude_nodes(nodes, &patterns);
563563

564564
assert!(result.is_err());
565-
assert!(result
566-
.unwrap_err()
567-
.to_string()
568-
.contains("too many wildcards"));
565+
assert!(
566+
result
567+
.unwrap_err()
568+
.to_string()
569+
.contains("too many wildcards")
570+
);
569571
}
570572

571573
#[test]
@@ -575,10 +577,12 @@ mod tests {
575577
let result = exclude_nodes(nodes, &patterns);
576578

577579
assert!(result.is_err());
578-
assert!(result
579-
.unwrap_err()
580-
.to_string()
581-
.contains("invalid characters"));
580+
assert!(
581+
result
582+
.unwrap_err()
583+
.to_string()
584+
.contains("invalid characters")
585+
);
582586
}
583587

584588
#[test]
@@ -588,10 +592,12 @@ mod tests {
588592
let result = exclude_nodes(nodes, &patterns);
589593

590594
assert!(result.is_err());
591-
assert!(result
592-
.unwrap_err()
593-
.to_string()
594-
.contains("invalid sequences"));
595+
assert!(
596+
result
597+
.unwrap_err()
598+
.to_string()
599+
.contains("invalid sequences")
600+
);
595601
}
596602

597603
#[test]

src/bin/bssh_keygen.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ fn main() -> Result<()> {
123123
};
124124

125125
// Ensure parent directory exists
126-
if let Some(parent) = output.parent() {
127-
if !parent.exists() {
128-
std::fs::create_dir_all(parent)
129-
.with_context(|| format!("Failed to create directory: {}", parent.display()))?;
130-
}
126+
if let Some(parent) = output.parent()
127+
&& !parent.exists()
128+
{
129+
std::fs::create_dir_all(parent)
130+
.with_context(|| format!("Failed to create directory: {}", parent.display()))?;
131131
}
132132

133133
// Check if file exists and prompt for overwrite

src/bin/bssh_server.rs

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
//! This binary provides a command-line interface for managing the bssh SSH server.
1818
1919
use anyhow::{Context, Result};
20-
use bssh::server::config::{generate_config_template, load_config, ServerFileConfig};
2120
use bssh::server::BsshServer;
21+
use bssh::server::config::{ServerFileConfig, generate_config_template, load_config};
2222
use bssh::utils::logging;
2323
use clap::{ArgAction, Parser, Subcommand};
2424
use std::fs;
@@ -471,37 +471,36 @@ fn setup_signal_handlers() -> Result<impl std::future::Future<Output = ()>> {
471471
/// Write the current process ID to a PID file
472472
fn write_pid_file(path: &PathBuf) -> Result<()> {
473473
// Check if PID file already exists and refers to a running process
474-
if path.exists() {
475-
if let Ok(existing_pid_str) = fs::read_to_string(path) {
476-
if let Ok(existing_pid) = existing_pid_str.trim().parse::<i32>() {
477-
// Check if process is still running
478-
#[cfg(unix)]
479-
{
480-
use nix::sys::signal::kill;
481-
use nix::unistd::Pid;
482-
483-
let pid = Pid::from_raw(existing_pid);
484-
// Use signal 0 (None) to check if process exists without sending actual signal
485-
if kill(pid, None).is_ok() {
486-
anyhow::bail!(
487-
"Another instance is already running with PID {}. \
474+
if path.exists()
475+
&& let Ok(existing_pid_str) = fs::read_to_string(path)
476+
&& let Ok(existing_pid) = existing_pid_str.trim().parse::<i32>()
477+
{
478+
// Check if process is still running
479+
#[cfg(unix)]
480+
{
481+
use nix::sys::signal::kill;
482+
use nix::unistd::Pid;
483+
484+
let pid = Pid::from_raw(existing_pid);
485+
// Use signal 0 (None) to check if process exists without sending actual signal
486+
if kill(pid, None).is_ok() {
487+
anyhow::bail!(
488+
"Another instance is already running with PID {}. \
488489
If this is incorrect, remove {} and try again.",
489-
existing_pid,
490-
path.display()
491-
);
492-
}
493-
}
494-
495-
#[cfg(not(unix))]
496-
{
497-
// On non-Unix systems, warn but allow overwrite
498-
tracing::warn!(
499-
"PID file exists with PID {}. Overwriting (process check not available on this platform).",
500-
existing_pid
501-
);
502-
}
490+
existing_pid,
491+
path.display()
492+
);
503493
}
504494
}
495+
496+
#[cfg(not(unix))]
497+
{
498+
// On non-Unix systems, warn but allow overwrite
499+
tracing::warn!(
500+
"PID file exists with PID {}. Overwriting (process check not available on this platform).",
501+
existing_pid
502+
);
503+
}
505504
}
506505

507506
let pid = std::process::id();
@@ -798,10 +797,12 @@ mod tests {
798797

799798
let result = gen_host_key("rsa", &key_path, 1024);
800799
assert!(result.is_err());
801-
assert!(result
802-
.unwrap_err()
803-
.to_string()
804-
.contains("RSA key size must be at least 2048"));
800+
assert!(
801+
result
802+
.unwrap_err()
803+
.to_string()
804+
.contains("RSA key size must be at least 2048")
805+
);
805806
}
806807

807808
#[test]

src/cli/bssh.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,12 @@ pub enum Commands {
444444
impl Cli {
445445
pub fn get_command(&self) -> String {
446446
// In multi-server mode with destination, treat destination as first command arg
447-
if self.is_multi_server_mode() {
448-
if let Some(dest) = &self.destination {
449-
let mut all_args = vec![dest.clone()];
450-
all_args.extend(self.command_args.clone());
451-
return all_args.join(" ");
452-
}
447+
if self.is_multi_server_mode()
448+
&& let Some(dest) = &self.destination
449+
{
450+
let mut all_args = vec![dest.clone()];
451+
all_args.extend(self.command_args.clone());
452+
return all_args.join(" ");
453453
}
454454
if !self.command_args.is_empty() {
455455
self.command_args.join(" ")
@@ -567,10 +567,10 @@ impl Cli {
567567

568568
// Check SSH options for Port=
569569
for opt in &self.ssh_options {
570-
if let Some(port_str) = opt.strip_prefix("Port=") {
571-
if let Ok(port) = port_str.parse::<u16>() {
572-
return Some(port);
573-
}
570+
if let Some(port_str) = opt.strip_prefix("Port=")
571+
&& let Ok(port) = port_str.parse::<u16>()
572+
{
573+
return Some(port);
574574
}
575575
}
576576

src/cli/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ pub use bssh::{Cli, Commands};
4444

4545
// Re-export pdsh compatibility utilities
4646
pub use pdsh::{
47-
has_pdsh_compat_flag, is_pdsh_compat_mode, remove_pdsh_compat_flag, PdshCli, QueryResult,
48-
PDSH_COMPAT_ENV_VAR,
47+
PDSH_COMPAT_ENV_VAR, PdshCli, QueryResult, has_pdsh_compat_flag, is_pdsh_compat_mode,
48+
remove_pdsh_compat_flag,
4949
};

0 commit comments

Comments
 (0)