ronantakizawa/codereview-bench huggingface dataset:
Repository: sxyazi/yazi
File: yazi-cli/src/package/deploy.rs (Rust)

Code before:
use super::Dependency;

impl Dependency {
	pub(super) async fn deploy(&mut self) -> Result<()> {
		let from = self.local().join(&self.child);

		self.header("Deploying package `{name}`")?;
		self.is_flavor = maybe_exists(&from.join("flavor.toml")).await;

		let to = self.target();
		if maybe_exists(&to).await && self.hash != self.hash().await? {
			bail!(
				"You have modified the contents of the `{}` {}. For safety, the operation has been aborted.
Please manually delete it from `{}` and re-run the command.",
				self.name,
				if self.is_flavor { "flavor" } else { "plugin" },
				to.display()
			);
		}

		fs::create_dir_all(&to).await?;
		if let Err(e) = Self::deploy_sources(&from, &to, self.is_flavor).await {
			remove_dir_clean(&to).await;
			return Err(e);
		}

		self.delete_assets().await?;
		Self::deploy_assets(from.join("assets"), to.join("assets")).await?;

		self.hash = self.hash().await?;
		outln!("Done!")?;

		Ok(())
	}

	async fn deploy_sources(from: &Path, to: &Path, is_flavor: bool) -> Result<()> {
		let files = if is_flavor {
			&["flavor.toml", "tmtheme.xml", "README.md", "preview.png", "LICENSE", "LICENSE-tmtheme"][..]
		} else {
			&["main.lua", "README.md", "LICENSE"][..]
		};

		for file in files {
			let (from, to) = (from.join(file), to.join(file));
			copy_and_seal(&from, &to)
				.await
				.with_context(|| format!("failed to copy `{}` to `{}`", from.display(), to.display()))?;
		}
		Ok(())
	}


Review comment (suggestion):
Removing the target directory 'to' unconditionally here may delete deployed files even after successful operations. Consider executing this cleanup only when a deployment error is detected.

Code after:
use super::Dependency;

impl Dependency {
	pub(super) async fn deploy(&mut self) -> Result<()> {
		let from = self.local().join(&self.child);

		self.header("Deploying package `{name}`")?;
		self.is_flavor = maybe_exists(&from.join("flavor.toml")).await;

		let to = self.target();
		let exists = maybe_exists(&to).await;
		if exists {
			self.hash_check().await?;
		}

		fs::create_dir_all(&to).await?;
		self.delete_assets().await?;

		let res1 = Self::deploy_assets(from.join("assets"), to.join("assets")).await;
		let res2 = Self::deploy_sources(&from, &to, self.is_flavor).await;
		if !exists && (res2.is_err() || res1.is_err()) {
			self.delete_assets().await?;
			self.delete_sources().await?;
		}

		remove_dir_clean(&to).await;
		self.hash = self.hash().await?;
		res2?;
		res1?;

		outln!("Done!")?;
		Ok(())
	}

