ronantakizawa/codereview-bench huggingface dataset:
Repository: sxyazi/yazi
File: yazi-core/src/tab/commands/copy.rs (Rust)

Code before:
		let mut s = OsString::new();
		let mut it = self.selected_or_hovered(true).peekable();
		while let Some(u) = it.next() {
			match opt.type_.as_str() {
				"path" => {
					match path_to_os_str(u, opt.separator) {
						Cow::Borrowed(p) => s.push(p),
						Cow::Owned(p) => s.push(&p),
					};
				}
				"dirname" => {
					if let Some(parent) = u.parent() {
						match path_to_os_str(parent, opt.separator) {
							Cow::Borrowed(p) => s.push(p),
							Cow::Owned(p) => s.push(&p),
						};
					}
				}
				"filename" => {
					s.push(u.name());
				}
				"name_without_ext" => {
					if let Some(stem) = u.file_stem() {
						s.push(stem);
					}
				}
				_ => 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));
	}
}

#[derive(Default, Clone, Copy)]
enum PathSeparator {
	Unix,
	#[default]
	Auto,
}

impl From<&Cmd> for PathSeparator {
	fn from(c: &Cmd) -> Self {

Review comment (suggestion):
I need to use `s.push` inside the match expression to avoid cloning `Cow::Borrowed(p)`. Moving `s.push` outside would require cloning `p` (`Cow::to_owned`) to align types correctly (due to scoping issue with `Cow::Owned(p)`), which defeats the purpose of using a COW string.

Code after:

		let mut s = OsString::new();
		let mut it = self.selected_or_hovered(true).peekable();
		while let Some(u) = it.next() {
			s.push(match opt.type_.as_str() {
				"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,
	Unix,
}

impl From<&str> for Separator {
	fn from(value: &str) -> Self {
		match value {
			"unix" => Self::Unix,
			_ => Self::Auto,
		}
	}
}

impl Separator {
	fn transform<T: AsRef<Path> + ?Sized>(self, p: &T) -> Cow<OsStr> {
		#[cfg(windows)]
		if self == Self::Unix {
			return match yazi_shared::fs::backslash_to_slash(p.as_ref()) {
				Cow::Owned(p) => Cow::Owned(p.into_os_string()),
				Cow::Borrowed(p) => Cow::Borrowed(p.as_os_str()),
			};
		}
		Cow::Borrowed(p.as_ref().as_os_str())
Repository: sxyazi/yazi
File: yazi-dds/src/body/hi.rs (Rust)

Code before:

use mlua::{ExternalResult, IntoLua, Lua, Value};
use serde::{Deserialize, Serialize};

use super::Body;

/// The client handshake
#[derive(Debug, Serialize, Deserialize)]
pub struct BodyHi<'a> {
	/// Specifies the kinds of events that the client can handle
	pub abilities: HashSet<Cow<'a, str>>,
	pub version:   String,
}

impl<'a> BodyHi<'a> {
	#[inline]
	pub fn borrowed(abilities: HashSet<&'a str>) -> Body<'a> {
		Self {
			abilities: abilities.into_iter().map(Cow::Borrowed).collect(),
			version:   Self::version(),
		}
		.into()
	}

	#[inline]
	pub fn version() -> String {
		concat!(env!("CARGO_PKG_VERSION"), " ", env!("VERGEN_GIT_SHA")).to_string()
	}
}

impl<'a> From<BodyHi<'a>> for Body<'a> {
	fn from(value: BodyHi<'a>) -> Self { Self::Hi(value) }
}

impl IntoLua for BodyHi<'_> {
	fn into_lua(self, _: &Lua) -> mlua::Result<Value> {
		Err("BodyHi cannot be converted to Lua").into_lua_err()
	}
}


Review comment (suggestion):
```suggestion
	pub fn version() -> &'static str {
```

Code after:

use mlua::{ExternalResult, IntoLua, Lua, Value};
use serde::{Deserialize, Serialize};

use super::Body;

/// The client handshake
#[derive(Debug, Serialize, Deserialize)]
pub struct BodyHi<'a> {
	/// Specifies the kinds of events that the client can handle
	pub abilities: HashSet<Cow<'a, str>>,
	pub version:   Cow<'static, str>,
}

impl<'a> BodyHi<'a> {
	#[inline]
	pub fn borrowed(abilities: HashSet<&'a str>) -> Body<'a> {
		Self {
			abilities: abilities.into_iter().map(Cow::Borrowed).collect(),
			version:   Self::version().into(),
		}
		.into()
	}

	#[inline]
	pub fn version() -> &'static str {
		concat!(env!("CARGO_PKG_VERSION"), " ", env!("VERGEN_GIT_SHA"))
	}
}

impl<'a> From<BodyHi<'a>> for Body<'a> {
	fn from(value: BodyHi<'a>) -> Self { Self::Hi(value) }
}

impl IntoLua for BodyHi<'_> {
	fn into_lua(self, _: &Lua) -> mlua::Result<Value> {
		Err("BodyHi cannot be converted to Lua").into_lua_err()
	}
}
Repository: sxyazi/yazi
File: yazi-dds/src/body/hey.rs (Rust)

Code before:
use std::collections::HashMap;

use mlua::{ExternalResult, IntoLua, Lua, Value};
use serde::{Deserialize, Serialize};

use super::{Body, BodyHi};
use crate::Peer;

#[derive(Debug, Serialize, Deserialize)]
pub struct BodyHey {
	pub peers:   HashMap<u64, Peer>,
	pub version: String,
}

impl BodyHey {
	#[inline]
	pub fn owned(peers: HashMap<u64, Peer>) -> Body<'static> {
		Self { peers, version: BodyHi::version().to_string() }.into()
	}
}

impl From<BodyHey> for Body<'_> {
	fn from(value: BodyHey) -> Self { Self::Hey(value) }
}

impl IntoLua for BodyHey {
	fn into_lua(self, _: &Lua) -> mlua::Result<Value> {
		Err("BodyHey cannot be converted to Lua").into_lua_err()
	}
}


Review comment (suggestion):
Please also change the `version`'s type to `&'static str` or `Cow<'static, str>`

Code after:
use std::{borrow::Cow, collections::HashMap};

use mlua::{ExternalResult, IntoLua, Lua, Value};
use serde::{Deserialize, Serialize};

use super::{Body, BodyHi};
use crate::Peer;

#[derive(Debug, Serialize, Deserialize)]
pub struct BodyHey {
	pub peers:   HashMap<u64, Peer>,
	pub version: Cow<'static, str>,
}

impl BodyHey {
	#[inline]
	pub fn owned(peers: HashMap<u64, Peer>) -> Body<'static> {
		Self { peers, version: BodyHi::version().into() }.into()
	}
}

impl From<BodyHey> for Body<'_> {
	fn from(value: BodyHey) -> Self { Self::Hey(value) }
}

impl IntoLua for BodyHey {
	fn into_lua(self, _: &Lua) -> mlua::Result<Value> {
		Err("BodyHey cannot be converted to Lua").into_lua_err()
	}
}
Repository: sxyazi/yazi
File: yazi-core/src/input/commands/type_.rs (Rust)

Code before:
use yazi_config::keymap::Key;
use yazi_shared::event::CmdCow;

use crate::input::{Input, InputMode};

struct Opt;

impl From<CmdCow> for Opt {
	fn from(_: CmdCow) -> Self { Self }
}

impl Input {
	pub fn type_(&mut self, key: &Key) -> bool {
		if self.mode() == InputMode::Replace {
			let Some(c) = key.plain() else {
				return false;
			};

			let snap = self.snaps.current_mut();
			snap.mode = InputMode::Normal;
			self.replace_str(c.encode_utf8(&mut [0; 4]));

			return true;
		}

		if self.mode() != InputMode::Insert {
			return false;
		}

		if let Some(c) = key.plain() {
			self.type_str(c.encode_utf8(&mut [0; 4]));
			return true;
		}

		false
	}
}


Review comment (suggestion):
Don't change back to normal mode for special keys.
Only here to fix `<Esc>` being handled twice.

