This commit is contained in:
sxyazi 2025-10-20 13:36:03 +08:00
parent 89623fbb99
commit 86665e788b
No known key found for this signature in database
3 changed files with 28 additions and 17 deletions

View file

@ -58,14 +58,24 @@ impl Cwd {
return cache.into(); return cache.into();
} }
let count = cache.strip_prefix(Xdg::cache_dir()).expect("under cache dir").components().count(); let latter = cache.strip_prefix(Xdg::cache_dir()).expect("under cache dir");
'outer: for n in (0..count).rev() { let mut it = latter.components().peekable();
while it.peek() == Some(&C::CurDir) {
it.next().unwrap();
}
let mut count = 0;
for c in it {
match c {
C::Prefix(_) | C::RootDir | C::ParentDir => return cache.into(),
C::CurDir | C::Normal(_) => count += 1,
}
}
for n in (0..count).rev() {
let mut it = cache.components(); let mut it = cache.components();
for _ in 0..n { for _ in 0..n {
match it.next_back().unwrap() { it.next_back().unwrap();
C::Prefix(_) | C::RootDir | C::ParentDir => break 'outer,
C::CurDir | C::Normal(_) => {}
}
} }
match std::fs::remove_file(it.as_path()) { match std::fs::remove_file(it.as_path()) {
Ok(_) => break, Ok(_) => break,

View file

@ -238,17 +238,19 @@ impl Local {
use std::os::unix::fs::OpenOptionsExt; use std::os::unix::fs::OpenOptionsExt;
tokio::task::spawn_blocking(move || { tokio::task::spawn_blocking(move || {
let mut reader = std::fs::File::open(from)?; let mut opts = std::fs::OpenOptions::new();
let mut writer = std::fs::OpenOptions::new() if let Some(mode) = attrs.mode {
.mode(cha.mode.bits() as _) opts.mode(mode.bits() as _);
.write(true) }
.create(true)
.truncate(true)
.open(to)?;
let mut reader = std::fs::File::open(from)?;
let mut writer = opts.write(true).create(true).truncate(true).open(to)?;
let written = std::io::copy(&mut reader, &mut writer)?; let written = std::io::copy(&mut reader, &mut writer)?;
writer.set_permissions(cha.into()).ok();
writer.set_times(cha.into()).ok(); if let Some(mode) = attrs.mode {
writer.set_permissions(mode.into()).ok();
}
writer.set_times(attrs.into()).ok();
Ok(written) Ok(written)
}) })

View file

@ -142,8 +142,7 @@ impl Operator {
F: ToByteStr<'a>, F: ToByteStr<'a>,
T: ToByteStr<'a>, T: ToByteStr<'a>,
{ {
let req = requests::Rename::new(from, to)?; let status: responses::Status = self.send(requests::Rename::new(from, to)?).await?;
let status: responses::Status = self.send(req).await?;
status.into() status.into()
} }