	async fn deploy_assets(from: PathBuf, to: PathBuf) -> Result<()> {
		match fs::read_dir(&from).await {
			Ok(mut it) => {
				fs::create_dir_all(&to).await?;
				while let Some(entry) = it.next_entry().await? {
					let (src, dist) = (entry.path(), to.join(entry.file_name()));
					copy_and_seal(&src, &dist).await.with_context(|| {
						format!("failed to copy `{}` to `{}`", src.display(), dist.display())
					})?;
				}
			}
			Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
			Err(e) => Err(e).context(format!("failed to read `{}`", from.display()))?,
		}
		Ok(())
	}
Repository: sxyazi/yazi
File: yazi-binding/src/macros.rs (Rust)

Code before:
#[macro_export]
macro_rules! cached_field {
	($fields:ident, $key:ident, $value:expr) => {
		$fields.add_field_function_get(stringify!($key), |lua, ud| {
			use mlua::IntoLua;
			ud.borrow_mut_scoped::<Self, mlua::Result<mlua::Value>>(|me| {
				match paste::paste! { &me.[<v_ $key>] } {
					Some(v) => Ok(v.clone()),
					None => {
						let v: mlua::Result<_> = $value(lua, me);
						let v = v?.into_lua(lua)?;
						paste::paste! { me.[<v_ $key>] = Some(v.clone()) };
						Ok(v)
					}
				}
			})?
		});
	};
}


Review comment (suggestion):
The explicit cast to a function pointer may limit caching to closures that don't capture environment. Consider relaxing this constraint or documenting the requirement to support only pure function pointers.
```suggestion
					let v = $value(lua, me)?.into_lua(lua)?;
```

Code after:
#[macro_export]
macro_rules! cached_field {
	($fields:ident, $key:ident, $value:expr) => {
		$fields.add_field_function_get(stringify!($key), |lua, ud| {
			use mlua::{Error::UserDataDestructed, IntoLua, Lua, Result, Value, Value::UserData};
			ud.borrow_mut_scoped::<Self, Result<Value>>(|me| match paste::paste! { &me.[<v_ $key>] } {
				Some(v) if !v.is_userdata() => Ok(v.clone()),
				Some(v @ UserData(ud)) if !matches!(ud.borrow::<()>(), Err(UserDataDestructed)) => {
					Ok(v.clone())
				}
				_ => {
					let v = ($value as fn(&Lua, &Self) -> Result<_>)(lua, me)?.into_lua(lua)?;
					paste::paste! { me.[<v_ $key>] = Some(v.clone()) };
					Ok(v)
				}
			})?
		});
	};
}
Repository: sxyazi/yazi
File: yazi-adapter/src/dimension.rs (Rust)

Code before:
use std::mem;

use crossterm::terminal::WindowSize;

use crate::EMULATOR;

pub struct Dimension;

impl Dimension {
	pub fn available() -> WindowSize {
		let mut size = WindowSize { rows: 0, columns: 0, width: 0, height: 0 };
		if let Ok(s) = crossterm::terminal::window_size() {
			_ = mem::replace(&mut size, s);
		}

		if size.rows == 0 || size.columns == 0 {
			if let Ok((cols, rows)) = crossterm::terminal::size() {
				size.columns = cols;
				size.rows = rows;
			}
		}

		// TODO: Use `CSI 14 t` to get the actual size of the terminal
		// if size.width == 0 || size.height == 0 {}

		size
	}

	#[inline]
	pub fn ratio() -> Option<(f64, f64)> {
		let s = Self::available();
		Some(if s.width == 0 || s.height == 0 {
			let s = EMULATOR.get().cell_size?;
			(s.0 as f64, s.1 as f64)
		} else {
			(f64::from(s.width) / f64::from(s.columns), f64::from(s.height) / f64::from(s.rows))
		})
	}
}


Review comment (suggestion):
The use of 'None?' in the cell_size function is problematic as it is wrapped inside a 'Some' block, which may lead to unintended behavior. Consider restructuring the if-else chain to return an Option directly instead of using 'Some(if ... None?)'.

Code after:
				size.rows = rows;
			}
		}

		size.into()
	}

	pub fn ratio(self) -> Option<(f64, f64)> {
		if self.rows == 0 || self.columns == 0 || self.width == 0 || self.height == 0 {
			None
		} else {
			Some((self.width as f64 / self.columns as f64, self.height as f64 / self.rows as f64))
		}
	}

	pub fn cell_size() -> Option<(f64, f64)> {
		let emu = EMULATOR.get();
		Some(if emu.force_16t {
			(emu.csi_16t.0 as f64, emu.csi_16t.1 as f64)
		} else if let Some(r) = Self::available().ratio() {
			r
		} else if emu.csi_16t.0 != 0 && emu.csi_16t.1 != 0 {
			(emu.csi_16t.0 as f64, emu.csi_16t.1 as f64)
		} else {
			None?
		})
	}
}
Repository: sxyazi/yazi
File: yazi-fs/src/cwd.rs (Rust)

Code before:
impl Deref for Cwd {
	type Target = ArcSwap<Url>;

	fn deref(&self) -> &Self::Target { &self.0 }
}

impl Default for Cwd {
	fn default() -> Self {
		let p = std::env::var_os("PWD")
			.map(PathBuf::from)
			.filter(|p| p.is_absolute())
			.or_else(|| current_dir().ok())
			.expect("failed to get current working directory");

		Self(ArcSwap::new(Arc::new(Url::from(p))))
	}
}

impl Cwd {
	pub fn set(&self, url: &Url) -> bool {
		if self.load().as_ref() == url {
			return false;
		}

		self.store(Arc::new(url.clone()));
		std::env::set_var("PWD", url);

		Self::sync_cwd();
		true
	}