Code after:
use yazi_config::keymap::Key;
use yazi_macro::render;
use yazi_shared::event::CmdCow;

use crate::input::{Input, InputMode};

struct Opt;

impl From<CmdCow> for Opt {
	fn from(_: CmdCow) -> Self { Self }
}

impl Input {
	pub fn type_(&mut self, key: &Key) -> bool {
		let Some(c) = key.plain() else { return false };

		if self.mode() == InputMode::Insert {
			self.type_str(c.encode_utf8(&mut [0; 4]));
			return true;
		} else if self.mode() == InputMode::Replace {
			self.replace_str(c.encode_utf8(&mut [0; 4]));
			return true;
		}

		false
	}

	pub fn type_str(&mut self, s: &str) {
		let snap = self.snap_mut();
		if snap.cursor < 1 {
			snap.value.insert_str(0, s);
		} else {
			snap.value.insert_str(snap.idx(snap.cursor).unwrap(), s);
		}

		self.move_(s.chars().count() as isize);
		self.flush_value();
		render!();
	}
}
Repository: sxyazi/yazi
File: yazi-core/src/input/commands/replace.rs (Rust)

Code before:
use yazi_macro::render;
use yazi_shared::event::CmdCow;

use crate::input::{Input, InputMode, op::InputOp};

impl Input {
	#[yazi_codegen::command]
	pub fn replace(&mut self, _: CmdCow) {
		let snap = self.snap_mut();
		if snap.mode == InputMode::Normal {
			snap.op = InputOp::None;
			snap.mode = InputMode::Replace;
			render!();
		}
	}

	pub fn replace_str(&mut self, s: &str) {
		let snap = self.snap_mut();

		if snap.value.is_empty() {
			snap.mode = InputMode::Normal;
			render!();
			return;
		}

		let start = snap.idx(snap.cursor).unwrap();
		let end = snap.idx(snap.cursor + 1).unwrap();

		snap.mode = InputMode::Normal;
		snap.value.replace_range(start..end, s);

		self.snaps.tag(self.limit()).then(|| self.flush_value());
		render!();
	}
}


Review comment (suggestion):
This matches vim behavior. Alternatively `R` could just be ignored if input is empty.

Code after:
use yazi_macro::render;
use yazi_shared::event::CmdCow;

use crate::input::{Input, InputMode, op::InputOp};

impl Input {
	#[yazi_codegen::command]
	pub fn replace(&mut self, _: CmdCow) {
		let snap = self.snap_mut();
		if snap.mode == InputMode::Normal {
			snap.op = InputOp::None;
			snap.mode = InputMode::Replace;
			render!();
		}
	}

	pub fn replace_str(&mut self, s: &str) {
		let snap = self.snap_mut();
		snap.mode = InputMode::Normal;

		let start = snap.idx(snap.cursor).unwrap();
		let mut it = snap.value[start..].char_indices();
		match (it.next(), it.next()) {
			(None, _) => {}
			(Some(_), None) => snap.value.replace_range(start..snap.len(), s),
			(Some(_), Some((len, _))) => snap.value.replace_range(start..start + len, s),
		}

		render!();
		self.snaps.tag(self.limit()).then(|| self.flush_value());
	}
}
Repository: sxyazi/yazi
File: yazi-cli/src/args.rs (Rust)

Code before:
	/// The name of the command.
	pub(super) name: String,
	/// The arguments of the command.
	#[arg(allow_hyphen_values = true, trailing_var_arg = true)]
	pub(super) args: Vec<String>,
}

