patch: implement statfs to improve OSX paste

Signed-off-by: ClSlaid <cailue@bupt.edu.cn>
This commit is contained in:
ClSlaid 2023-10-29 07:37:18 +08:00
parent 3dfa0525bd
commit 434242858f
No known key found for this signature in database
GPG Key ID: E0A5F564C51C056E
2 changed files with 28 additions and 10 deletions

View File

@ -154,6 +154,11 @@ impl fuser::Filesystem for FuseClient {
let mut server = self.server.lock(); let mut server = self.server.lock();
server.getattr(req, ino, reply) server.getattr(req, ino, reply)
} }
fn statfs(&mut self, req: &fuser::Request<'_>, ino: u64, reply: fuser::ReplyStatfs) {
let mut server = self.server.lock();
server.statfs(req, ino, reply)
}
} }
/// fuse server /// fuse server
@ -486,6 +491,15 @@ impl fuser::Filesystem for FuseServer {
let attr = (&entry.attributes).into(); let attr = (&entry.attributes).into();
reply.attr(&std::time::Duration::default(), &attr) reply.attr(&std::time::Duration::default(), &attr)
} }
fn statfs(&mut self, _req: &fuser::Request<'_>, _ino: u64, reply: fuser::ReplyStatfs) {
let mut blocks = 0;
for file in self.files.iter() {
blocks += file.attributes.size / (BLOCK_SIZE as u64)
+ (file.attributes.size % (BLOCK_SIZE as u64) != 0) as u64;
}
reply.statfs(blocks, 0, 0, 0, 0, BLOCK_SIZE, 512, BLOCK_SIZE)
}
} }
impl FuseServer { impl FuseServer {

View File

@ -6,23 +6,29 @@ use std::{
use cacao::pasteboard::{Pasteboard, PasteboardName}; use cacao::pasteboard::{Pasteboard, PasteboardName};
use hbb_common::log; use hbb_common::log;
use once_cell::sync::Lazy;
use parking_lot::Mutex; use parking_lot::Mutex;
use crate::{platform::unix::send_format_list, CliprdrError}; use crate::{platform::unix::send_format_list, CliprdrError};
use super::SysClipboard; use super::SysClipboard;
static NS_PASTEBOARD: Lazy<Pasteboard> = Lazy::new(|| Pasteboard::named(PasteboardName::General));
#[inline] #[inline]
fn wait_file_list() -> Option<Vec<PathBuf>> { fn wait_file_list() -> Option<Vec<PathBuf>> {
NS_PASTEBOARD let pb = Pasteboard::named(PasteboardName::General);
.get_file_urls() pb.get_file_urls()
.ok() .ok()
.map(|v| v.into_iter().map(|nsurl| nsurl.to_path_buf()).collect()) .map(|v| v.into_iter().map(|nsurl| nsurl.pathbuf()).collect())
} }
#[inline]
fn set_file_list(file_list: &[PathBuf]) -> Result<(), CliprdrError> {
let pb = Pasteboard::named(PasteboardName::General);
pb.set_files(file_list.to_vec())
.map_err(|_| CliprdrError::ClipboardInternalError)
}
pub struct NsPasteboard { pub struct NsPasteboard {
stopped: AtomicBool,
ignore_path: PathBuf, ignore_path: PathBuf,
former_file_list: Mutex<Vec<PathBuf>>, former_file_list: Mutex<Vec<PathBuf>>,
@ -46,9 +52,7 @@ impl NsPasteboard {
impl SysClipboard for NsPasteboard { impl SysClipboard for NsPasteboard {
fn set_file_list(&self, paths: &[PathBuf]) -> Result<(), CliprdrError> { fn set_file_list(&self, paths: &[PathBuf]) -> Result<(), CliprdrError> {
*self.former_file_list.lock() = paths.to_vec(); *self.former_file_list.lock() = paths.to_vec();
NS_PASTEBOARD set_file_list(paths)
.set_file_urls(paths)
.map_err(|_| CliprdrError::ClipboardInternalError)
} }
fn start(&self) { fn start(&self) {
@ -67,7 +71,7 @@ impl SysClipboard for NsPasteboard {
} }
}; };
let filtered = paths let filtered = file_list
.into_iter() .into_iter()
.filter(|pb| !pb.starts_with(&self.ignore_path)) .filter(|pb| !pb.starts_with(&self.ignore_path))
.collect::<Vec<_>>(); .collect::<Vec<_>>();