	fn sync_cwd() {
		static SYNCING: AtomicBool = AtomicBool::new(false);
		if SYNCING.swap(true, atomic::Ordering::Relaxed) {
			return;
		}

		tokio::task::spawn_blocking(move || {
			_ = set_current_dir(CWD.load().as_ref());
			let p = current_dir().unwrap_or_default();

			SYNCING.store(false, atomic::Ordering::Relaxed);
			if p != CWD.load().as_path() {
				set_current_dir(CWD.load().as_ref()).ok();
			}
		});
	}
}


Review comment (suggestion):
std::env::set_var is a safe function; wrapping it in an unsafe block is unnecessary and could confuse readers. Consider removing the unsafe block.
```suggestion
		std::env::set_var("PWD", url);
```

Code after:
impl Deref for Cwd {
	type Target = ArcSwap<Url>;

	fn deref(&self) -> &Self::Target { &self.0 }
}

impl Default for Cwd {
	fn default() -> Self {
		let p = std::env::var_os("PWD")
			.map(PathBuf::from)
			.filter(|p| p.is_absolute())
			.or_else(|| current_dir().ok())
			.expect("failed to get current working directory");

		Self(ArcSwap::new(Arc::new(Url::from(p))))
	}
}

impl Cwd {
	pub fn set(&self, url: &Url) -> bool {
		if self.load().as_ref() == url {
			return false;
		}

		self.store(Arc::new(url.clone()));
		unsafe { std::env::set_var("PWD", url) };

		Self::sync_cwd();
		true
	}

	fn sync_cwd() {
		static SYNCING: AtomicBool = AtomicBool::new(false);
		if SYNCING.swap(true, atomic::Ordering::Relaxed) {
			return;
		}

		tokio::task::spawn_blocking(move || {
			_ = set_current_dir(CWD.load().as_ref());
			let p = current_dir().unwrap_or_default();

			SYNCING.store(false, atomic::Ordering::Relaxed);
			if p != CWD.load().as_path() {
				set_current_dir(CWD.load().as_ref()).ok();
			}
		});
	}
}
Repository: sxyazi/yazi
File: yazi-dds/src/lib.rs (Rust)

Code before:
#![allow(clippy::option_map_unit_fn)]

yazi_macro::mod_pub!(body);

yazi_macro::mod_flat!(client payload pubsub pump sendable server state stream);

pub fn init() {
	let (tx, rx) = tokio::sync::mpsc::unbounded_channel();

	// Client
	ID.init(yazi_boot::ARGS.client_id.unwrap_or(yazi_shared::Id::unique()));
	PEERS.with(<_>::default);
	QUEUE_TX.init(tx);
	QUEUE_RX.init(rx);

	// Server
	CLIENTS.with(<_>::default);
	STATE.with(<_>::default);

	// Pubsub
	LOCAL.with(<_>::default);
	REMOTE.with(<_>::default);

	// Env
	if let Some(s) = std::env::var("YAZI_ID").ok().filter(|s| !s.is_empty()) {
		std::env::set_var("YAZI_PID", s);
	}
	std::env::set_var("YAZI_ID", ID.to_string());
	std::env::set_var(
		"YAZI_LEVEL",
		(std::env::var("YAZI_LEVEL").unwrap_or_default().parse().unwrap_or(0u16) + 1).to_string(),
	);
}

pub fn serve() {
	Pump::serve();
	Client::serve();
}

pub async fn shutdown() { Pump::shutdown().await; }


Review comment (refactor):
The std::env::set_var calls inside this unsafe block do not require unsafe wrappers since the function is safe. Consider removing the unsafe block to clean up the code.

Code after:
#![allow(clippy::option_map_unit_fn)]

yazi_macro::mod_pub!(body);

yazi_macro::mod_flat!(client payload pubsub pump sendable server state stream);

pub fn init() {
	let (tx, rx) = tokio::sync::mpsc::unbounded_channel();

	// Client
	ID.init(yazi_boot::ARGS.client_id.unwrap_or(yazi_shared::Id::unique()));
	PEERS.with(<_>::default);
	QUEUE_TX.init(tx);
	QUEUE_RX.init(rx);

	// Server
	CLIENTS.with(<_>::default);
	STATE.with(<_>::default);

	// Pubsub
	LOCAL.with(<_>::default);
	REMOTE.with(<_>::default);

	// Env
	unsafe {
		if let Some(s) = std::env::var("YAZI_ID").ok().filter(|s| !s.is_empty()) {
			std::env::set_var("YAZI_PID", s);
		}
		std::env::set_var("YAZI_ID", ID.to_string());
		std::env::set_var(
			"YAZI_LEVEL",
			(std::env::var("YAZI_LEVEL").unwrap_or_default().parse().unwrap_or(0u16) + 1).to_string(),
		);
	}
}

