Skip to content

Commit

Permalink
Filestore: Update README and add testcase using new add-ss functionally
Browse files Browse the repository at this point in the history
With the new "add-ss" command it is now possible to add files to the
filestore with the daemon online.  Update README to reflect this
fact and create some new test cases to test the new functionally.

License: MIT
Signed-off-by: Kevin Atkinson <[email protected]>
  • Loading branch information
kevina committed May 12, 2016
1 parent 3152f8c commit 07aec44
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 8 deletions.
38 changes: 30 additions & 8 deletions filestore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,41 @@ without duplicating the content in the IPFS datastore

## Quick start

To add a file to IPFS without copying the contents use `add --no-copy`
or to add a directory use `add -r --no-copy`. (Throughout this
document all command are assumed to start with `ipfs` so `add
--no-copy` really mains `ipfs add --no-copy`)

Note: For now the daemon running must currently be offline otherwise
you will get an error: `Reader does not support setting ExtraInfo.`
To add a file to IPFS without copying, first bring the daemon offline
and then use `add --no-copy` or to add a directory use `add -r
--no-copy`. (Throughout this document all command are assumed to
start with `ipfs` so `add --no-copy` really mains `ipfs add
--no-copy`). For example to add the file `hello.txt` use:
```
ipfs add --no-copy hello.txt
```

The file or directory will then be added. You can now bring the
daemon online and try to retrieve it from another node such as the
ipfs.io gateway.

If the contents of an added file have changed the block will invalid.
To add a file to IPFS without copying and the daemon online you must
first enable API.ServerSideAdds using:
```
ipfs config API.ServerSideAdds --bool true
```
This will enable adding files from the filesystem the server is on.
*This option should be used with care since it will allow anyone with
access to the API Server access to any files that the daemon has
permission to read.* For security reasons it is probably best to only
enable this on a single user system and to make sure the API server is
configured to the default value of only binding to the localhost
(`127.0.0.1`).

With the API.ServerSideAdds option enabled you can add files using
`add-ss --no-copy`. Since the file will read by the daemon the
absolute path must be specified. For example, to add the file
`hello.txt` in the local directory use something like:
```
ipfs add-ss --no-copy "`pwd`"/hello.txt
```

If the contents of an added file have changed the block will become invalid.
The filestore uses the modification-time to determine if a file has changed.
If the mod-time of a file differs from what is expected the contents
of the block are rechecked by recomputing the multihash and failing if
Expand Down
44 changes: 44 additions & 0 deletions test/sharness/t0261-filestore-online.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh
#
# Copyright (c) 2014 Christian Couder
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test filestore"

. lib/test-filestore-lib.sh
. lib/test-lib.sh

test_init_ipfs

test_expect_success "enable API.ServerSideAdds" '
ipfs config API.ServerSideAdds --bool true
'

test_launch_ipfs_daemon

test_add_cat_file "add-ss --no-copy" "`pwd`"

test_add_cat_5MB "add-ss --no-copy" "`pwd`"

cat <<EOF > add_expect
added QmQhAyoEzSg5JeAzGDCx63aPekjSGKeQaYs4iRf4y6Qm6w adir
added QmSr7FqYkxYWGoSfy8ZiaMWQ5vosb18DQGCzjwEQnVHkTb adir/file3
added QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH adir/file1
added QmZm53sWMaAQ59x56tFox8X9exJFELWC33NLjK6m8H7CpN adir/file2
EOF

test_expect_success "testing add-ss -r --no-copy" '
mkdir adir &&
echo "Hello Worlds!" > adir/file1 &&
echo "HELLO WORLDS!" > adir/file2 &&
random 5242880 41 > adir/file3 &&
ipfs add-ss --no-copy -r "`pwd`/adir" | LC_ALL=C sort > add_actual &&
test_cmp add_expect add_actual &&
ipfs cat QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH > cat_actual
test_cmp adir/file1 cat_actual
'

test_kill_ipfs_daemon

test_done

0 comments on commit 07aec44

Please sign in to comment.