Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

clear unwrap (#8605)

fufesou86ff76824163
diff --git a/libs/clipboard/src/platform/fuse.rs b/libs/clipboard/src/platform/fuse.rs
index 950dff958..c5fe60f56 100644
--- a/libs/clipboard/src/platform/fuse.rs
+++ b/libs/clipboard/src/platform/fuse.rs
@@ -795,7 +795,11 @@ impl FuseNode {
conn_id: desc.conn_id,
stream_id: rand::random(),
index: inode as usize - 2,
- name: desc.name.to_str().unwrap().to_owned(),
+ name: desc
+ .name
+ .to_str()
+ .map(|s| s.to_string())
+ .unwrap_or_default(),
parent: None,
attributes: InodeAttributes::from_description(inode, desc),
children: Vec::new(),
@@ -1140,7 +1144,7 @@ mod fuse_test {
}
fn build_single_file(prefix: &str) {
- let raw_name = "衬衫的价格为 9 镑 15 便士.txt";
+ let raw_name = "simple_test_file.txt";
let f_name = if prefix == "" {
raw_name.to_string()
} else {
diff --git a/libs/clipboard/src/platform/mod.rs b/libs/clipboard/src/platform/mod.rs
index 0a2988d2c..2be4ce809 100644
--- a/libs/clipboard/src/platform/mod.rs
+++ b/libs/clipboard/src/platform/mod.rs
@@ -52,9 +52,9 @@ pub fn create_cliprdr_context(
log::warn!("umount {:?} may fail: {:?}", mnt_path, e);
}
- let unix_ctx = unix::ClipboardContext::new(timeout, mnt_path.parse().unwrap())?;
+ let unix_ctx = unix::ClipboardContext::new(timeout, mnt_path.parse()?)?;
log::debug!("start cliprdr FUSE");
- unix_ctx.run().expect("failed to start cliprdr FUSE");
+ unix_ctx.run()?;
Ok(Box::new(unix_ctx) as Box<_>)
}
diff --git a/libs/clipboard/src/platform/unix/local_file.rs b/libs/clipboard/src/platform/unix/local_file.rs
index c9186c4fa..e24712efa 100644
--- a/libs/clipboard/src/platform/unix/local_file.rs
+++ b/libs/clipboard/src/platform/unix/local_file.rs
@@ -113,7 +113,7 @@ impl LocalFile {
let win32_time = self
.last_write_time
.duration_since(std::time::UNIX_EPOCH)
- .unwrap()
+ .unwrap_or_default()
.as_nanos() as u64
/ 100
+ LDAP_EPOCH_DELTA;
@@ -188,7 +188,7 @@ impl LocalFile {
pub fn read_exact_at(&mut self, buf: &mut [u8], offset: u64) -> Result<(), CliprdrError> {
self.load_handle()?;
- let handle = self.handle.as_mut().unwrap();
+ let handle = self.handle.as_mut()?;
if offset != self.offset.load(Ordering::Relaxed) {
handle
@@ -238,9 +238,9 @@ pub(super) fn construct_file_list(paths: &[PathBuf]) -> Result<Vec<LocalFile>, C
})?;
if mt.is_dir() {
- let dir = std::fs::read_dir(path).unwrap();
+ let dir = std::fs::read_dir(path)?;
for entry in dir {
- let entry = entry.unwrap();
+ let entry = entry?;
let path = entry.path();
constr_file_lst(&path, file_list, visited)?;
}
diff --git a/libs/clipboard/src/platform/unix/mod.rs b/libs/clipboard/src/platform/unix/mod.rs
index a58361f82..9a0861094 100644
--- a/libs/clipboard/src/platform/unix/mod.rs
+++ b/libs/clipboard/src/platform/unix/mod.rs
@@ -383,13 +383,11 @@ impl ClipboardContext {
let file_contents_id = fmt_lst
.iter()
.find(|(_, name)| name == FILECONTENTS_FORMAT_NAME)
- .map(|(id, _)| *id)
- .unwrap();
+ .map(|(id, _)| *id)?;
let file_descriptor_id = fmt_lst
.iter()
.find(|(_, name)| name == FILEDESCRIPTORW_FORMAT_NAME)
- .map(|(id, _)| *id)
- .unwrap();
+ .map(|(id, _)| *id)?;
add_remote_format(FILECONTENTS_FORMAT_NAME, file_contents_id);
add_remote_format(FILEDESCRIPTORW_FORMAT_NAME, file_descriptor_id);
diff --git a/libs/clipboard/src/platform/unix/url.rs b/libs/clipboard/src/platform/unix/url.rs
index ce97810c4..2ae520f4d 100644
--- a/libs/clipboard/src/platform/unix/url.rs
+++ b/libs/clipboard/src/platform/unix/url.rs
@@ -7,9 +7,9 @@ use crate::CliprdrError;
// url encode and decode is needed
const ENCODE_SET: percent_encoding::AsciiSet = percent_encoding::CONTROLS.add(b' ').remove(b'/');
-pub(super) fn encode_path_to_uri(path: &PathBuf) -> String {
- let encoded = percent_encoding::percent_encode(path.to_str().unwrap().as_bytes(), &ENCODE_SET)
- .to_string();
+pub(super) fn encode_path_to_uri(path: &PathBuf) -> io::Result<String> {
+ let encoded =
+ percent_encoding::percent_encode(path.to_str()?.as_bytes(), &ENCODE_SET).to_string();
format!("file://{}", encoded)
}
@@ -54,7 +54,7 @@ mod uri_test {
#[test]
fn test_conversion() {
let path = std::path::PathBuf::from("/home/rustdesk/pictures/🖼️.png");
- let uri = super::encode_path_to_uri(&path);
+ let uri = super::encode_path_to_uri(&path).unwrap();
assert_eq!(
uri,
"file:///home/rustdesk/pictures/%F0%9F%96%BC%EF%B8%8F.png"
diff --git a/libs/clipboard/src/platform/unix/x11.rs b/libs/clipboard/src/platform/unix/x11.rs
index 4ca3a2c0b..41b642640 100644
--- a/libs/clipboard/src/platform/unix/x11.rs
+++ b/libs/clipboard/src/platform/unix/x11.rs
@@ -89,7 +89,13 @@ impl SysClipboard for X11Clipboard {
fn set_file_list(&self, paths: &[PathBuf]) -> Result<(), CliprdrError> {
*self.former_file_list.lock() = paths.to_vec();
- let uri_list: Vec<String> = paths.iter().map(encode_path_to_uri).collect();
+ let uri_list: Vec<String> = {
+ let mut v = Vec::new();
+ for path in paths {
+ v.push(encode_path_to_uri(path)?);
+ }
+ v
+ };
let uri_list = uri_list.join("\n");
let text_uri_list_data = uri_list.as_bytes().to_vec();
let gnome_copied_files_data = ["copy\n".as_bytes(), uri_list.as_bytes()].concat();
diff --git a/libs/clipboard/src/platform/windows.rs b/libs/clipboard/src/platform/windows.rs
index 1148112b5..8fc917c6f 100644
--- a/libs/clipboard/src/platform/windows.rs
+++ b/libs/clipboard/src/platform/windows.rs
@@ -5,16 +5,16 @@
#![allow(non_snake_case)]
#![allow(deref_nullptr)]
-use std::{
- boxed::Box,
- ffi::{CStr, CString},
- result::Result,
-};
use crate::{
allow_err, send_data, ClipboardFile, CliprdrError, CliprdrServiceContext, ResultType,
ERR_CODE_INVALID_PARAMETER, ERR_CODE_SERVER_FUNCTION_NONE, VEC_MSG_CHANNEL,
};
use hbb_common::log;
+use std::{
+ boxed::Box,
+ ffi::{CStr, CString},
+ result::Result,
+};
// only used error code will be recorded here
/// success
@@ -779,7 +779,7 @@ pub fn server_format_list(
} else {
let n = match CString::new(format.1) {
Ok(n) => n,
- Err(_) => CString::new("").unwrap(),
+ Err(_) => CString::new("").unwrap_or_default(),
};
CLIPRDR_FORMAT {
formatId: format.0 as UINT32,
diff --git a/src/clipboard.rs b/src/clipboard.rs
index 973f948f6..9dbdfddda 100644
--- a/src/clipboard.rs
+++ b/src/clipboard.rs
@@ -60,7 +60,7 @@ fn parse_plain_uri_list(v: Vec<u8>) -> Result<String, String> {
#[cfg(all(target_os = "linux", feature = "unix-file-copy-paste"))]
impl ClipboardContext {
- pub fn new() -> Result<Self, String> {
+ pub fn new(_listen: bool) -> Result<Self, String> {
let clipboard = get_clipboard()?;
let string_getter = clipboard
.getter
@@ -95,14 +95,14 @@ impl ClipboardContext {
.load(clip, self.string_getter, prop, TIMEOUT)
.map_err(|e| e.to_string())?;
- let file_urls = get_clipboard()?.load(clip, self.text_uri_list, prop, TIMEOUT);
+ let file_urls = get_clipboard()?.load(clip, self.text_uri_list, prop, TIMEOUT)?;
- if file_urls.is_err() || file_urls.as_ref().unwrap().is_empty() {
+ if file_urls.is_err() || file_urls.as_ref().is_empty() {
log::trace!("clipboard get text, no file urls");
return String::from_utf8(text_content).map_err(|e| e.to_string());
}
- let file_urls = parse_plain_uri_list(file_urls.unwrap())?;
+ let file_urls = parse_plain_uri_list(file_urls)?;
let text_content = String::from_utf8(text_content).map_err(|e| e.to_string())?;
diff --git a/src/flutter.rs b/src/flutter.rs
index 0cce2ae71..d1e44008b 100644
--- a/src/flutter.rs
+++ b/src/flutter.rs
@@ -1069,12 +1069,9 @@ impl FlutterHandler {
// 1. "display 1" will not send the event.
// 2. "displays 0&1" will not send the event. Because it uses texutre render for now.
if !is_sent {
- self.display_rgbas
- .write()
- .unwrap()
- .get_mut(&display)
- .unwrap()
- .valid = false;
+ if let Some(rgba_data) = self.display_rgbas.write().unwrap().get_mut(&display) {
+ rgba_data.valid = false;
+ }
}
}
diff --git a/src/hbbs_http/http_client.rs b/src/hbbs_http/http_client.rs
index c4bb2452c..944e84ae6 100644
--- a/src/hbbs_http/http_client.rs
+++ b/src/hbbs_http/http_client.rs
@@ -24,14 +24,16 @@ macro_rules! configure_http_client {
if let Some(auth) = proxy.intercept.maybe_auth() {
let basic_auth =
format!("Basic {}", auth.get_basic_authorization());
- builder = builder.default_headers(
- vec![(
- reqwest::header::PROXY_AUTHORIZATION,
- basic_auth.parse().unwrap(),
- )]
- .into_iter()
- .collect(),
- );
+ if let Ok(auth) = basic_auth.parse() {
+ builder = builder.default_headers(
+ vec![(
+ reqwest::header::PROXY_AUTHORIZATION,
+ auth,
+ )]
+ .into_iter()
+ .collect(),
+ );
+ }
}
builder.build().unwrap_or_else(|e| {
info!("Failed to create a proxied client: {}", e);
diff --git a/src/server.rs b/src/server.rs
index e1f5d634c..fc33188f4 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -360,7 +360,12 @@ impl Server {
self.services
.keys()
.filter(|k| {
- Self::is_video_service_name(k) && self.services.get(*k).unwrap().is_subed(conn_id)
+ Self::is_video_service_name(k)
+ && self
+ .services
+ .get(*k)
+ .map(|s| s.is_subed(conn_id))
+ .unwrap_or(false)
})
.count()
}