Skip to content

Commit

Permalink
Add --server --force flag.
Browse files Browse the repository at this point in the history
* Add a --force flag for server in the case the
socket already exists and you need to forcefully
delete the file.
  • Loading branch information
VasilisManol committed Jan 10, 2025
1 parent ca0e0d6 commit c40faf3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ impl App {
server_name,
self.tx_seqs.clone(),
Arc::clone(&shared_root),
con.launch_args.force,
);
self.shared_root = Some(shared_root);
server
Expand Down
5 changes: 5 additions & 0 deletions src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ pub struct Args {
#[arg(long, value_name = "socket")]
pub listen: Option<String>,

/// Force delete the socket file in case it already exists.
#[cfg(unix)]
#[arg(long)]
pub force: bool,

/// Ask for the current root of the remote broot
#[cfg(unix)]
#[arg(long)]
Expand Down
13 changes: 12 additions & 1 deletion src/net/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@ impl Server {
name: &str,
tx: Sender<Sequence>,
root: Arc<Mutex<PathBuf>>,
force: bool,
) -> Result<Self, NetError> {
let path = super::socket_file_path(name);
if fs::metadata(&path).is_ok() {
return Err(NetError::SocketNotAvailable { path });
if force {
match fs::remove_file(&path){
Ok(_) => {},
Err(e) => {
return Err(NetError::Io{ source: e })
}
}
} else {
return Err(NetError::SocketNotAvailable { path });
}
}

let listener = UnixListener::bind(&path)?;
info!("listening on {}", &path);

Expand Down

0 comments on commit c40faf3

Please sign in to comment.