mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: support package.toml as a symlink (#2245)
This commit is contained in:
parent
29284613a0
commit
af9a875512
2 changed files with 10 additions and 13 deletions
|
|
@ -3,7 +3,7 @@ use std::{path::{Path, PathBuf}, str::FromStr};
|
|||
use anyhow::{Context, Result, bail};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use tokio::fs;
|
||||
use yazi_fs::{Xdg, create_and_seal, ok_or_not_found, unique_name};
|
||||
use yazi_fs::{Xdg, ok_or_not_found, unique_name};
|
||||
use yazi_macro::outln;
|
||||
|
||||
use super::Dependency;
|
||||
|
|
@ -41,7 +41,7 @@ impl Package {
|
|||
}
|
||||
|
||||
let s = toml::to_string_pretty(self)?;
|
||||
create_and_seal(&Self::toml(), s.as_bytes()).await.context("Failed to write package.toml")
|
||||
fs::write(Self::toml(), s).await.context("Failed to write package.toml")
|
||||
}
|
||||
|
||||
pub(crate) async fn delete(&mut self, use_: &str) -> Result<()> {
|
||||
|
|
@ -57,7 +57,7 @@ impl Package {
|
|||
}
|
||||
|
||||
let s = toml::to_string_pretty(self)?;
|
||||
create_and_seal(&Self::toml(), s.as_bytes()).await.context("Failed to write package.toml")
|
||||
fs::write(Self::toml(), s).await.context("Failed to write package.toml")
|
||||
}
|
||||
|
||||
pub(crate) async fn install(&mut self, upgrade: bool) -> Result<()> {
|
||||
|
|
@ -77,7 +77,7 @@ impl Package {
|
|||
}
|
||||
|
||||
let s = toml::to_string_pretty(self)?;
|
||||
create_and_seal(&Self::toml(), s.as_bytes()).await.context("Failed to write package.toml")
|
||||
fs::write(Self::toml(), s).await.context("Failed to write package.toml")
|
||||
}
|
||||
|
||||
pub(crate) fn print(&self) -> Result<()> {
|
||||
|
|
@ -179,7 +179,7 @@ impl Package {
|
|||
}
|
||||
|
||||
let s = toml::to_string_pretty(self)?;
|
||||
create_and_seal(&Self::toml(), s.as_bytes()).await.context("Failed to write package.toml")
|
||||
fs::write(Self::toml(), s).await.context("Failed to write package.toml")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
|
|
@ -83,16 +83,13 @@ async fn _paths_to_same_file(a: &Path, b: &Path) -> std::io::Result<bool> {
|
|||
Ok(final_name(a).await? == final_name(b).await?)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn copy_and_seal(from: &Path, to: &Path) -> io::Result<()> {
|
||||
create_and_seal(to, &fs::read(from).await?).await
|
||||
}
|
||||
let b = fs::read(from).await?;
|
||||
ok_or_not_found(fs::remove_file(to).await)?;
|
||||
|
||||
pub async fn create_and_seal(p: &Path, b: &[u8]) -> io::Result<()> {
|
||||
ok_or_not_found(fs::remove_file(p).await)?;
|
||||
|
||||
let mut file = fs::OpenOptions::new().create_new(true).write(true).truncate(true).open(p).await?;
|
||||
file.write_all(b).await?;
|
||||
let mut file =
|
||||
fs::OpenOptions::new().create_new(true).write(true).truncate(true).open(to).await?;
|
||||
file.write_all(&b).await?;
|
||||
|
||||
let mut perm = file.metadata().await?.permissions();
|
||||
perm.set_readonly(true);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue