Skip to content

Commit

Permalink
Fix potential bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubelotix committed Jun 1, 2024
1 parent cf3cb75 commit d7319ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
15 changes: 4 additions & 11 deletions daemon/src/index/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl DocumentIndex {
for (child_cid, child_name, child_is_folder) in new_links {
let child_cid = normalize_cid(child_cid).unwrap();
if child_is_folder {
self.add_ancestor(&child_cid, child_name, &cid).await;
self.add_ancestor(&child_cid, child_name, child_is_folder, &cid).await;
if !listed.contains(&child_cid) {
to_list.push(child_cid);
}
Expand All @@ -108,7 +108,7 @@ impl DocumentIndex {
let Ok(document) = fetch_document(ipfs_rpc, &cid).await else {continue};
let Some(inspected) = inspect_document(document) else {continue};
self.add_document(&cid, inspected).await;
self.add_ancestor(&cid, name, &parent_cid).await;
self.add_ancestor(&cid, name, false, &parent_cid).await;
i += 1;
if i % 500 == 0 {
debug!("Still loading files ({i} in {:.02})", start.elapsed().as_secs_f32());
Expand Down Expand Up @@ -138,15 +138,8 @@ impl DocumentIndex {
self.inner.write().await.add_document(cid, doc);
}

pub async fn add_ancestor(&self, cid: &String, name: String, folder_cid: &String) {
self.inner.write().await.add_ancestor(cid, name, folder_cid);
}

pub async fn add_ancestors(&self, ancestors: Vec<(&String, String, &String)>) {
let mut inner = self.inner.write().await;
for (cid, name, folder_cid) in ancestors {
inner.add_ancestor(cid, name, folder_cid);
}
pub async fn add_ancestor(&self, cid: &String, name: String, is_folder: bool, folder_cid: &String) {
self.inner.write().await.add_ancestor(cid, name, is_folder, folder_cid);
}

pub async fn build_path(&self, cid: &String) -> Option<Vec<Vec<String>>> {
Expand Down
6 changes: 4 additions & 2 deletions daemon/src/index/inner_common.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use super::*;

impl DocumentIndexInner {
pub fn add_ancestor(&mut self, cid: &String, name: String, folder_cid: &String) {
pub fn add_ancestor(&mut self, cid: &String, name: String, is_folder: bool, folder_cid: &String) {
let lcid = match self.cids.get_by_right(cid) {
Some(lcid) => lcid.to_owned(),
None => {
let lcid = LocalCid(self.cid_counter);
self.cid_counter += 1;
self.cids.insert(lcid, cid.clone());
self.folders.insert(lcid);
lcid
}
};
if is_folder {
self.folders.insert(lcid);
}

let ancestor_lcid = match self.cids.get_by_right(folder_cid) {
Some(lcid) => lcid.to_owned(),
Expand Down

0 comments on commit d7319ca

Please sign in to comment.