Ref: Optimiert Geräteadresssuche und integriert Konfigurationsspeicherung bei erfolgreicher Ermittlung von device_ip.
This commit is contained in:
25
src/main.rs
25
src/main.rs
@@ -1,11 +1,11 @@
|
|||||||
use crate::config::get_config;
|
use crate::config::{get_config, modify_config, Storage};
|
||||||
use crate::filesystem::credentials::save_credentials_webdav;
|
use crate::filesystem::credentials::save_credentials_webdav;
|
||||||
use crate::filesystem::mount::{mount, unmount};
|
use crate::filesystem::mount::{mount, unmount};
|
||||||
use crate::filesystem::mounted::{is_mounted, is_mounted_as};
|
use crate::filesystem::mounted::{is_mounted, is_mounted_as};
|
||||||
use crate::log::log;
|
use crate::log::log;
|
||||||
use crate::log::LogLevel;
|
use crate::log::LogLevel;
|
||||||
use crate::network::network_interface::{get_active_network_interface, get_interface_ip_address};
|
use crate::network::network_interface::{get_active_network_interface, get_interface_ip_address};
|
||||||
use crate::network::utils::{get_ip_from_mac, get_network_address, is_reachable, wake_on_land};
|
use crate::network::utils::{get_ip_from_mac, get_mac_from_ip, get_network_address, is_reachable, wake_on_land};
|
||||||
use crate::sudo::{is_run_as_root, run_as_root};
|
use crate::sudo::{is_run_as_root, run_as_root};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
@@ -83,15 +83,29 @@ fn mount_local(network_address: String) {
|
|||||||
let mount_point: &str = get_config().general.mount_point.as_str();
|
let mount_point: &str = get_config().general.mount_point.as_str();
|
||||||
|
|
||||||
let mac_address: &str = get_config().local.device_mac.as_str();
|
let mac_address: &str = get_config().local.device_mac.as_str();
|
||||||
let mount_type: &str = &get_config().local.mount_type.as_str();
|
let mount_type: &str = get_config().local.mount_type.as_str();
|
||||||
|
|
||||||
|
let mut device_address: Option<String> = None;
|
||||||
|
|
||||||
|
if get_config().storage.is_some() {
|
||||||
|
device_address = Some(get_config().storage.clone().unwrap().device_ip);
|
||||||
|
|
||||||
|
if !is_reachable(device_address.clone().unwrap().as_str()) && get_mac_from_ip(device_address.clone().unwrap().as_str()).unwrap() != mac_address {
|
||||||
|
device_address = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut device_address: Option<String>;
|
|
||||||
let mut count: i32 = 0;
|
let mut count: i32 = 0;
|
||||||
|
|
||||||
|
if device_address.is_none() {
|
||||||
loop {
|
loop {
|
||||||
device_address = get_ip_from_mac(mac_address, network_address.as_str());
|
device_address = get_ip_from_mac(mac_address, network_address.as_str());
|
||||||
|
|
||||||
if device_address.is_some() || count >= 10 {
|
if device_address.is_some() || count >= 10 {
|
||||||
|
modify_config(|config| {
|
||||||
|
let storage = config.storage.get_or_insert(Storage::default());
|
||||||
|
storage.device_ip = device_address.clone().unwrap();
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +116,7 @@ fn mount_local(network_address: String) {
|
|||||||
count = count + 1;
|
count = count + 1;
|
||||||
sleep(Duration::from_secs(30));
|
sleep(Duration::from_secs(30));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if device_address.is_none() {
|
if device_address.is_none() {
|
||||||
log("main", "Couldn't find device address for MAC address.", LogLevel::Warn);
|
log("main", "Couldn't find device address for MAC address.", LogLevel::Warn);
|
||||||
|
|||||||
Reference in New Issue
Block a user