Move Store::update_worktree
to Db::update_worktree
This commit is contained in:
parent
4b1dcf2d55
commit
e9eadcaa6a
4 changed files with 139 additions and 67 deletions
|
@ -3,7 +3,7 @@ use anyhow::{anyhow, Result};
|
|||
use collections::{btree_map, BTreeMap, BTreeSet, HashMap, HashSet};
|
||||
use rpc::{proto, ConnectionId};
|
||||
use serde::Serialize;
|
||||
use std::{path::PathBuf, str};
|
||||
use std::path::PathBuf;
|
||||
use tracing::instrument;
|
||||
|
||||
pub type RoomId = u64;
|
||||
|
@ -325,37 +325,6 @@ impl Store {
|
|||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn update_worktree(
|
||||
&mut self,
|
||||
connection_id: ConnectionId,
|
||||
project_id: ProjectId,
|
||||
worktree_id: u64,
|
||||
worktree_root_name: &str,
|
||||
removed_entries: &[u64],
|
||||
updated_entries: &[proto::Entry],
|
||||
scan_id: u64,
|
||||
is_last_update: bool,
|
||||
) -> Result<Vec<ConnectionId>> {
|
||||
let project = self.write_project(project_id, connection_id)?;
|
||||
|
||||
let connection_ids = project.connection_ids();
|
||||
let mut worktree = project.worktrees.entry(worktree_id).or_default();
|
||||
worktree.root_name = worktree_root_name.to_string();
|
||||
|
||||
for entry_id in removed_entries {
|
||||
worktree.entries.remove(entry_id);
|
||||
}
|
||||
|
||||
for entry in updated_entries {
|
||||
worktree.entries.insert(entry.id, entry.clone());
|
||||
}
|
||||
|
||||
worktree.scan_id = scan_id;
|
||||
worktree.is_complete = is_last_update;
|
||||
Ok(connection_ids)
|
||||
}
|
||||
|
||||
pub fn project_connection_ids(
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
|
@ -384,24 +353,6 @@ impl Store {
|
|||
}
|
||||
}
|
||||
|
||||
fn write_project(
|
||||
&mut self,
|
||||
project_id: ProjectId,
|
||||
connection_id: ConnectionId,
|
||||
) -> Result<&mut Project> {
|
||||
let project = self
|
||||
.projects
|
||||
.get_mut(&project_id)
|
||||
.ok_or_else(|| anyhow!("no such project"))?;
|
||||
if project.host_connection_id == connection_id
|
||||
|| project.guests.contains_key(&connection_id)
|
||||
{
|
||||
Ok(project)
|
||||
} else {
|
||||
Err(anyhow!("no such project"))?
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn check_invariants(&self) {
|
||||
for (connection_id, connection) in &self.connections {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue