feat: update shared directories at runtime
Client::set_shared_directories rescans the given roots into a fresh in-memory index, swaps it for peers, and re-announces the folder/file counts to the server. The current directory list moves into the client context so the running set is queryable. e2e-verified: a browser sees a directory that was added after login.
This commit is contained in:
@@ -46,7 +46,12 @@ impl Shares {
|
||||
|
||||
let mut files = Vec::new();
|
||||
let mut folder_count = 0;
|
||||
scan_root(root, &root_display_name(root), &mut files, &mut folder_count);
|
||||
scan_root(
|
||||
root,
|
||||
&root_display_name(root),
|
||||
&mut files,
|
||||
&mut folder_count,
|
||||
);
|
||||
Ok(Self::from_files(files, folder_count))
|
||||
}
|
||||
|
||||
@@ -278,8 +283,7 @@ mod tests {
|
||||
fn scan_many_merges_roots() {
|
||||
let root_a = temp_tree();
|
||||
let root_b = temp_tree();
|
||||
let shares =
|
||||
Shares::scan_many(&[root_a.clone(), root_b.clone()]);
|
||||
let shares = Shares::scan_many(&[root_a.clone(), root_b.clone()]);
|
||||
assert_eq!(shares.file_count(), 6);
|
||||
assert_eq!(shares.folder_count(), 4);
|
||||
// Files from both roots are reachable under their root's name.
|
||||
@@ -303,8 +307,7 @@ mod tests {
|
||||
std::fs::write(music_a.join("a.mp3"), b"a").unwrap();
|
||||
std::fs::write(music_b.join("b.mp3"), b"b").unwrap();
|
||||
|
||||
let shares =
|
||||
Shares::scan_many(&[music_a.clone(), music_b.clone()]);
|
||||
let shares = Shares::scan_many(&[music_a.clone(), music_b.clone()]);
|
||||
assert!(shares.get("music\\a.mp3").is_some());
|
||||
assert!(
|
||||
shares.get("music (2)\\b.mp3").is_some(),
|
||||
|
||||
Reference in New Issue
Block a user