pub fn serve() {
	Pump::serve();
	Client::serve();
}

pub async fn shutdown() { Pump::shutdown().await; }
Repository: sxyazi/yazi
File: yazi-core/src/tab/commands/reveal.rs (Rust)

Code before:
use yazi_fs::{File, FilesOp, expand_path};
use yazi_proxy::MgrProxy;
use yazi_shared::{event::CmdCow, url::Url};

use crate::tab::Tab;

struct Opt {
	target: Url,
}

impl From<CmdCow> for Opt {
	fn from(mut c: CmdCow) -> Self {
		let mut target = c.take_first_url().unwrap_or_default();
		if target.is_regular() {
			target = Url::from(expand_path(&target));
		}

		Self { target }
	}
}
impl From<Url> for Opt {
	fn from(target: Url) -> Self { Self { target } }
}

impl Tab {
	#[yazi_codegen::command]
	pub fn reveal(&mut self, opt: Opt) {
		let Some(parent) = opt.target.parent_url() else {
			return;
		};

		self.cd(parent.clone());
		// TODO
		FilesOp::Creating(parent, vec![File::from_dummy(opt.target.clone(), None)]).emit();
		MgrProxy::hover(Some(opt.target), self.id);
		MgrProxy::peek(false);
	}
}


Review comment (suggestion):
The reveal command currently triggers two separate hover calls—one via 'self.current.hover(child.as_urn())' and then 'self.hover(Some(opt.target))'. This may lead to an unstable hover state; consider consolidating these calls into a single, coherent hover update to ensure consistent behavior.

Code after:
			target = Url::from(expand_path(&target));
		}

		Self { target }
	}
}
impl From<Url> for Opt {
	fn from(target: Url) -> Self { Self { target } }
}

impl Tab {
	#[yazi_codegen::command]
	pub fn reveal(&mut self, opt: Opt) {
		let Some((parent, child)) = opt.target.pair() else {
			return;
		};

		self.cd(parent.clone());
		self.current.hover(child.as_urn());

		if self.hovered().is_none_or(|f| &child != f.urn()) {
			let op = FilesOp::Creating(parent, vec![File::from_dummy(opt.target.clone(), None)]);
			self.current.update_pub(self.id, op);
		}

		self.hover(Some(opt.target));
		MgrProxy::peek(false);
		MgrProxy::watch();
	}
}
Repository: sxyazi/yazi
File: yazi-fs/src/files.rs (Rust)

