This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "sync-linux"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib"]
|
||||
|
||||
[dependencies]
|
||||
# 不依赖 sync-core,避免循环依赖
|
||||
notify = { version = "7", features = ["macos_fsevent"] }
|
||||
walkdir = "2"
|
||||
thiserror = { workspace = true }
|
||||
tracing = "0.1"
|
||||
anyhow = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
async-trait = "0.1"
|
||||
@@ -0,0 +1,80 @@
|
||||
#![cfg(target_os = "linux")]
|
||||
|
||||
//! Linux 平台适配层
|
||||
//!
|
||||
//! 提供文件系统监听 (notify/inotify) 用于:
|
||||
//! - 实时检测本地文件变更
|
||||
//! - inotify 限制检测与配置
|
||||
//! - 混合模式(事件+轮询)切换
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
pub struct LinuxAdapter {
|
||||
watcher: Option<notify::RecommendedWatcher>,
|
||||
}
|
||||
|
||||
impl Default for LinuxAdapter {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl LinuxAdapter {
|
||||
pub fn new() -> Self {
|
||||
Self { watcher: None }
|
||||
}
|
||||
|
||||
/// 启动文件监听 (Phase 3)
|
||||
pub fn start_watching(&mut self, _root: &Path) -> anyhow::Result<()> {
|
||||
// Phase 3: 实现 notify 监听
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 停止监听
|
||||
pub fn stop_watching(&mut self) -> anyhow::Result<()> {
|
||||
if let Some(w) = self.watcher.take() {
|
||||
drop(w);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// inotify 限制检测
|
||||
pub struct InotifyConfig;
|
||||
|
||||
impl InotifyConfig {
|
||||
pub fn check_limits() -> InotifyStatus {
|
||||
let max_watches = std::fs::read_to_string("/proc/sys/fs/inotify/max_user_watches")
|
||||
.ok()
|
||||
.and_then(|s| s.trim().parse().ok())
|
||||
.unwrap_or(8192);
|
||||
|
||||
let max_user_instances = std::fs::read_to_string("/proc/sys/fs/inotify/max_user_instances")
|
||||
.ok()
|
||||
.and_then(|s| s.trim().parse().ok())
|
||||
.unwrap_or(128);
|
||||
|
||||
InotifyStatus {
|
||||
max_watches,
|
||||
max_user_instances,
|
||||
recommendation: if max_watches < 524288 {
|
||||
Some("建议执行: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p".to_string())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InotifyStatus {
|
||||
pub max_watches: u64,
|
||||
pub max_user_instances: u64,
|
||||
pub recommendation: Option<String>,
|
||||
}
|
||||
|
||||
/// 占位符信息 (Linux 不使用,保持接口一致)
|
||||
pub struct PlaceholderEntry {
|
||||
pub relative_path: String,
|
||||
pub file_size: u64,
|
||||
pub is_dir: bool,
|
||||
}
|
||||
Reference in New Issue
Block a user