#[derive(clap::Args)]
pub(super) struct CommandEmitTo {
	/// The receiver ID.
	pub(super) receiver: u64,
	/// The name of the command.
	pub(super) name:     String,
	/// The arguments of the command.
	#[arg(allow_hyphen_values = true, trailing_var_arg = true)]
	pub(super) args:     Vec<String>,
}

#[derive(clap::Args)]
#[command(arg_required_else_help = true)]
pub(super) struct CommandPack {
	/// Add packages.
	#[arg(short = 'a', long, num_args = 1..)]
	pub(super) add:     Option<Vec<String>>,
	/// Delete a package.
	#[arg(short = 'd', long,num_args = 1..)]
	pub(super) delete:  Option<Vec<String>>,
	/// Install all packages.
	#[arg(short = 'i', long)]
	pub(super) install: bool,
	/// List all packages.
	#[arg(short = 'l', long)]
	pub(super) list:    bool,
	/// Upgrade all packages.
	#[arg(short = 'u', long)]
	pub(super) upgrade: bool,
	/// Migrate all packages.
	#[arg(short = 'm', long)]
	pub(super) migrate: bool, // TODO: remove this
}

#[derive(clap::Args)]
pub(super) struct CommandPub {
	/// The kind of message.
	#[arg(index = 1)]
	pub(super) kind: String,
	/// Send the message with a string body.
	#[arg(long)]
	pub(super) str:  Option<String>,
	/// Send the message with a JSON body.
	#[arg(long)]

Review comment (suggestion):
```suggestion
	#[arg(short = 'd', long, num_args = 1..)]
```

Code after:
	/// The name of the command.
	pub(super) name: String,
	/// The arguments of the command.
	#[arg(allow_hyphen_values = true, trailing_var_arg = true)]
	pub(super) args: Vec<String>,
}

#[derive(clap::Args)]
pub(super) struct CommandEmitTo {
	/// The receiver ID.
	pub(super) receiver: u64,
	/// The name of the command.
	pub(super) name:     String,
	/// The arguments of the command.
	#[arg(allow_hyphen_values = true, trailing_var_arg = true)]
	pub(super) args:     Vec<String>,
}

#[derive(clap::Args)]
#[command(arg_required_else_help = true)]
pub(super) struct CommandPack {
	/// Add packages.
	#[arg(short = 'a', long, num_args = 1..)]
	pub(super) add:     Option<Vec<String>>,
	/// Delete packages.
	#[arg(short = 'd', long, num_args = 1..)]
	pub(super) delete:  Option<Vec<String>>,
	/// Install all packages.
	#[arg(short = 'i', long)]
	pub(super) install: bool,
	/// List all packages.
	#[arg(short = 'l', long)]
	pub(super) list:    bool,
	/// Upgrade all packages.
	#[arg(short = 'u', long)]
	pub(super) upgrade: bool,
	/// Migrate all packages.
	#[arg(short = 'm', long)]
	pub(super) migrate: bool, // TODO: remove this
}

#[derive(clap::Args)]
pub(super) struct CommandPub {
	/// The kind of message.
	#[arg(index = 1)]
	pub(super) kind: String,
	/// Send the message with a string body.
	#[arg(long)]
	pub(super) str:  Option<String>,
	/// Send the message with a JSON body.
	#[arg(long)]
Repository: sxyazi/yazi
File: yazi-cli/src/main.rs (Rust)

Code before:
		}

		Command::EmitTo(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
			if let Err(e) = yazi_dds::Client::shot("dds-emit", cmd.receiver, &cmd.body()?).await {
				errln!("Cannot emit command: {e}")?;
				std::process::exit(1);
			}
		}

		Command::Pack(cmd) => {
			package::init()?;
			package::Package::load().await?.sync().await.ok();
			if cmd.migrate {
				outln!("Migration successful")?;
			} else if cmd.install {
				package::Package::load().await?.install(false).await?;
			} else if cmd.list {
				package::Package::load().await?.print()?;
			} else if cmd.upgrade {
				package::Package::load().await?.install(true).await?;
			} else if let Some(repos) = cmd.add {
				let mut package = package::Package::load().await?;
				for repo in repos {
					package.add(&repo).await?;
				}
			} else if let Some(repos) = cmd.delete {
				let mut package = package::Package::load().await?;
				for repo in repos {
					package.delete(&repo).await?;
				}
			}
		}

		Command::Pub(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
			if let Err(e) = yazi_dds::Client::shot(&cmd.kind, CommandPub::receiver()?, &cmd.body()?).await
			{
				errln!("Cannot send message: {e}")?;
				std::process::exit(1);
			}
		}

		Command::PubTo(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
			if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, &cmd.body()?).await {
				errln!("Cannot send message: {e}")?;
				std::process::exit(1);

Review comment (suggestion):
Please add a new method `add_many` in `yazi-cli/src/package/add.rs` and call it instead

Code after:
		}

		Command::EmitTo(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
			if let Err(e) = yazi_dds::Client::shot("dds-emit", cmd.receiver, &cmd.body()?).await {
				errln!("Cannot emit command: {e}")?;
				std::process::exit(1);
			}
		}

		Command::Pack(cmd) => {
			package::init()?;
			package::Package::load().await?.sync().await.ok();
			if cmd.migrate {
				outln!("Migration successful")?;
			} else if cmd.install {
				package::Package::load().await?.install(false).await?;
			} else if cmd.list {
				package::Package::load().await?.print()?;
			} else if cmd.upgrade {
				package::Package::load().await?.install(true).await?;
			} else if let Some(uses) = cmd.add {
				package::Package::load().await?.add_many(&uses).await?;
			} else if let Some(uses) = cmd.delete {
				package::Package::load().await?.delete_many(&uses).await?;
			}
		}

		Command::Pub(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
			if let Err(e) = yazi_dds::Client::shot(&cmd.kind, CommandPub::receiver()?, &cmd.body()?).await
			{
				errln!("Cannot send message: {e}")?;
				std::process::exit(1);
			}
		}

		Command::PubTo(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
			if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, &cmd.body()?).await {
				errln!("Cannot send message: {e}")?;
				std::process::exit(1);
			}
		}

		Command::Sub(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
Repository: sxyazi/yazi
File: yazi-cli/src/main.rs (Rust)

Code before:
			if let Err(e) = yazi_dds::Client::shot("dds-emit", cmd.receiver, &cmd.body()?).await {
				errln!("Cannot emit command: {e}")?;
				std::process::exit(1);
			}
		}

		Command::Pack(cmd) => {
			package::init()?;
			package::Package::load().await?.sync().await.ok();
			if cmd.migrate {
				outln!("Migration successful")?;
			} else if cmd.install {
				package::Package::load().await?.install(false).await?;
			} else if cmd.list {
				package::Package::load().await?.print()?;
			} else if cmd.upgrade {
				package::Package::load().await?.install(true).await?;
			} else if let Some(repos) = cmd.add {
				let mut package = package::Package::load().await?;
				for repo in repos {
					package.add(&repo).await?;
				}
			} else if let Some(repos) = cmd.delete {
				let mut package = package::Package::load().await?;
				for repo in repos {
					package.delete(&repo).await?;
				}
			}
		}

		Command::Pub(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
			if let Err(e) = yazi_dds::Client::shot(&cmd.kind, CommandPub::receiver()?, &cmd.body()?).await
			{
				errln!("Cannot send message: {e}")?;
				std::process::exit(1);
			}
		}

		Command::PubTo(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
			if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, &cmd.body()?).await {
				errln!("Cannot send message: {e}")?;
				std::process::exit(1);
			}
		}

		Command::Sub(cmd) => {
			yazi_boot::init_default();

Review comment (suggestion):
Please add a new method `delete_many` in `yazi-cli/src/package/delete.rs` and call it instead

Code after:
			if let Err(e) = yazi_dds::Client::shot("dds-emit", cmd.receiver, &cmd.body()?).await {
				errln!("Cannot emit command: {e}")?;
				std::process::exit(1);
			}
		}

		Command::Pack(cmd) => {
			package::init()?;
			package::Package::load().await?.sync().await.ok();
			if cmd.migrate {
				outln!("Migration successful")?;
			} else if cmd.install {
				package::Package::load().await?.install(false).await?;
			} else if cmd.list {
				package::Package::load().await?.print()?;
			} else if cmd.upgrade {
				package::Package::load().await?.install(true).await?;
			} else if let Some(uses) = cmd.add {
				package::Package::load().await?.add_many(&uses).await?;
			} else if let Some(uses) = cmd.delete {
				package::Package::load().await?.delete_many(&uses).await?;
			}
		}

		Command::Pub(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
			if let Err(e) = yazi_dds::Client::shot(&cmd.kind, CommandPub::receiver()?, &cmd.body()?).await
			{
				errln!("Cannot send message: {e}")?;
				std::process::exit(1);
			}
		}

		Command::PubTo(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
			if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, &cmd.body()?).await {
				errln!("Cannot send message: {e}")?;
				std::process::exit(1);
			}
		}

		Command::Sub(cmd) => {
			yazi_boot::init_default();
			yazi_dds::init();
			yazi_dds::Client::draw(cmd.kinds.split(',').collect()).await?;

			tokio::signal::ctrl_c().await?;
		}
	}
