Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Commit

Permalink
fix: Better handling of removed content in orb (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdata authored Aug 10, 2023
1 parent 36e42fb commit b811e68
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 96 deletions.
115 changes: 26 additions & 89 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions rust/noosphere-cli/src/native/commands/sphere/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,29 @@ Author: {author}"#

if !content_changes.is_empty() {
let mut removed = Vec::new();
let mut any_content_added = false;

for change in content_changes {
match change {
MapOperation::Add { key, .. } => info!("{: >12} /{key}", "Modified"),
MapOperation::Add { key, .. } => {
any_content_added = true;
info!("{: >12} /{key}", "Modified")
}
MapOperation::Remove { key } => removed.push(key),
}
}

info!("")
if any_content_added {
info!("");
}

for slug in &removed {
info!("{: >12} /{slug}", "Removed");
}

if !removed.is_empty() {
info!("")
}
}

let petname_changes = mutation.identities().changes();
Expand Down
8 changes: 8 additions & 0 deletions rust/noosphere-cli/src/native/render/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ impl SphereWriter {
pub async fn remove_content(&self, slug: &str) -> Result<()> {
if self.is_root_writer() {
let slug_path = self.paths.slug(slug)?;

if !slug_path.exists() {
trace!(
"No slug link found at '{}', skipping removal of '{slug}'...",
slug_path.display()
);
}

let file_path = tokio::fs::read_link(&slug_path).await?;

let _ = remove_symlink_file(slug_path);
Expand Down
15 changes: 14 additions & 1 deletion rust/noosphere-cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,21 @@ mod multiplayer {
.spawn(move |mut ctx| async move {
// Give the graph state the opportunity to "settle"
wait(2).await;

// Change up petnames a bit
ctx.set_petname("peer3", None).await?;
ctx.set_petname("peer2", None).await?;
ctx.set_petname("peer2-renamed", Some(sphere_2_id)).await?;

// Add some new content...
ctx.write("never-seen", "text/plain", "boo".as_bytes(), None)
.await?;
ctx.save(None).await?;

// ...and remove it again:
ctx.remove("never-seen").await?;
ctx.save(None).await?;

ctx.sync(SyncRecovery::Retry(3)).await?;
wait(2).await;
let version = ctx.sync(SyncRecovery::Retry(3)).await?;
Expand Down Expand Up @@ -410,6 +421,8 @@ mod multiplayer {
"@peer2-renamed/@peer3-of-peer2/@peer4-of-peer3/@peer5/content5.txt";

let unexpected_content = [
// Content added and removed remotely before local sync
"never-seen",
// Peer removed
"@peer3/content3.txt",
// Peer renamed
Expand All @@ -430,7 +443,7 @@ mod multiplayer {
wait(1).await;

// Sync again, but with a greater render depth
cli.orb(&["sphere", "sync", "--auto-retry", "3", "--render-depth", "4"])
cli.orb(&["sphere", "sync", "--auto-retry", "3", "--render-depth", "5"])
.await?;

// Previously omitted peer should be rendered now
Expand Down
Loading

0 comments on commit b811e68

Please sign in to comment.