mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
fix: unable to delete sealed files on Windows due to platform differences (#2319)
This commit is contained in:
parent
d75a5d6628
commit
498623191a
4 changed files with 19 additions and 8 deletions
|
|
@ -19,7 +19,7 @@ async fn main() -> ExitCode {
|
|||
}
|
||||
}
|
||||
}
|
||||
errln!("{:#}", e).ok();
|
||||
errln!("{e:#}").ok();
|
||||
ExitCode::FAILURE
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use anyhow::{Context, Result, bail};
|
||||
use tokio::fs;
|
||||
use yazi_fs::{maybe_exists, ok_or_not_found, remove_dir_clean};
|
||||
use yazi_fs::{maybe_exists, ok_or_not_found, remove_dir_clean, remove_sealed};
|
||||
use yazi_macro::outln;
|
||||
|
||||
use super::Dependency;
|
||||
|
|
@ -30,7 +30,7 @@ Please manually delete it from: {}",
|
|||
&["main.lua", "README.md", "LICENSE"][..]
|
||||
};
|
||||
for p in files.iter().map(|&f| dir.join(f)) {
|
||||
ok_or_not_found(fs::remove_file(&p).await)
|
||||
ok_or_not_found(remove_sealed(&p).await)
|
||||
.with_context(|| format!("failed to delete `{}`", p.display()))?;
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ For safety, user data has been preserved, please manually delete them within: {}
|
|||
match fs::read_dir(&assets).await {
|
||||
Ok(mut it) => {
|
||||
while let Some(entry) = it.next_entry().await? {
|
||||
fs::remove_file(entry.path())
|
||||
remove_sealed(&entry.path())
|
||||
.await
|
||||
.with_context(|| format!("failed to remove `{}`", entry.path().display()))?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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, ok_or_not_found, unique_name};
|
||||
use yazi_fs::{Xdg, ok_or_not_found, remove_sealed, unique_name};
|
||||
use yazi_macro::outln;
|
||||
|
||||
use super::Dependency;
|
||||
|
|
@ -134,7 +134,7 @@ impl Package {
|
|||
if d.hash.is_empty() {
|
||||
d.hash = d.hash().await?;
|
||||
}
|
||||
fs::remove_file(&tracker).await.ok();
|
||||
remove_sealed(&tracker).await.ok();
|
||||
}
|
||||
}
|
||||
for d in &mut self.flavors {
|
||||
|
|
@ -156,7 +156,7 @@ impl Package {
|
|||
if d.hash.is_empty() {
|
||||
d.hash = d.hash().await?;
|
||||
}
|
||||
fs::remove_file(&tracker).await.ok();
|
||||
remove_sealed(&tracker).await.ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ async fn _paths_to_same_file(a: &Path, b: &Path) -> std::io::Result<bool> {
|
|||
|
||||
pub async fn copy_and_seal(from: &Path, to: &Path) -> io::Result<()> {
|
||||
let b = fs::read(from).await?;
|
||||
ok_or_not_found(fs::remove_file(to).await)?;
|
||||
ok_or_not_found(remove_sealed(to).await)?;
|
||||
|
||||
let mut file =
|
||||
fs::OpenOptions::new().create_new(true).write(true).truncate(true).open(to).await?;
|
||||
|
|
@ -98,6 +98,17 @@ pub async fn copy_and_seal(from: &Path, to: &Path) -> io::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn remove_sealed(p: &Path) -> io::Result<()> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let mut perm = fs::metadata(p).await?.permissions();
|
||||
perm.set_readonly(false);
|
||||
fs::set_permissions(p, perm).await?;
|
||||
}
|
||||
|
||||
fs::remove_file(p).await
|
||||
}
|
||||
|
||||
pub async fn realname(p: &Path) -> Option<OsString> {
|
||||
let name = p.file_name()?;
|
||||
if p == fs::canonicalize(p).await.ok()? {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue