How can I find out if a given content can be found in IPFS?

135 views Asked by At

I want to see if a given string ("hello" in this case) is accessible via IPFS. I am trying this:

echo hello | ipfs add -nq | ipfs cat

I am getting this:

Error: lock /root/.ipfs/repo.lock: someone else has the lock

What's going on? Is there a global lock, or is IPFS just protecting itself from a race condition that could have happened if I hadn't specified the -n flag?

This seems to work:

HASH=`echo hithere | ipfs add -nq` &&  ipfs cat $HASH

However, I wonder whether there is a more idiomatic way. This must be a fairly standard thing to do.

1

There are 1 answers

0
Jorropo On

What's going on?

Your daemon is not running, so both ipfs add and ipfs cat tries to start an offline daemon at the same time which doesn't work (only one daemon per IPFS_PATH can run).

You need to run ipfs daemon in the background first, so then the commands will just hit ipfs daemon's API instead of starting their own daemon.

This seems to work:

HASH=`echo hithere | ipfs add -nq` &&  ipfs cat $HASH

Yes because you are using && which schedule them to wait on each other first.