Go-ipfs: ipfs files cp command help text inaccurate

Created on 3 May 2018  路  6Comments  路  Source: ipfs/go-ipfs

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
good first issue help wanted

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:

$ 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

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mikaela picture Mikaela  路  3Comments

magik6k picture magik6k  路  3Comments

kallisti5 picture kallisti5  路  3Comments

emelleme picture emelleme  路  3Comments

0x6431346e picture 0x6431346e  路  3Comments