mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-22 13:37:10 +00:00
config_tools: filter out non-existing history path
filter out non-existing history path Tracked-On: #6691 Signed-off-by: Weiyi Feng <weiyix.feng@intel.com>
This commit is contained in:
parent
3c47f285cc
commit
35e4aed110
@ -283,9 +283,24 @@ static mut WORKING_FOLDER: String = String::new();
|
||||
#[tauri::command]
|
||||
pub fn get_history(history_type: HistoryType) -> Result<String, ()> {
|
||||
let configurator = Configurator::new();
|
||||
let history = serde_json::to_string(configurator.get_history(history_type))
|
||||
.unwrap_or_else(|_| String::from("[]"));
|
||||
Ok(history)
|
||||
let history = configurator.get_history(history_type);
|
||||
// filter out empty string and not exist history path
|
||||
let clean_history: Vec<&String> = match history_type {
|
||||
HistoryType::WorkingFolder => history
|
||||
.into_iter()
|
||||
.filter(|s| !s.is_empty())
|
||||
.filter(|s| Path::new(s).is_dir())
|
||||
.collect::<Vec<_>>(),
|
||||
_ => history
|
||||
.into_iter()
|
||||
.filter(|s| !s.is_empty())
|
||||
.filter(|s| Path::new(s).is_file())
|
||||
.collect::<Vec<_>>(),
|
||||
};
|
||||
|
||||
let history_json_text =
|
||||
serde_json::to_string(&clean_history).unwrap_or_else(|_| String::from("[]"));
|
||||
Ok(history_json_text)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
Loading…
Reference in New Issue
Block a user