A string path local socket name returns false for is_supported but true for is_always_supported
Describe the bug When I attempted to create a LocalSocketName on my Linux machine and verify that it was supported, I got the following error. According to the panic output, is_always_supported is true, but is_supported is false which seem to be backwards.
thread 'main' panicked at 'Unable to create socket name LocalSocketName {
is_namespaced: false,
is_path: true,
is_supported: false,
is_always_supported: true,
inner_os_string: "/tmp/cfg2vec",
}'
To Reproduce
use std::fmt::{Debug, Formatter};
use interprocess::local_socket::{LocalSocketName, ToLocalSocketName};
struct Lsn<'a>(LocalSocketName<'a>);
impl <'a> Debug for Lsn<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("LocalSocketName")
.field("is_namespaced", &self.0.is_namespaced())
.field("is_path", &self.0.is_path())
.field("is_supported", &self.0.is_supported())
.field("is_always_supported", &self.0.is_always_supported())
.field("inner_os_string", &self.0.inner())
.finish()
}
}
fn main() {
#[cfg(unix)]
let socket_name = "/tmp/cfg2vec".to_local_socket_name().unwrap();
// let socket_name = "@/tmp/cfg2vec".to_local_socket_name().unwrap();
if !socket_name.is_supported() {
panic!("Unable to create socket name {:#?}", Lsn(socket_name));
}
println!("Hello, world! {:#?}", Lsn(socket_name));
}
Expected behavior I expected this to print Hello, world!, not panic. If I'm misunderstanding something, any explanation would also be welcome.
Yup, that's a really weird typo in is_supported(). No clue how it got there. I'll make sure to fix it in the 1.2.0 release. A quick workaround would be:
use interprocess::local_socket::{LocalSocketName, NameTypeSupport};
fn name_supported(nm: &LocalSocketName<'_>) -> bool {
let nts = NameTypeSupport::query();
(nm.is_path() && nts.paths_supported())
|| (nm.is_namespaced() && nts.namespace_supported())
}
(is_supported() is implemented in almost the same way, but there's a typo that makes it always report paths as unsupported.)
1.2.0 is finally out, so I'm closing this one!