This commit is contained in:
evpeople 2025-01-29 20:24:45 +08:00
parent f5da79f302
commit a2ea22a5f2
No known key found for this signature in database
GPG key ID: CF5768B6A73046FF
2 changed files with 51 additions and 53 deletions

View file

@ -1,16 +1,15 @@
use std::{borrow::Cow, collections::{HashMap, HashSet}, ffi::{OsStr, OsString}, io::{stderr, BufWriter, Write}, path::PathBuf}; use std::{borrow::Cow, collections::{HashMap, HashSet}, ffi::{OsStr, OsString}, io::{BufWriter, Write, stderr}, path::PathBuf};
use anyhow::{Result, anyhow}; use anyhow::{Result, anyhow};
use scopeguard::defer; use scopeguard::defer;
use tokio::{io::{AsyncReadExt, AsyncWriteExt, stdin}}; use tokio::{fs, io::{AsyncReadExt, AsyncWriteExt, stdin}};
use tokio::fs;
use yazi_config::{OPEN, PREVIEW}; use yazi_config::{OPEN, PREVIEW};
use yazi_dds::Pubsub; use yazi_dds::Pubsub;
use yazi_fs::{max_common_root, maybe_exists, ok_or_not_found, paths_to_same_file, realname, File, FilesOp}; use yazi_fs::{File, FilesOp, max_common_root, maybe_exists, ok_or_not_found, paths_to_same_file, realname};
use yazi_proxy::{AppProxy, HIDER, TasksProxy, WATCHER}; use yazi_proxy::{AppProxy, HIDER, TasksProxy, WATCHER};
use yazi_shared::{terminal_clear, url::{Url, UrnBuf}}; use yazi_shared::{terminal_clear, url::{Url, UrnBuf}};
use crate::manager:: Manager; use crate::manager::Manager;
impl Manager { impl Manager {
pub(super) fn bulk_create(&self) { pub(super) fn bulk_create(&self) {
@ -33,11 +32,11 @@ impl Manager {
AppProxy::stop().await; AppProxy::stop().await;
let new: Vec<_> = fs::read_to_string(&tmp).await?.lines().map(Url::from).collect(); let new: Vec<_> = fs::read_to_string(&tmp).await?.lines().map(Url::from).collect();
Self::bulk_create_do( new).await Self::bulk_create_do(new).await
}); });
} }
async fn bulk_create_do(new:Vec<Url>) -> Result<()> { async fn bulk_create_do(new: Vec<Url>) -> Result<()> {
terminal_clear(&mut stderr())?; terminal_clear(&mut stderr())?;
if new.is_empty() { if new.is_empty() {
return Ok(()); return Ok(());
@ -48,7 +47,7 @@ impl Manager {
for n in &new { for n in &new {
if n.to_str().unwrap().ends_with('/') || n.to_str().unwrap().ends_with('\\') { if n.to_str().unwrap().ends_with('/') || n.to_str().unwrap().ends_with('\\') {
writeln!(stderr, "create new dir-> {}", n.display())?; writeln!(stderr, "create new dir-> {}", n.display())?;
}else{ } else {
writeln!(stderr, "create new file-> {}", n.display())?; writeln!(stderr, "create new file-> {}", n.display())?;
} }
} }
@ -96,8 +95,6 @@ impl Manager {
} }
} }
if !succeeded.is_empty() { if !succeeded.is_empty() {
Pubsub::pub_from_bulk(succeeded.iter().map(|(o, n)| (o, &n.url)).collect()); Pubsub::pub_from_bulk(succeeded.iter().map(|(o, n)| (o, &n.url)).collect());
FilesOp::create(succeeded.into_values().collect()); FilesOp::create(succeeded.into_values().collect());

View file

@ -74,6 +74,7 @@ impl FilesOp {
} }
} }
} }
pub fn create(files: Vec<File>) { pub fn create(files: Vec<File>) {
let mut parents: HashMap<_, Vec<_>> = Default::default(); let mut parents: HashMap<_, Vec<_>> = Default::default();
for file in files { for file in files {