file rename (#9089)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2024-08-16 12:55:58 +08:00
committed by GitHub
parent 579e0fac36
commit ed18e3c786
59 changed files with 507 additions and 50 deletions

View File

@@ -3180,6 +3180,7 @@ pub enum Data {
NewVoiceCall,
CloseVoiceCall,
ResetDecoder(Option<usize>),
RenameFile((i32, String, String, bool)),
}
/// Keycode for key events.

View File

@@ -1,4 +1,4 @@
use hbb_common::{fs, message_proto::*, log};
use hbb_common::{fs, log, message_proto::*};
use super::{Data, Interface};
@@ -7,7 +7,12 @@ pub trait FileManager: Interface {
fs::get_home_as_string()
}
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli", feature = "flutter")))]
#[cfg(not(any(
target_os = "android",
target_os = "ios",
feature = "cli",
feature = "flutter"
)))]
fn read_dir(&self, path: String, include_hidden: bool) -> sciter::Value {
match fs::read_dir(&fs::get_path(&path), include_hidden) {
Err(_) => sciter::Value::null(),
@@ -20,7 +25,12 @@ pub trait FileManager: Interface {
}
}
#[cfg(any(target_os = "android", target_os = "ios", feature = "cli", feature = "flutter"))]
#[cfg(any(
target_os = "android",
target_os = "ios",
feature = "cli",
feature = "flutter"
))]
fn read_dir(&self, path: &str, include_hidden: bool) -> String {
use crate::common::make_fd_to_json;
match fs::read_dir(&fs::get_path(path), include_hidden) {
@@ -136,4 +146,8 @@ pub trait FileManager: Interface {
is_upload,
)));
}
fn rename_file(&self, act_id: i32, path: String, new_name: String, is_remote: bool) {
self.send(Data::RenameFile((act_id, path, new_name, is_remote)));
}
}

View File

@@ -817,6 +817,25 @@ impl<T: InvokeUiSession> Remote<T> {
}
}
}
Data::RenameFile((id, path, new_name, is_remote)) => {
if is_remote {
let mut msg_out = Message::new();
let mut file_action = FileAction::new();
file_action.set_rename(FileRename {
id,
path,
new_name,
..Default::default()
});
msg_out.set_file_action(file_action);
allow_err!(peer.send(&msg_out).await);
} else {
let err = fs::rename_file(&path, &new_name)
.err()
.map(|e| e.to_string());
self.handle_job_status(id, -1, err);
}
}
Data::RecordScreen(start, display, w, h, id) => {
let _ = self
.video_sender

View File

@@ -710,6 +710,18 @@ pub fn session_resume_job(session_id: SessionID, act_id: i32, is_remote: bool) {
}
}
pub fn session_rename_file(
session_id: SessionID,
act_id: i32,
path: String,
new_name: String,
is_remote: bool,
) {
if let Some(session) = sessions::get_session_by_session_id(&session_id) {
session.rename_file(act_id, path, new_name, is_remote);
}
}
pub fn session_elevate_direct(session_id: SessionID) {
if let Some(session) = sessions::get_session_by_session_id(&session_id) {
session.elevate_direct();

View File

@@ -102,6 +102,11 @@ pub enum FS {
last_modified: u64,
is_upload: bool,
},
Rename {
id: i32,
path: String,
new_name: String,
},
}
#[cfg(target_os = "windows")]

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", "平台"),
("Days remaining", "剩余天数"),
("enable-trusted-devices-tip", "允许受信任的设备跳过 2FA 验证"),
("Parent directory", "父目录"),
("Resume", "继续"),
("Invalid file name", "无效文件名"),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", "Platforma"),
("Days remaining", "Zbývajících dnů"),
("enable-trusted-devices-tip", "Přeskočte 2FA ověření na důvěryhodných zařízeních"),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", "Plattform"),
("Days remaining", "Verbleibende Tage"),
("enable-trusted-devices-tip", "2FA-Verifizierung auf vertrauenswürdigen Geräten überspringen"),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", "Plataforma"),
("Days remaining", "Días restantes"),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", "Piattaforma"),
("Days remaining", "Giorni rimanenti"),
("enable-trusted-devices-tip", "Salta verifica 2FA nei dispositivi attendibili"),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", "플랫폼"),
("Days remaining", "일 남음"),
("enable-trusted-devices-tip", "신뢰할 수 있는 기기에서 2FA 검증 건너뛰기"),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -641,5 +641,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", ""),
("Days remaining", ""),
("enable-trusted-devices-tip", ""),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
].iter().cloned().collect();
}

View File

@@ -2274,6 +2274,22 @@ impl Connection {
job.confirm(&r);
}
}
Some(file_action::Union::Rename(r)) => {
self.send_fs(ipc::FS::Rename {
id: r.id,
path: r.path.clone(),
new_name: r.new_name.clone(),
});
self.send_to_cm(ipc::Data::FileTransferLog((
"rename".to_string(),
serde_json::to_string(&FileRenameLog {
conn_id: self.inner.id(),
path: r.path,
new_name: r.new_name,
})
.unwrap_or_default(),
)));
}
_ => {}
}
}
@@ -3451,6 +3467,14 @@ struct FileActionLog {
dir: bool,
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
struct FileRenameLog {
conn_id: i32,
path: String,
new_name: String,
}
struct FileRemoveLogControl {
conn_id: i32,
instant: Instant,

View File

@@ -881,6 +881,9 @@ async fn handle_fs(
}
}
}
ipc::FS::Rename { id, path, new_name } => {
rename_file(path, new_name, id, tx).await;
}
_ => {}
}
}
@@ -945,6 +948,17 @@ async fn create_dir(path: String, id: i32, tx: &UnboundedSender<Data>) {
.await;
}
#[cfg(not(any(target_os = "ios")))]
async fn rename_file(path: String, new_name: String, id: i32, tx: &UnboundedSender<Data>) {
handle_result(
spawn_blocking(move || fs::rename_file(&path, &new_name)).await,
id,
0,
tx,
)
.await;
}
#[cfg(not(any(target_os = "ios")))]
async fn remove_dir(path: String, id: i32, recursive: bool, tx: &UnboundedSender<Data>) {
let path = fs::get_path(&path);