From fc0aca09a5f5c07fccbe06673dc6244b5a9f8853 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sat, 13 Nov 2021 10:56:50 +0000 Subject: [PATCH] Refactor get_hostname --- datman/src/bin/datman.rs | 5 +---- datman/src/commands/ilabel.rs | 6 ++---- datman/src/lib.rs | 7 +++++++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/datman/src/bin/datman.rs b/datman/src/bin/datman.rs index c4c9963..2b69457 100644 --- a/datman/src/bin/datman.rs +++ b/datman/src/bin/datman.rs @@ -182,10 +182,7 @@ fn main() -> anyhow::Result<()> { source_name, destination_name, } => { - let my_hostname = hostname::get() - .expect("No hostname") - .into_string() - .expect("Hostname string must be sensible."); + let my_hostname = get_hostname(); let descriptor = load_descriptor(Path::new(".")).unwrap(); let source = &descriptor.source[&source_name]; let destination = &descriptor.piles[&destination_name]; diff --git a/datman/src/commands/ilabel.rs b/datman/src/commands/ilabel.rs index 0e3b77a..e5b45f3 100644 --- a/datman/src/commands/ilabel.rs +++ b/datman/src/commands/ilabel.rs @@ -32,6 +32,7 @@ use crate::labelling::{ use crate::tree::{scan, FileTree, FileTree1}; use log::info; +use crate::get_hostname; use crate::remote::backup_source_requester; use crate::remote::backup_source_requester::connect_to_remote; use anyhow::{anyhow, bail}; @@ -187,10 +188,7 @@ pub fn interactive_labelling_session(path: &Path, source_name: String) -> anyhow directory, } = source { - let my_hostname = hostname::get() - .expect("No hostname") - .into_string() - .expect("Hostname string must be sensible."); + let my_hostname = get_hostname(); let mut dir_scan = if &my_hostname == hostname { info!("Scanning source; this might take a little while..."); scan(directory)? diff --git a/datman/src/lib.rs b/datman/src/lib.rs index ab23eaf..91475d3 100644 --- a/datman/src/lib.rs +++ b/datman/src/lib.rs @@ -3,3 +3,10 @@ pub mod descriptor; pub mod labelling; pub mod remote; pub mod tree; + +pub fn get_hostname() -> String { + hostname::get() + .expect("No hostname") + .into_string() + .expect("Hostname string must be sensible.") +}