Reverse refs (or how to find parent hash)

From @lockedshadow on Mon Feb 15 2016 00:20:59 GMT+0000 (UTC)

First of all, apologize for my bad english. Hope that you can understand it.

For example, we created directory named «foo» and put to it files named «bar», «baz», then pinned them recursively by ipfs add command, like this:

mkdir foo
echo bar > ./foo/bar
echo baz > ./foo/baz
ipfs add -r ./foo

And next we have result:

added QmTz3oc4gdpRMKP2sdGUPZTAGRngqjsi99BPoztyP53JMM foo/bar
added QmWLdkp93sNxGRjnFHPaYg8tCQ35NBY3XPn6KiETd3Z4WR foo/baz
added QmRoqGfDXiwoUBMTKtU9Hbd8W1DTbSGZ4rJmUGtmNXbgY2 foo

Is there an easy way to determine hash of directory «foo» and other pinned directories which contains this objects, if now we know only hashes of «bar» and «baz» (QmTz3oc4gdpRMKP2sdGUPZTAGRngqjsi99BPoztyP53JMM and QmWLdkp93sNxGRjnFHPaYg8tCQ35NBY3XPn6KiETd3Z4WR)? Something like ipfs refs --reverse command.

(At least we can use this workaround: for hash in $(ipfs pin ls -q) ; do ipfs refs -e $hash | grep [hash] ; done, but maybe built-in solution available?)


Copied from original issue: https://github.com/ipfs/faq/issues/95

From @lernisto on Fri Feb 26 2016 03:11:48 GMT+0000 (UTC)

A “directory” is just a set of links to other hashes. It is not possible to include a “…” ref in the directory, because such a reference would introduce a cycle into the DAG. A hash is somewhat like a private key in that if you lose it, there is no general way to recover it (short of re-hashing the content). Your workaround is probably the best solution, if you don’t want to store the parent hash in IPNS.