Repository: sxyazi/yazi
File: yazi-proxy/src/options/search.rs (Rust)

Code before:
#[derive(PartialEq, Eq)]
pub enum SearchOptVia {
	// TODO: remove `None` in the future
	None,
	Rga,
	Rg,
	Fd,
}

impl From<&str> for SearchOptVia {
	fn from(value: &str) -> Self {
		match value {
			"rg" => Self::Rg,
			"fd" => Self::Fd,
			"rga" => Self::Rga,
			_ => Self::None,
		}
	}
}

impl Display for SearchOptVia {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		f.write_str(match self {
			Self::Rg => "rg",
			Self::Rga => "rga",
			Self::Fd => "fd",
			Self::None => "none",
		})
	}
}


Review comment (suggestion):
```suggestion
			Self::Rg => "rg",
			Self::Fd => "fd",
			Self::Rga => "rga",
```

Code after:
#[derive(PartialEq, Eq)]
pub enum SearchOptVia {
	// TODO: remove `None` in the future
	None,
	Rg,
	Fd,
	Rga,
}

impl From<&str> for SearchOptVia {
	fn from(value: &str) -> Self {
		match value {
			"rg" => Self::Rg,
			"fd" => Self::Fd,
			"rga" => Self::Rga,
			_ => Self::None,
		}
	}
}

impl Display for SearchOptVia {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		f.write_str(match self {
			Self::Rg => "rg",
			Self::Fd => "fd",
			Self::Rga => "rga",
			Self::None => "none",
		})
	}
}
Repository: sxyazi/yazi
File: yazi-cli/src/package/deploy.rs (Rust)

Code before:
use std::path::{Path, PathBuf};

use anyhow::{Context, Result};
use tokio::fs;
use yazi_fs::{copy_and_seal, maybe_exists, remove_dir_clean};
use yazi_macro::outln;

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 maybe_exists(&to).await {
			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;

		remove_dir_clean(&to).await;
		if !exists && (res2.is_err() || res1.is_err()) {
			self.delete_assets().await?;
			self.delete_sources().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) => {

Review comment (refactor):
A redundant call to maybe_exists() is made despite storing its result in the 'exists' variable. Consider reusing 'exists' to avoid duplicate filesystem checks.
```suggestion
		if exists {
```

Code after:
use std::path::{Path, PathBuf};

use anyhow::{Context, Result};
use tokio::fs;
use yazi_fs::{copy_and_seal, maybe_exists, remove_dir_clean};
use yazi_macro::outln;

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?;