From 07aec449e37c7e7894b52944b3dfa1c3ae83eb57 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Thu, 12 May 2016 01:31:09 -0400 Subject: [PATCH] Filestore: Update README and add testcase using new add-ss functionally 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 --- filestore/README.md | 38 ++++++++++++++++----- test/sharness/t0261-filestore-online.sh | 44 +++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 8 deletions(-) create mode 100755 test/sharness/t0261-filestore-online.sh diff --git a/filestore/README.md b/filestore/README.md index 67a3622e585..49bbfd6fc32 100644 --- a/filestore/README.md +++ b/filestore/README.md @@ -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 diff --git a/test/sharness/t0261-filestore-online.sh b/test/sharness/t0261-filestore-online.sh new file mode 100755 index 00000000000..002d1dbe83f --- /dev/null +++ b/test/sharness/t0261-filestore-online.sh @@ -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 < 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