mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-22 05:30:24 +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]
|
#[tauri::command]
|
||||||
pub fn get_history(history_type: HistoryType) -> Result<String, ()> {
|
pub fn get_history(history_type: HistoryType) -> Result<String, ()> {
|
||||||
let configurator = Configurator::new();
|
let configurator = Configurator::new();
|
||||||
let history = serde_json::to_string(configurator.get_history(history_type))
|
let history = configurator.get_history(history_type);
|
||||||
.unwrap_or_else(|_| String::from("[]"));
|
// filter out empty string and not exist history path
|
||||||
Ok(history)
|
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]
|
#[tauri::command]
|
||||||
@ -405,4 +420,4 @@ pub fn acrn_remove_file(path: &str) -> Result<(), String> {
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn open_devtools(window: Window) {
|
pub fn open_devtools(window: Window) {
|
||||||
window.open_devtools()
|
window.open_devtools()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user