mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-09 23:31:29 +03:00
refactor: replace &PathBuf with &Path to enhance generality (#10332)
This commit is contained in:
@@ -3,7 +3,7 @@ use std::{
|
|||||||
fs::File,
|
fs::File,
|
||||||
io::{BufRead, BufReader, Read, Seek},
|
io::{BufRead, BufReader, Read, Seek},
|
||||||
os::unix::prelude::PermissionsExt,
|
os::unix::prelude::PermissionsExt,
|
||||||
path::PathBuf,
|
path::{Path, PathBuf},
|
||||||
sync::atomic::{AtomicU64, Ordering},
|
sync::atomic::{AtomicU64, Ordering},
|
||||||
time::SystemTime,
|
time::SystemTime,
|
||||||
};
|
};
|
||||||
@@ -51,7 +51,7 @@ pub(super) struct LocalFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LocalFile {
|
impl LocalFile {
|
||||||
pub fn try_open(path: &PathBuf) -> Result<Self, CliprdrError> {
|
pub fn try_open(path: &Path) -> Result<Self, CliprdrError> {
|
||||||
let mt = std::fs::metadata(path).map_err(|e| CliprdrError::FileError {
|
let mt = std::fs::metadata(path).map_err(|e| CliprdrError::FileError {
|
||||||
path: path.clone(),
|
path: path.clone(),
|
||||||
err: e,
|
err: e,
|
||||||
@@ -219,7 +219,7 @@ impl LocalFile {
|
|||||||
|
|
||||||
pub(super) fn construct_file_list(paths: &[PathBuf]) -> Result<Vec<LocalFile>, CliprdrError> {
|
pub(super) fn construct_file_list(paths: &[PathBuf]) -> Result<Vec<LocalFile>, CliprdrError> {
|
||||||
fn constr_file_lst(
|
fn constr_file_lst(
|
||||||
path: &PathBuf,
|
path: &Path,
|
||||||
file_list: &mut Vec<LocalFile>,
|
file_list: &mut Vec<LocalFile>,
|
||||||
visited: &mut HashSet<PathBuf>,
|
visited: &mut HashSet<PathBuf>,
|
||||||
) -> Result<(), CliprdrError> {
|
) -> Result<(), CliprdrError> {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
path::PathBuf,
|
path::{Path, PathBuf},
|
||||||
sync::{mpsc::Sender, Arc},
|
sync::{mpsc::Sender, Arc},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
@@ -74,7 +74,7 @@ trait SysClipboard: Send + Sync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn get_sys_clipboard(ignore_path: &PathBuf) -> Result<Box<dyn SysClipboard>, CliprdrError> {
|
fn get_sys_clipboard(ignore_path: &Path) -> Result<Box<dyn SysClipboard>, CliprdrError> {
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
{
|
{
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
@@ -88,7 +88,7 @@ fn get_sys_clipboard(ignore_path: &PathBuf) -> Result<Box<dyn SysClipboard>, Cli
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fn get_sys_clipboard(ignore_path: &PathBuf) -> Result<Box<dyn SysClipboard>, CliprdrError> {
|
fn get_sys_clipboard(ignore_path: &Path) -> Result<Box<dyn SysClipboard>, CliprdrError> {
|
||||||
use ns_clipboard::*;
|
use ns_clipboard::*;
|
||||||
let ns_pb = NsPasteboard::new(ignore_path)?;
|
let ns_pb = NsPasteboard::new(ignore_path)?;
|
||||||
Ok(Box::new(ns_pb) as Box<_>)
|
Ok(Box::new(ns_pb) as Box<_>)
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use std::{collections::BTreeSet, path::PathBuf};
|
use std::{
|
||||||
|
collections::BTreeSet,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
use cacao::pasteboard::{Pasteboard, PasteboardName};
|
use cacao::pasteboard::{Pasteboard, PasteboardName};
|
||||||
use hbb_common::log;
|
use hbb_common::log;
|
||||||
@@ -30,7 +33,7 @@ pub struct NsPasteboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NsPasteboard {
|
impl NsPasteboard {
|
||||||
pub fn new(ignore_path: &PathBuf) -> Result<Self, CliprdrError> {
|
pub fn new(ignore_path: &Path) -> Result<Self, CliprdrError> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
ignore_path: ignore_path.to_owned(),
|
ignore_path: ignore_path.to_owned(),
|
||||||
former_file_list: Mutex::new(vec![]),
|
former_file_list: Mutex::new(vec![]),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crate::CliprdrError;
|
|||||||
// url encode and decode is needed
|
// url encode and decode is needed
|
||||||
const ENCODE_SET: percent_encoding::AsciiSet = percent_encoding::CONTROLS.add(b' ').remove(b'/');
|
const ENCODE_SET: percent_encoding::AsciiSet = percent_encoding::CONTROLS.add(b' ').remove(b'/');
|
||||||
|
|
||||||
pub(super) fn encode_path_to_uri(path: &PathBuf) -> io::Result<String> {
|
pub(super) fn encode_path_to_uri(path: &Path) -> io::Result<String> {
|
||||||
let encoded =
|
let encoded =
|
||||||
percent_encoding::percent_encode(path.to_str()?.as_bytes(), &ENCODE_SET).to_string();
|
percent_encoding::percent_encode(path.to_str()?.as_bytes(), &ENCODE_SET).to_string();
|
||||||
format!("file://{}", encoded)
|
format!("file://{}", encoded)
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use std::{collections::BTreeSet, path::PathBuf};
|
use std::{
|
||||||
|
collections::BTreeSet,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
use hbb_common::log;
|
use hbb_common::log;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
@@ -26,7 +29,7 @@ pub struct X11Clipboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl X11Clipboard {
|
impl X11Clipboard {
|
||||||
pub fn new(ignore_path: &PathBuf) -> Result<Self, CliprdrError> {
|
pub fn new(ignore_path: &Path) -> Result<Self, CliprdrError> {
|
||||||
let clipboard = get_clip()?;
|
let clipboard = get_clip()?;
|
||||||
let text_uri_list = clipboard
|
let text_uri_list = clipboard
|
||||||
.setter
|
.setter
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ pub fn get_home_as_string() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_dir_recursive(
|
fn read_dir_recursive(
|
||||||
path: &PathBuf,
|
path: &Path,
|
||||||
prefix: &Path,
|
prefix: &Path,
|
||||||
include_hidden: bool,
|
include_hidden: bool,
|
||||||
) -> ResultType<Vec<FileEntry>> {
|
) -> ResultType<Vec<FileEntry>> {
|
||||||
@@ -186,7 +186,7 @@ pub fn get_recursive_files(path: &str, include_hidden: bool) -> ResultType<Vec<F
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_empty_dirs_recursive(
|
fn read_empty_dirs_recursive(
|
||||||
path: &PathBuf,
|
path: &Path,
|
||||||
prefix: &Path,
|
prefix: &Path,
|
||||||
include_hidden: bool,
|
include_hidden: bool,
|
||||||
) -> ResultType<Vec<FileDirectory>> {
|
) -> ResultType<Vec<FileDirectory>> {
|
||||||
@@ -854,7 +854,7 @@ pub async fn handle_read_jobs(
|
|||||||
Ok(job_log)
|
Ok(job_log)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_all_empty_dir(path: &PathBuf) -> ResultType<()> {
|
pub fn remove_all_empty_dir(path: &Path) -> ResultType<()> {
|
||||||
let fd = read_dir(path, true)?;
|
let fd = read_dir(path, true)?;
|
||||||
for entry in fd.entries.iter() {
|
for entry in fd.entries.iter() {
|
||||||
match entry.entry_type.enum_value() {
|
match entry.entry_type.enum_value() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{self},
|
fs::{self},
|
||||||
io::{Cursor, Read},
|
io::{Cursor, Read},
|
||||||
path::PathBuf,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
@@ -42,7 +42,7 @@ impl BinaryData {
|
|||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_to_file(&self, prefix: &PathBuf) {
|
pub fn write_to_file(&self, prefix: &Path) {
|
||||||
let p = prefix.join(&self.path);
|
let p = prefix.join(&self.path);
|
||||||
if let Some(parent) = p.parent() {
|
if let Some(parent) = p.parent() {
|
||||||
if !parent.exists() {
|
if !parent.exists() {
|
||||||
@@ -122,7 +122,7 @@ impl BinaryReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(linux)]
|
#[cfg(linux)]
|
||||||
pub fn configure_permission(&self, prefix: &PathBuf) {
|
pub fn configure_permission(&self, prefix: &Path) {
|
||||||
use std::os::unix::prelude::PermissionsExt;
|
use std::os::unix::prelude::PermissionsExt;
|
||||||
|
|
||||||
let exe_path = prefix.join(&self.exe);
|
let exe_path = prefix.join(&self.exe);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![windows_subsystem = "windows"]
|
#![windows_subsystem = "windows"]
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
path::PathBuf,
|
path::{Path, PathBuf},
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ const APPNAME_RUNTIME_ENV_KEY: &str = "RUSTDESK_APPNAME";
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
const SET_FOREGROUND_WINDOW_ENV_KEY: &str = "SET_FOREGROUND_WINDOW";
|
const SET_FOREGROUND_WINDOW_ENV_KEY: &str = "SET_FOREGROUND_WINDOW";
|
||||||
|
|
||||||
fn is_timestamp_matches(dir: &PathBuf, ts: &mut u64) -> bool {
|
fn is_timestamp_matches(dir: &Path, ts: &mut u64) -> bool {
|
||||||
let Ok(app_metadata) = std::str::from_utf8(APP_METADATA) else {
|
let Ok(app_metadata) = std::str::from_utf8(APP_METADATA) else {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@@ -50,7 +50,7 @@ fn is_timestamp_matches(dir: &PathBuf, ts: &mut u64) -> bool {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_meta(dir: &PathBuf, ts: u64) {
|
fn write_meta(dir: &Path, ts: u64) {
|
||||||
let meta_file = dir.join(APP_METADATA_CONFIG);
|
let meta_file = dir.join(APP_METADATA_CONFIG);
|
||||||
if ts != 0 {
|
if ts != 0 {
|
||||||
let content = format!("{}{}", META_LINE_PREFIX_TIMESTAMP, ts);
|
let content = format!("{}{}", META_LINE_PREFIX_TIMESTAMP, ts);
|
||||||
@@ -169,13 +169,13 @@ fn main() {
|
|||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
mod windows {
|
mod windows {
|
||||||
use std::{fs, os::windows::process::CommandExt, path::PathBuf, process::Command};
|
use std::{fs, os::windows::process::CommandExt, path::Path, process::Command};
|
||||||
|
|
||||||
// Used for privacy mode(magnifier impl).
|
// Used for privacy mode(magnifier impl).
|
||||||
pub const RUNTIME_BROKER_EXE: &'static str = "C:\\Windows\\System32\\RuntimeBroker.exe";
|
pub const RUNTIME_BROKER_EXE: &'static str = "C:\\Windows\\System32\\RuntimeBroker.exe";
|
||||||
pub const WIN_TOPMOST_INJECTED_PROCESS_EXE: &'static str = "RuntimeBroker_rustdesk.exe";
|
pub const WIN_TOPMOST_INJECTED_PROCESS_EXE: &'static str = "RuntimeBroker_rustdesk.exe";
|
||||||
|
|
||||||
pub(super) fn copy_runtime_broker(dir: &PathBuf) {
|
pub(super) fn copy_runtime_broker(dir: &Path) {
|
||||||
let src = RUNTIME_BROKER_EXE;
|
let src = RUNTIME_BROKER_EXE;
|
||||||
let tgt = WIN_TOPMOST_INJECTED_PROCESS_EXE;
|
let tgt = WIN_TOPMOST_INJECTED_PROCESS_EXE;
|
||||||
let target_file = dir.join(tgt);
|
let target_file = dir.join(tgt);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ use include_dir::{include_dir, Dir};
|
|||||||
use objc::rc::autoreleasepool;
|
use objc::rc::autoreleasepool;
|
||||||
use objc::{class, msg_send, sel, sel_impl};
|
use objc::{class, msg_send, sel, sel_impl};
|
||||||
use scrap::{libc::c_void, quartz::ffi::*};
|
use scrap::{libc::c_void, quartz::ffi::*};
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
static PRIVILEGES_SCRIPTS_DIR: Dir =
|
static PRIVILEGES_SCRIPTS_DIR: Dir =
|
||||||
include_dir!("$CARGO_MANIFEST_DIR/src/platform/privileges_scripts");
|
include_dir!("$CARGO_MANIFEST_DIR/src/platform/privileges_scripts");
|
||||||
@@ -661,7 +661,7 @@ pub fn hide_dock() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_server_start_time_of(p: &Process, path: &PathBuf) -> Option<i64> {
|
fn get_server_start_time_of(p: &Process, path: &Path) -> Option<i64> {
|
||||||
let cmd = p.cmd();
|
let cmd = p.cmd();
|
||||||
if cmd.len() <= 1 {
|
if cmd.len() <= 1 {
|
||||||
return None;
|
return None;
|
||||||
@@ -679,7 +679,7 @@ fn get_server_start_time_of(p: &Process, path: &PathBuf) -> Option<i64> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_server_start_time(sys: &mut System, path: &PathBuf) -> Option<(i64, Pid)> {
|
fn get_server_start_time(sys: &mut System, path: &Path) -> Option<(i64, Pid)> {
|
||||||
sys.refresh_processes_specifics(ProcessRefreshKind::new());
|
sys.refresh_processes_specifics(ProcessRefreshKind::new());
|
||||||
for (_, p) in sys.processes() {
|
for (_, p) in sys.processes() {
|
||||||
if let Some(t) = get_server_start_time_of(p, path) {
|
if let Some(t) = get_server_start_time_of(p, path) {
|
||||||
|
|||||||
@@ -1460,15 +1460,13 @@ fn to_le(v: &mut [u16]) -> &[u8] {
|
|||||||
unsafe { v.align_to().1 }
|
unsafe { v.align_to().1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_undone_file(tmp: &PathBuf) -> ResultType<PathBuf> {
|
fn get_undone_file(tmp: &Path) -> ResultType<PathBuf> {
|
||||||
let mut tmp1 = tmp.clone();
|
Ok(tmp.with_file_name(format!(
|
||||||
tmp1.set_file_name(format!(
|
|
||||||
"{}.undone",
|
"{}.undone",
|
||||||
tmp.file_name()
|
tmp.file_name()
|
||||||
.ok_or(anyhow!("Failed to get filename of {:?}", tmp))?
|
.ok_or(anyhow!("Failed to get filename of {:?}", tmp))?
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
));
|
)))
|
||||||
Ok(tmp1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_cmds(cmds: String, show: bool, tip: &str) -> ResultType<()> {
|
fn run_cmds(cmds: String, show: bool, tip: &str) -> ResultType<()> {
|
||||||
@@ -1933,7 +1931,7 @@ pub fn create_process_with_logon(user: &str, pwd: &str, exe: &str, arg: &str) ->
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_path_permission(dir: &PathBuf, permission: &str) -> ResultType<()> {
|
pub fn set_path_permission(dir: &Path, permission: &str) -> ResultType<()> {
|
||||||
std::process::Command::new("icacls")
|
std::process::Command::new("icacls")
|
||||||
.arg(dir.as_os_str())
|
.arg(dir.as_os_str())
|
||||||
.arg("/grant")
|
.arg("/grant")
|
||||||
|
|||||||
@@ -452,7 +452,7 @@ pub(super) mod install {
|
|||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{BufReader, BufWriter, Write},
|
io::{BufReader, BufWriter, Write},
|
||||||
path::PathBuf,
|
path::Path,
|
||||||
};
|
};
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
@@ -488,7 +488,7 @@ pub(super) mod install {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn download_file(id: &str, url: &str, filename: &PathBuf) -> bool {
|
fn download_file(id: &str, url: &str, filename: &Path) -> bool {
|
||||||
let file = match File::create(filename) {
|
let file = match File::create(filename) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -505,7 +505,7 @@ pub(super) mod install {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_install_file(filename: &PathBuf, target_dir: &PathBuf) -> ResultType<()> {
|
fn do_install_file(filename: &Path, target_dir: &Path) -> ResultType<()> {
|
||||||
let mut zip = ZipArchive::new(BufReader::new(File::open(filename)?))?;
|
let mut zip = ZipArchive::new(BufReader::new(File::open(filename)?))?;
|
||||||
for i in 0..zip.len() {
|
for i in 0..zip.len() {
|
||||||
let mut file = zip.by_index(i)?;
|
let mut file = zip.by_index(i)?;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use serde_derive::Serialize;
|
|||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
ffi::{c_char, c_void},
|
ffi::{c_char, c_void},
|
||||||
path::PathBuf,
|
path::Path,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ pub(super) fn load_plugins(uninstalled_ids: &HashSet<String>) -> ResultType<()>
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_plugin_dir(dir: &PathBuf) {
|
fn load_plugin_dir(dir: &Path) {
|
||||||
log::debug!("Begin load plugin dir: {}", dir.display());
|
log::debug!("Begin load plugin dir: {}", dir.display());
|
||||||
if let Ok(rd) = std::fs::read_dir(dir) {
|
if let Ok(rd) = std::fs::read_dir(dir) {
|
||||||
for entry in rd {
|
for entry in rd {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use shared_memory::*;
|
|||||||
use std::{
|
use std::{
|
||||||
mem::size_of,
|
mem::size_of,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
path::PathBuf,
|
path::Path,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
@@ -92,7 +92,7 @@ impl SharedMemory {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
log::info!("Create shared memory, size: {}, flink: {}", size, flink);
|
log::info!("Create shared memory, size: {}, flink: {}", size, flink);
|
||||||
set_path_permission(&PathBuf::from(flink), "F").ok();
|
set_path_permission(Path::new(&flink), "F").ok();
|
||||||
Ok(SharedMemory { inner: shmem })
|
Ok(SharedMemory { inner: shmem })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -586,8 +586,8 @@ pub mod client {
|
|||||||
let mut exe = std::env::current_exe()?.to_string_lossy().to_string();
|
let mut exe = std::env::current_exe()?.to_string_lossy().to_string();
|
||||||
#[cfg(feature = "flutter")]
|
#[cfg(feature = "flutter")]
|
||||||
{
|
{
|
||||||
if let Some(dir) = PathBuf::from(&exe).parent() {
|
if let Some(dir) = Path::new(&exe).parent() {
|
||||||
if set_path_permission(&PathBuf::from(dir), "RX").is_err() {
|
if set_path_permission(Path::new(dir), "RX").is_err() {
|
||||||
*SHMEM.lock().unwrap() = None;
|
*SHMEM.lock().unwrap() = None;
|
||||||
bail!("Failed to set permission of {:?}", dir);
|
bail!("Failed to set permission of {:?}", dir);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user