mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
d9bad0f557
commit
d3cc7df0d9
5 changed files with 24 additions and 23 deletions
|
|
@ -21,7 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
|
|||
- New `relay-notify-push` DDS event to customize the notification handler ([#3642])
|
||||
- New `ind-app-title` DDS event to customize the app title ([#3684])
|
||||
- New `fs.unique()` creates a unique file or directory ([#3677])
|
||||
- New `download` DDS event fires when remote files are downloaded
|
||||
- New `download` DDS event fires when remote files are downloaded ([#3687])
|
||||
- New `cx.which` API to access the which component state ([#3617])
|
||||
- New `ind-which-activate` DDS event to change the which component behavior ([#3608])
|
||||
|
||||
|
|
@ -1661,3 +1661,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
|
|||
[#3677]: https://github.com/sxyazi/yazi/pull/3677
|
||||
[#3678]: https://github.com/sxyazi/yazi/pull/3678
|
||||
[#3684]: https://github.com/sxyazi/yazi/pull/3684
|
||||
[#3687]: https://github.com/sxyazi/yazi/pull/3687
|
||||
|
|
|
|||
|
|
@ -403,7 +403,7 @@ impl File {
|
|||
pub(crate) async fn upload_do(&self, task: FileInUpload) -> Result<(), FileOutUploadDo> {
|
||||
let cha = task.cha.unwrap();
|
||||
let cache = ctx!(task, task.cache.as_ref(), "Cannot determine cache path")?;
|
||||
let lock = ctx!(task, task.url.cache_lock(), "Cannot determine cache lock")?;
|
||||
let lock = ctx!(task, task.target.cache_lock(), "Cannot determine cache lock")?;
|
||||
|
||||
let hash = ctx!(task, Local::regular(&lock).read_to_string().await, "Cannot read cache lock")?;
|
||||
let hash = ctx!(task, u128::from_str_radix(&hash, 16), "Cannot parse hash from lock")?;
|
||||
|
|
@ -412,7 +412,7 @@ impl File {
|
|||
}
|
||||
|
||||
let tmp =
|
||||
ctx!(task, Transaction::tmp(&task.url).await, "Cannot determine temporary upload path")?;
|
||||
ctx!(task, Transaction::tmp(&task.target).await, "Cannot determine temporary upload path")?;
|
||||
let mut it = ctx!(
|
||||
task,
|
||||
provider::copy_with_progress(cache, &tmp, Attrs {
|
||||
|
|
@ -428,15 +428,15 @@ impl File {
|
|||
match progress_or_break!(it, task.done) {
|
||||
Ok(0) => {
|
||||
let cha =
|
||||
ctx!(task, Self::cha(&task.url, true, None).await, "Cannot stat original file")?;
|
||||
ctx!(task, Self::cha(&task.target, true, None).await, "Cannot stat original file")?;
|
||||
if hash != cha.hash_u128() {
|
||||
Err(anyhow!("Failed to work on: {task:?}: remote file has changed during upload"))?;
|
||||
}
|
||||
|
||||
ctx!(task, provider::rename(&tmp, &task.url).await, "Cannot persist uploaded file")?;
|
||||
ctx!(task, provider::rename(&tmp, &task.target).await, "Cannot persist uploaded file")?;
|
||||
|
||||
let cha =
|
||||
ctx!(task, Self::cha(&task.url, true, None).await, "Cannot stat uploaded file")?;
|
||||
ctx!(task, Self::cha(&task.target, true, None).await, "Cannot stat uploaded file")?;
|
||||
let hash = format!("{:x}", cha.hash_u128());
|
||||
ctx!(task, Local::regular(&lock).write(hash).await, "Cannot lock cache")?;
|
||||
|
||||
|
|
|
|||
|
|
@ -197,9 +197,9 @@ pub(crate) struct FileInDownload {
|
|||
// --- Upload
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct FileInUpload {
|
||||
pub(crate) id: Id,
|
||||
pub(crate) url: UrlBuf,
|
||||
pub(crate) cha: Option<Cha>,
|
||||
pub(crate) cache: Option<PathBuf>,
|
||||
pub(crate) done: CompletionToken,
|
||||
pub(crate) id: Id,
|
||||
pub(crate) target: UrlBuf,
|
||||
pub(crate) cha: Option<Cha>,
|
||||
pub(crate) cache: Option<PathBuf>,
|
||||
pub(crate) done: CompletionToken,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,25 +132,25 @@ impl Traverse for FileInUpload {
|
|||
|
||||
fn follow(&self) -> bool { true }
|
||||
|
||||
fn from(&self) -> Url<'_> { self.url.as_url() }
|
||||
fn from(&self) -> Url<'_> { self.target.as_url() }
|
||||
|
||||
async fn init(&mut self) -> anyhow::Result<Cha> {
|
||||
if self.cha.is_none() {
|
||||
self.cha = Some(super::File::cha(self.from(), self.follow(), None).await?)
|
||||
}
|
||||
if self.cache.is_none() {
|
||||
self.cache = self.url.cache();
|
||||
self.cache = self.target.cache();
|
||||
}
|
||||
Ok(self.cha.unwrap())
|
||||
}
|
||||
|
||||
fn spawn(&self, from: UrlBuf, _to: Option<UrlBuf>, cha: Cha) -> Self {
|
||||
Self {
|
||||
id: self.id,
|
||||
cha: Some(cha),
|
||||
cache: from.cache(),
|
||||
url: from,
|
||||
done: self.done.clone(),
|
||||
id: self.id,
|
||||
cha: Some(cha),
|
||||
cache: from.cache(),
|
||||
target: from,
|
||||
done: self.done.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -164,19 +164,19 @@ impl Scheduler {
|
|||
task.done.clone()
|
||||
}
|
||||
|
||||
pub fn file_upload(&self, url: UrlBuf) {
|
||||
pub fn file_upload(&self, target: UrlBuf) {
|
||||
let mut ongoing = self.ongoing.lock();
|
||||
let task = ongoing.add::<FileProgUpload>(format!("Upload {}", url.display()));
|
||||
let task = ongoing.add::<FileProgUpload>(format!("Upload {}", target.display()));
|
||||
|
||||
if !url.kind().is_remote() {
|
||||
if !target.kind().is_remote() {
|
||||
return self
|
||||
.ops
|
||||
.out(task.id, FileOutUpload::Fail("Cannot upload non-remote file".to_owned()));
|
||||
};
|
||||
|
||||
task.set_hook(HookInUpload { id: task.id, target: url.clone() });
|
||||
task.set_hook(HookInUpload { id: task.id, target: target.clone() });
|
||||
self.file.submit(
|
||||
FileInUpload { id: task.id, url, cha: None, cache: None, done: task.done.clone() },
|
||||
FileInUpload { id: task.id, target, cha: None, cache: None, done: task.done.clone() },
|
||||
LOW,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue