troll 0.3.1

The port manager that guards the bridge: permanent claims, expiring leases, and a live view of who listens where.
use std::{
    fs::File,
    future::Future,
    io::{self, Write},
    ops::RangeInclusive,
    path::{Path, PathBuf},
};

use troll_core::{ProbeError, Store};
use troll_probe::{ListenerProbe, SystemProbe};

use crate::error::CliError;

pub fn config_home() -> Result<PathBuf, CliError> {
    Err(CliError::MissingConfigHome)
}

pub fn data_home() -> Result<PathBuf, CliError> {
    Err(CliError::MissingDataHome)
}

pub fn state_home() -> Result<PathBuf, CliError> {
    Err(CliError::MissingStateHome)
}

pub fn open_store(home: impl Into<PathBuf>) -> Store {
    Store::new(home)
}

pub fn private_state_dir(_path: &Path) -> io::Result<()> {
    Err(io::Error::new(
        io::ErrorKind::Unsupported,
        "private state directory setup is unsupported on this platform",
    ))
}

pub(super) fn create_private_file(_path: &Path) -> io::Result<File> {
    Err(io::Error::new(
        io::ErrorKind::Unsupported,
        "private file creation is unsupported on this platform",
    ))
}

pub(super) fn set_private_file_permissions(_file: &File) -> io::Result<()> {
    Ok(())
}

pub fn lock_setup_dir(_dir: &Path) -> io::Result<File> {
    Err(io::Error::new(
        io::ErrorKind::Unsupported,
        "setup directory locking is unsupported on this platform",
    ))
}

pub fn service_log_writer() -> io::Result<Box<dyn Write + Send>> {
    Err(io::Error::new(
        io::ErrorKind::Unsupported,
        "service logging is unsupported on this platform",
    ))
}

pub fn service_shutdown() -> io::Result<impl Future<Output = ()>> {
    Err::<std::future::Pending<()>, _>(io::Error::new(
        io::ErrorKind::Unsupported,
        "service shutdown is unsupported on this platform",
    ))
}

pub fn require_listener_probe(probe: &SystemProbe) -> Result<(), ProbeError> {
    let _ = probe.report()?;
    Ok(())
}

pub fn setup_ephemeral_range() -> Result<Option<RangeInclusive<u16>>, ProbeError> {
    troll_probe::ephemeral_range()
}

pub fn proc_probe() -> SystemProbe {
    SystemProbe::new()
}