fix(startup): do not parse resurrectable sessions on startup (#3505)
* fix(startup): do not parse resurrectable sessions on startup * style(fmt): rustfmt
This commit is contained in:
parent
206ea3230b
commit
4df7b42766
2 changed files with 38 additions and 9 deletions
|
|
@ -3,9 +3,10 @@ use std::{fs::File, io::prelude::*, path::PathBuf, process, time::Duration};
|
|||
|
||||
use crate::sessions::{
|
||||
assert_dead_session, assert_session, assert_session_ne, delete_session as delete_session_impl,
|
||||
get_active_session, get_name_generator, get_resurrectable_sessions, get_sessions,
|
||||
get_sessions_sorted_by_mtime, kill_session as kill_session_impl, match_session_name,
|
||||
print_sessions, print_sessions_with_index, resurrection_layout, session_exists, ActiveSession,
|
||||
get_active_session, get_name_generator, get_resurrectable_session_names,
|
||||
get_resurrectable_sessions, get_sessions, get_sessions_sorted_by_mtime,
|
||||
kill_session as kill_session_impl, match_session_name, print_sessions,
|
||||
print_sessions_with_index, resurrection_layout, session_exists, ActiveSession,
|
||||
SessionNameMatch,
|
||||
};
|
||||
use zellij_client::{
|
||||
|
|
@ -673,10 +674,7 @@ fn generate_unique_session_name() -> String {
|
|||
.map(|s| s.0.clone())
|
||||
.collect::<Vec<String>>()
|
||||
});
|
||||
let dead_sessions: Vec<String> = get_resurrectable_sessions()
|
||||
.iter()
|
||||
.map(|(s, _, _)| s.clone())
|
||||
.collect();
|
||||
let dead_sessions = get_resurrectable_session_names();
|
||||
let Ok(sessions) = sessions else {
|
||||
eprintln!("Failed to list existing sessions: {:?}", sessions);
|
||||
process::exit(1);
|
||||
|
|
|
|||
|
|
@ -97,6 +97,37 @@ pub(crate) fn get_resurrectable_sessions() -> Vec<(String, Duration, Layout)> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_resurrectable_session_names() -> Vec<String> {
|
||||
match fs::read_dir(&*ZELLIJ_SESSION_INFO_CACHE_DIR) {
|
||||
Ok(files_in_session_info_folder) => {
|
||||
let files_that_are_folders = files_in_session_info_folder
|
||||
.filter_map(|f| f.ok().map(|f| f.path()))
|
||||
.filter(|f| f.is_dir());
|
||||
files_that_are_folders
|
||||
.filter_map(|folder_name| {
|
||||
let folder = folder_name.display().to_string();
|
||||
let resurrection_layout_file = session_layout_cache_file_name(&folder);
|
||||
if std::path::Path::new(&resurrection_layout_file).exists() {
|
||||
folder_name
|
||||
.file_name()
|
||||
.map(|f| format!("{}", f.to_string_lossy()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
},
|
||||
Err(e) => {
|
||||
log::error!(
|
||||
"Failed to read session_info cache folder: \"{:?}\": {:?}",
|
||||
&*ZELLIJ_SESSION_INFO_CACHE_DIR,
|
||||
e
|
||||
);
|
||||
vec![]
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_sessions_sorted_by_mtime() -> anyhow::Result<Vec<String>> {
|
||||
match fs::read_dir(&*ZELLIJ_SOCK_DIR) {
|
||||
Ok(files) => {
|
||||
|
|
@ -407,8 +438,8 @@ pub(crate) fn assert_session_ne(name: &str) {
|
|||
|
||||
match session_exists(name) {
|
||||
Ok(result) if !result => {
|
||||
let resurrectable_sessions = get_resurrectable_sessions();
|
||||
if resurrectable_sessions.iter().find(|(s, _, _)| s == name).is_some() {
|
||||
let resurrectable_sessions = get_resurrectable_session_names();
|
||||
if resurrectable_sessions.iter().find(|s| s == &name).is_some() {
|
||||
println!("Session with name {:?} already exists, but is dead. Use the attach command to resurrect it or, the delete-session command to kill it or specify a different name.", name);
|
||||
} else {
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue