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:
michel
2026-07-20 20:47:23 +02:00
parent 8389d525e7
commit a605431a10
9 changed files with 277 additions and 117 deletions
+19 -21
View File
@@ -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();