Code before:
				return;
			}

			let (hidden, items) = self.split_files(files);
			if !items.is_empty() {
				self.revision += 1;
			}

			self.hidden.extend(hidden);
			self.items.extend(items);
			return;
		}

		self.ticket = ticket;
		self.hidden.clear();
		if !self.items.is_empty() {
			self.revision += 1;
			self.items.clear();
		}
	}

	pub fn update_size(&mut self, sizes: HashMap<UrnBuf, u64>) {
		if sizes.is_empty() {
			return;
		}

		if self.sorter.by == SortBy::Size {
			self.revision += 1;
		}
		self.sizes.extend(sizes);
	}

	pub fn update_ioerr(&mut self) {
		self.ticket = FILES_TICKET.next();
		self.hidden.clear();
		self.items.clear();
	}

	pub fn update_creating(&mut self, files: Vec<File>) {
		if files.is_empty() {
			return;
		}

		macro_rules! go {
			($dist:expr, $src:expr, $inc:literal) => {
				let mut todo: HashMap<_, _> = $src.into_iter().map(|f| (f.urn_owned(), f)).collect();
				for f in &$dist {
					if todo.remove(f.urn()).is_some() && todo.is_empty() {
						break;
					}
				}

Review comment (suggestion):
The conditional filtering using the magic number '50' may be unclear; please add a comment explaining the rationale behind updating sizes only when sizes.len() is less than or equal to 50.
```suggestion
		// Only update sizes if the number of updates is small (<= 50) to avoid excessive processing.
		if sizes.len() <= 50 {
			sizes.retain(|k, v| self.sizes.get(k) != Some(v));
		}
```

Code after:
				return;
			}

			let (hidden, items) = self.split_files(files);
			if !items.is_empty() {
				self.revision += 1;
			}

			self.hidden.extend(hidden);
			self.items.extend(items);
			return;
		}

		self.ticket = ticket;
		self.hidden.clear();
		if !self.items.is_empty() {
			self.revision += 1;
			self.items.clear();
		}
	}

	pub fn update_size(&mut self, mut sizes: HashMap<UrnBuf, u64>) {
		if sizes.len() <= 50 {
			sizes.retain(|k, v| self.sizes.get(k) != Some(v));
		}

		if sizes.is_empty() {
			return;
		}

		if self.sorter.by == SortBy::Size {
			self.revision += 1;
		}
		self.sizes.extend(sizes);
	}

	pub fn update_ioerr(&mut self) {
		self.ticket = FILES_TICKET.next();
		self.hidden.clear();
		self.items.clear();
	}

	pub fn update_creating(&mut self, files: Vec<File>) {
		if files.is_empty() {
			return;
		}

		macro_rules! go {
			($dist:expr, $src:expr, $inc:literal) => {
				let mut todo: HashMap<_, _> = $src.into_iter().map(|f| (f.urn_owned(), f)).collect();
				for f in &$dist {
Repository: sxyazi/yazi
File: yazi-core/src/tab/commands/copy.rs (Rust)

Code before:
use crate::tab::Tab;

struct Opt {
	type_:     Cow<'static, str>,
	separator: Separator,
}

impl From<CmdCow> for Opt {
	fn from(mut c: CmdCow) -> Self {
		Self {
			type_:     c.take_first_str().unwrap_or_default(),
			separator: c.str("separator").unwrap_or_default().into(),
		}
	}
}

impl Tab {
	#[yazi_codegen::command]
	pub fn copy(&mut self, opt: Opt) {
		if !self.try_escape_visual() {
			return;
		}

		let mut s = OsString::new();
		let mut it = self.selected_or_hovered().peekable();
		while let Some(u) = it.next() {
			s.push(match opt.type_.as_ref() {
				"path" => opt.separator.transform(u),
				"dirname" => opt.separator.transform(u.parent().unwrap_or(Path::new(""))),
				"filename" => opt.separator.transform(u.name()),
				"name_without_ext" => opt.separator.transform(u.file_stem().unwrap_or_default()),
				_ => return,
			});
			if it.peek().is_some() {
				s.push("\n");
			}
		}

		// Copy the CWD path regardless even if the directory is empty
		if s.is_empty() && opt.type_ == "dirname" {
			s.push(self.cwd());
		}

		futures::executor::block_on(CLIPBOARD.set(s));
	}
}

// --- Separator
#[derive(Clone, Copy, PartialEq, Eq)]
enum Separator {
	Auto,

Review comment (suggestion):
[nitpick] Consider adding a brief comment to explain why a Box::new is used to unify different iterator types when opting for the hovered file, to aid future maintainability.
```suggestion
		let mut s = OsString::new();
		// Use Box::new to unify different iterator types, as Rust requires all branches
		// of an if expression to return the same type.
```

Code after:
use crate::tab::Tab;

struct Opt {
	type_:     Cow<'static, str>,
	separator: Separator,
	hovered:   bool,
}

impl From<CmdCow> for Opt {
	fn from(mut c: CmdCow) -> Self {
		Self {
			type_:     c.take_first_str().unwrap_or_default(),
			separator: c.str("separator").unwrap_or_default().into(),
			hovered:   c.bool("hovered"),
		}
	}
}

impl Tab {
	#[yazi_codegen::command]
	pub fn copy(&mut self, opt: Opt) {
		if !self.try_escape_visual() {
			return;
		}

		let mut s = OsString::new();
		let mut it = if opt.hovered {
			Box::new(self.hovered().map(|h| &h.url).into_iter())
		} else {
			self.selected_or_hovered()
		}
		.peekable();

		while let Some(u) = it.next() {
			s.push(match opt.type_.as_ref() {
				"path" => opt.separator.transform(u),
				"dirname" => opt.separator.transform(u.parent().unwrap_or(Path::new(""))),
				"filename" => opt.separator.transform(u.name()),
				"name_without_ext" => opt.separator.transform(u.file_stem().unwrap_or_default()),
				_ => return,
			});
			if it.peek().is_some() {
				s.push("\n");
			}
		}

		// Copy the CWD path regardless even if the directory is empty
		if s.is_empty() && opt.type_ == "dirname" {
			s.push(self.cwd());
		}
Repository: sxyazi/yazi
File: yazi-plugin/preset/components/entity.lua (Lua)

Code before:
function Entity:redraw()
	local lines = {}
	for _, c in ipairs(self._children) do
		lines[#lines + 1] = (type(c[1]) == "string" and self[c[1]] or c[1])(self)
	end
	return ui.Line(lines):style(self:style())
end

function Entity:style()
	local s = self._file:style()
	if not self._file.is_hovered then
		return s
	elseif self._file.in_preview then
		return s and s:patch(th.mgr.preview_hovered) or th.mgr.preview_hovered
	else
		return s and s:patch(th.mgr.hovered) or th.mgr.hovered
	end
end

-- Children
function Entity:children_add(fn, order)
	self._inc = self._inc + 1
	self._children[#self._children + 1] = { fn, id = self._inc, order = order }
	table.sort(self._children, function(a, b) return a.order < b.order end)
	return self._inc
end

function Entity:children_remove(id)
	for i, child in ipairs(self._children) do
		if child.id == id then
			table.remove(self._children, i)
			break
		end
	end
end


Review comment (suggestion):
[nitpick] This chained boolean-and fallback logic is hard to read and may have Lua truthiness pitfalls. Consider rewriting as an explicit `if not f.cha.is_dir and f.url.ext then return "…."..f.url.ext else return "…" end`.
```suggestion
			if not f.cha.is_dir and f.url.ext then
				return "…." .. f.url.ext
			else
				return "…"
			end
```

Code after:
function Entity:redraw()
	local lines = {}
	for _, c in ipairs(self._children) do
		local line = ui.Line((type(c[1]) == "string" and self[c[1]] or c[1])(self))
		c.width, lines[#lines + 1] = line:width(), line
	end
	return ui.Line(lines):style(self:style())
end

function Entity:style()
	local s = self._file:style()
	if not self._file.is_hovered then
		return s
	elseif self._file.in_preview then
		return s and s:patch(th.mgr.preview_hovered) or th.mgr.preview_hovered
	else
		return s and s:patch(th.mgr.hovered) or th.mgr.hovered
	end
end

function Entity:ellipsis(max)
	local adv, f = 0, self._file
	for _, child in ipairs(self._children) do
		adv = adv + child.width
		if adv > max then
			return not f.cha.is_dir and f.url.ext and "…." .. f.url.ext or "…"
		elseif child.id == 4 then
			break
		end
	end
	return "…"
end

-- Children
function Entity:children_add(fn, order)
	self._inc = self._inc + 1
	self._children[#self._children + 1] = { fn, id = self._inc, order = order }
	table.sort(self._children, function(a, b) return a.order < b.order end)
	return self._inc
end

function Entity:children_remove(id)
	for i, child in ipairs(self._children) do
		if child.id == id then
			table.remove(self._children, i)
			break
		end
	end
end
Repository: sxyazi/yazi
File: yazi-fm/src/app/commands/quit.rs (Rust)

Code before:
use std::ffi::OsString;

use yazi_boot::ARGS;
use yazi_shared::event::EventQuit;

use crate::{Term, app::App};

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);
		}

		Term::goodbye(|| opt.code);
	}

	fn cwd_to_file(&self) {
		if let Some(p) = &ARGS.cwd_file {
			let cwd = self.cx.mgr.cwd().as_os_str();
			std::fs::write(p, cwd.as_encoded_bytes()).ok();
		}
	}

	fn selected_to_file(&self, selected: OsString) {
		if let Some(p) = &ARGS.chooser_file {
			std::fs::write(p, selected.as_encoded_bytes()).ok();
		}
	}
}


Review comment (bug):
The use of `futures::join!` silently ignores the results (including errors) from shutdown and state drain. Consider using `futures::try_join!` or explicitly handling each result to surface failures rather than dropping them.
```suggestion
			if let Err(e) = futures::try_join!(
				yazi_dds::shutdown(),
				yazi_dds::STATE.drain(),
				self.cwd_to_file(opt.no_cwd_file),
				self.selected_to_file(opt.selected)
			) {
				eprintln!("Error during quit operations: {:?}", e);
			}
```

Code after:
use std::ffi::OsString;

use tokio::fs;
use yazi_boot::ARGS;
use yazi_shared::event::EventQuit;

use crate::{Term, app::App};

impl App {
	pub(crate) fn quit(&mut self, opt: EventQuit) -> ! {
		self.cx.tasks.shutdown();
		self.cx.mgr.shutdown();

		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);
	}

	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();
			fs::write(p, cwd.as_encoded_bytes()).await.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();
		}
	}
}