fix: always try to create state directory before draining DDS data (#2769)

This commit is contained in:
三咲雅 misaki masa 2025-05-17 14:25:08 +08:00 committed by GitHub
parent 746c7f5ce9
commit 358524347f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 14 deletions

View file

@ -56,6 +56,7 @@ impl State {
return Ok(());
}
fs::create_dir_all(&BOOT.state_dir).await?;
let mut buf = BufWriter::new(
OpenOptions::new()
.write(true)

View file

@ -1,5 +1,6 @@
use std::ffi::OsString;
use tokio::fs;
use yazi_boot::ARGS;
use yazi_shared::event::EventQuit;
@ -9,29 +10,29 @@ impl App {
pub(crate) fn quit(&mut self, opt: EventQuit) -> ! {
self.cx.tasks.shutdown();
self.cx.mgr.shutdown();
futures::executor::block_on(yazi_dds::shutdown());
futures::executor::block_on(yazi_dds::STATE.drain()).ok();
if !opt.no_cwd_file {
self.cwd_to_file();
}
if let Some(selected) = opt.selected {
self.selected_to_file(selected);
}
futures::executor::block_on(async {
_ = futures::join!(
yazi_dds::shutdown(),
yazi_dds::STATE.drain(),
self.cwd_to_file(opt.no_cwd_file),
self.selected_to_file(opt.selected)
);
});
Term::goodbye(|| opt.code);
}
fn cwd_to_file(&self) {
if let Some(p) = &ARGS.cwd_file {
async fn cwd_to_file(&self, no: bool) {
if let Some(p) = ARGS.cwd_file.as_ref().filter(|_| !no) {
let cwd = self.cx.mgr.cwd().as_os_str();
std::fs::write(p, cwd.as_encoded_bytes()).ok();
fs::write(p, cwd.as_encoded_bytes()).await.ok();
}
}
fn selected_to_file(&self, selected: OsString) {
if let Some(p) = &ARGS.chooser_file {
std::fs::write(p, selected.as_encoded_bytes()).ok();
async fn selected_to_file(&self, selected: Option<OsString>) {
if let (Some(s), Some(p)) = (selected, &ARGS.chooser_file) {
fs::write(p, s.as_encoded_bytes()).await.ok();
}
}
}