Skip to content

Commit

Permalink
Fix split_mount_point()
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanda Vacek committed Nov 6, 2024
1 parent 3f4f994 commit 0973ddb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shvbroker"
version = "3.2.0"
version = "3.2.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
15 changes: 9 additions & 6 deletions src/brokerimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,13 @@ pub(crate) fn state_writer(state: &SharedBrokerState) -> RwLockWriteGuard<Broker
state.write().unwrap()
}
fn split_mount_point(mount_point: &str) -> shvrpc::Result<(&str, &str)> {
let ix = mount_point.rfind('/').ok_or("Empty path ???")?;
let dir = &mount_point[ix + 1 ..];
let prefix = &mount_point[..ix];
Ok((prefix, dir))
if let Some(ix) = mount_point.rfind('/') {
let dir = &mount_point[ix + 1 ..];
let prefix = &mount_point[..ix];
Ok((prefix, dir))
} else {
Ok(("", mount_point))
}
}
impl BrokerImpl {
pub(crate) fn new(config: &BrokerConfig, access: AccessConfig, sql_connection: Option<rusqlite::Connection>) -> Self {
Expand Down Expand Up @@ -993,7 +996,7 @@ impl BrokerImpl {
peer_id,
peer_kind,
sender} => {
info!("New peer, id: {peer_id}.");
debug!("New peer, id: {peer_id}.");
state_writer(&self.state).add_peer(peer_id, peer_kind, sender)?;
let mount_point = state_reader(&self.state).mount_point(peer_id);
if let Some(mount_point) = mount_point {
Expand All @@ -1009,7 +1012,7 @@ impl BrokerImpl {
spawn_and_log_error(Self::on_device_mounted(self.state.clone(), peer_id));
}
BrokerCommand::PeerGone { peer_id } => {
info!("Peer gone, id: {peer_id}.");
debug!("Peer gone, id: {peer_id}.");
let mount_point = state_writer(&self.state).remove_peer(peer_id)?;
if let Some(mount_point) = mount_point {
let (shv_path, dir) = split_mount_point(&mount_point)?;
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@ impl BrokerConfig {
}
impl Default for BrokerConfig {
fn default() -> Self {
let mut child_broker_config = BrokerConnectionConfig::default();
child_broker_config.connection_kind = ConnectionKind::ToChildBroker { shv_root: "".to_string(), mount_point: "".to_string() };
Self {
listen: Listen { tcp: Some("localhost:3755".to_string()), ssl: None },
use_access_db: false,
shv2_compatibility: false,
data_directory: None,
connections: vec![
BrokerConnectionConfig::default(),
child_broker_config,
],
access: AccessConfig {
users: BTreeMap::from([
Expand Down
7 changes: 4 additions & 3 deletions src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub(crate) fn next_peer_id() -> i64 {
pub(crate) async fn try_server_peer_loop(peer_id: PeerId, broker_writer: Sender<BrokerCommand>, stream: TcpStream) -> shvrpc::Result<()> {
match server_peer_loop(peer_id, broker_writer.clone(), stream).await {
Ok(_) => {
info!("Client loop exit OK, peer id: {peer_id}");
debug!("Client loop exit OK, peer id: {peer_id}");
}
Err(e) => {
info!("Client loop exit ERROR, peer id: {peer_id}, error: {e}");
debug!("Client loop exit ERROR, peer id: {peer_id}, error: {e}");
}
}
broker_writer.send(BrokerCommand::PeerGone { peer_id }).await?;
Expand Down Expand Up @@ -135,7 +135,7 @@ pub(crate) async fn server_peer_loop(peer_id: PeerId, broker_writer: Sender<Brok
};
let device_id = device_options.as_map().get("deviceId").map(|v| v.as_str().to_string());
let mount_point = device_options.as_map().get("mountPoint").map(|v| v.as_str().to_string());
debug!("Client ID: {peer_id} login success.");
info!("Client ID: {peer_id} login success.");
let peer_kind = if device_id.is_some() || mount_point.is_some() {
PeerKind::Device {
user,
Expand Down Expand Up @@ -191,6 +191,7 @@ pub(crate) async fn server_peer_loop(peer_id: PeerId, broker_writer: Sender<Brok
}
}
}
info!("Client ID: {peer_id} gone.");
Ok(())
}
pub(crate) async fn client_peer_loop_with_reconnect(peer_id: PeerId, config: BrokerConnectionConfig, broker_writer: Sender<BrokerCommand>) -> shvrpc::Result<()> {
Expand Down
2 changes: 0 additions & 2 deletions src/shvnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ pub const DOT_LOCAL_GRANT: &str = "dot-local";
pub const DOT_LOCAL_DIR: &str = ".local";
pub const DOT_LOCAL_HACK: &str = "dot-local-hack";
pub const DIR_APP: &str = ".app";
pub const DIR_APP_DEVICE: &str = ".app/device";

pub enum DirParam {
Brief,
Full,
Expand Down

0 comments on commit 0973ddb

Please sign in to comment.