The CLI help says that ipfs files cp can be used to copy files into mfs:
$ ipfs files cp --help
USAGE
ipfs files cp <source> <dest> - Copy files into mfs.
It doesn't seem to work like that though:
$ ipfs files cp ./my-file.txt /my-file.txt
Error: paths must start with a leading slash
I think what this is meant to mean (at least what I have found) is that it only copies from IPFS-at-large, not from disk:
$ ipfs files cp /ipfs/QmV5QdWAVbYCpcEspWu4tiCtVfdL9SESidLmnXLEJ82gdL /research-stuff
So if you want to copy from disk:
$ ipfs add ./my-file.txt
$ ipfs files cp /ipfs/<hash from previous command> /my-file.txt
The help text could still be clearer on that, though. I definitely tried to do what you鈥檙e describing the first time :P
Ok, so the source can be IPFS-at-large or the existing mfs, but IPFS-at-large seems to win in the case where there's a matching path in your mfs:
$ echo 'alive' | ipfs files write --create /dog.txt
$ ipfs files cp /dog.txt /cat.txt
$ ipfs files read /cat.txt
alive
$ ipfs files stat --hash /cat.txt
QmcDam5WmvRs3ExhQrUSYdT43iERyDdVVPkmtW5L2y64h9
$ ipfs files mkdir /ipfs
$ echo 'dead' | ipfs files write --create /ipfs/QmcDam5WmvRs3ExhQrUSYdT43iERyDdVVPkmtW5L2y64h9
$ ipfs files cp /ipfs/QmcDam5WmvRs3ExhQrUSYdT43iERyDdVVPkmtW5L2y64h9 /shroedinger.txt
$ ipfs files read /shroedinger.txt
...drumroll
alive
Yeah, I believe that鈥檚 a known issue based on comments like this: https://github.com/ipfs/go-ipfs/issues/4602#issuecomment-360927582
I had to find this issue after searching quite a lot (maybe I was just unlucky) learn how to use files api :sweat_smile:
@nickdex, @achingbrain can you review: https://github.com/ipfs/go-ipfs/pull/7069 ?
@hsanjaun looks much better now, thank you.
Most helpful comment
Ok, so the source can be IPFS-at-large or the existing mfs, but IPFS-at-large seems to win in the case where there's a matching path in your mfs:
...drumroll