feat: multiple shared directories
Shares::scan_many merges several roots into one index, suffixing duplicate root names so virtual paths cannot collide, and skipping unreadable roots instead of failing. ClientSettings now takes shared_directories: Vec<String>; config gains a shared_dirs list (combined with the single shared_dir and --shared-dir, deduped), with an explicitly empty value still disabling sharing and the share-what-you-download default unchanged.
This commit is contained in:
@@ -23,27 +23,25 @@ impl Client {
|
||||
|
||||
let listen_sender = sender.clone();
|
||||
|
||||
// Scan the shared directory once into the read-only index, and report
|
||||
// the real folder/file counts to the server on login.
|
||||
let shares = match self.shared_directory.as_deref() {
|
||||
Some(dir) if !dir.trim().is_empty() => {
|
||||
match Shares::scan(std::path::Path::new(dir)) {
|
||||
Ok(scanned) => {
|
||||
info!(
|
||||
"Sharing {} files in {} folders from {}",
|
||||
scanned.file_count(),
|
||||
scanned.folder_count(),
|
||||
dir
|
||||
);
|
||||
Arc::new(scanned)
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to scan shared directory {}: {}", dir, e);
|
||||
Arc::new(Shares::empty())
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => Arc::new(Shares::empty()),
|
||||
// Scan the shared directories once into the read-only index, and
|
||||
// report the real folder/file counts to the server on login.
|
||||
let roots: Vec<std::path::PathBuf> = self
|
||||
.shared_directories
|
||||
.iter()
|
||||
.filter(|dir| !dir.trim().is_empty())
|
||||
.map(std::path::PathBuf::from)
|
||||
.collect();
|
||||
let shares = if roots.is_empty() {
|
||||
Arc::new(Shares::empty())
|
||||
} else {
|
||||
let scanned = Shares::scan_many(&roots);
|
||||
info!(
|
||||
"Sharing {} files in {} folders from {} directories",
|
||||
scanned.file_count(),
|
||||
scanned.folder_count(),
|
||||
roots.len()
|
||||
);
|
||||
Arc::new(scanned)
|
||||
};
|
||||
let shared_folder_count = shares.folder_count();
|
||||
let shared_file_count = shares.file_count();
|
||||
|
||||
@@ -97,9 +97,9 @@ pub struct ClientSettings {
|
||||
pub server_address: PeerAddress,
|
||||
pub enable_listen: bool,
|
||||
pub listen_port: u16,
|
||||
/// Directory whose files are shared with (uploaded to) other peers.
|
||||
/// `None` means nothing is shared.
|
||||
pub shared_directory: Option<String>,
|
||||
/// Directories whose files are shared with (uploaded to) other peers.
|
||||
/// Empty means nothing is shared.
|
||||
pub shared_directories: Vec<String>,
|
||||
}
|
||||
|
||||
impl ClientSettings {
|
||||
@@ -126,7 +126,7 @@ impl Default for ClientSettings {
|
||||
),
|
||||
enable_listen: true,
|
||||
listen_port: DEFAULT_LISTEN_PORT,
|
||||
shared_directory: None,
|
||||
shared_directories: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -617,7 +617,7 @@ pub struct Client {
|
||||
address: PeerAddress,
|
||||
username: String,
|
||||
password: String,
|
||||
shared_directory: Option<String>,
|
||||
shared_directories: Vec<String>,
|
||||
server_handle: Option<ActorHandle<ServerMessage>>,
|
||||
context: Arc<RwLock<ClientContext>>,
|
||||
}
|
||||
@@ -639,16 +639,16 @@ impl Client {
|
||||
address: settings.server_address,
|
||||
username: settings.username,
|
||||
password: settings.password,
|
||||
shared_directory: settings.shared_directory,
|
||||
shared_directories: settings.shared_directories,
|
||||
context: Arc::new(RwLock::new(ClientContext::new())),
|
||||
server_handle: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The directory whose files are shared with other peers, if configured.
|
||||
/// The directories whose files are shared with other peers.
|
||||
#[must_use]
|
||||
pub fn shared_directory(&self) -> Option<&str> {
|
||||
self.shared_directory.as_deref()
|
||||
pub fn shared_directories(&self) -> &[String] {
|
||||
&self.shared_directories
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user