From 981a67d781e226d867b60ecaea89d490e5c96a17 Mon Sep 17 00:00:00 2001 From: Joonas Koivunen Date: Sat, 22 Aug 2020 22:42:45 +0300 Subject: [PATCH] refactor: use ipfs.dag().resolve in http perhaps the error message requirements have changed, since this worked right away? aah nope, they must concern other uses of walk_path. well, this passes the tests either way. --- http/src/v0/dag.rs | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/http/src/v0/dag.rs b/http/src/v0/dag.rs index cce520d1..77465733 100644 --- a/http/src/v0/dag.rs +++ b/http/src/v0/dag.rs @@ -121,38 +121,23 @@ async fn inner_resolve( ipfs: Ipfs, opts: ResolveOptions, ) -> Result { - use crate::v0::refs::{walk_path, IpfsPath, WalkOptions}; + use ipfs::IpfsPath; use std::convert::TryFrom; let path = IpfsPath::try_from(opts.arg.as_str()).map_err(StringError::from)?; - let walk_opts = WalkOptions { - follow_dagpb_data: true, - }; - - let (current, _, remaining) = walk_path(&ipfs, &walk_opts, path) + let (resolved, remaining) = ipfs + .dag() + .resolve(path, /* FIXME: query */ true) .maybe_timeout(opts.timeout.map(StringSerialized::into_inner)) .await .map_err(StringError::from)? .map_err(StringError::from)?; - let remaining = { - let slashes = remaining.len(); - let mut buf = - String::with_capacity(remaining.iter().map(|s| s.len()).sum::() + slashes); - - for piece in remaining.into_iter().rev() { - if !buf.is_empty() { - buf.push('/'); - } - buf.push_str(&piece); - } - - buf - }; + let current = resolved.cid(); Ok(reply::json(&json!({ "Cid": { "/": current.to_string() }, - "RemPath": remaining, + "RemPath": StringSerialized(remaining), }))) }