mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41: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 anyhow::{Context, Result, bail};
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use tokio::fs;
|
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 yazi_macro::outln;
|
||||||
|
|
||||||
use super::Dependency;
|
use super::Dependency;
|
||||||
|
|
@ -41,7 +41,7 @@ impl Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
let s = toml::to_string_pretty(self)?;
|
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<()> {
|
pub(crate) async fn delete(&mut self, use_: &str) -> Result<()> {
|
||||||
|
|
@ -57,7 +57,7 @@ impl Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
let s = toml::to_string_pretty(self)?;
|
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<()> {
|
pub(crate) async fn install(&mut self, upgrade: bool) -> Result<()> {
|
||||||
|
|
@ -77,7 +77,7 @@ impl Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
let s = toml::to_string_pretty(self)?;
|
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<()> {
|
pub(crate) fn print(&self) -> Result<()> {
|
||||||
|
|
@ -179,7 +179,7 @@ impl Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
let s = toml::to_string_pretty(self)?;
|
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]
|
#[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?)
|
Ok(final_name(a).await? == final_name(b).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn copy_and_seal(from: &Path, to: &Path) -> io::Result<()> {
|
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<()> {
|
let mut file =
|
||||||
ok_or_not_found(fs::remove_file(p).await)?;
|
fs::OpenOptions::new().create_new(true).write(true).truncate(true).open(to).await?;
|
||||||
|
file.write_all(&b).await?;
|
||||||
let mut file = fs::OpenOptions::new().create_new(true).write(true).truncate(true).open(p).await?;
|
|
||||||
file.write_all(b).await?;
|
|
||||||
|
|
||||||
let mut perm = file.metadata().await?.permissions();
|
let mut perm = file.metadata().await?.permissions();
|
||||||
perm.set_readonly(true);
|
perm.set_readonly(true);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue