If you add a directory but only one file is new, the adding process will generally be faster. But if you have 1000s of files, while only 1% is newer, it might be faster to write a script that just adds what you want to add.
You can manipulate directories in IPFS with the ipfs object patch
commands.
USAGE
ipfs object patch - Create a new merkledag object based on an existing one.
SYNOPSIS
ipfs object patch
DESCRIPTION
'ipfs object patch <root> <cmd> <args>' is a plumbing command used to
build custom DAG objects. It mutates objects, creating new objects as a
result. This is the Merkle-DAG version of modifying an object.
SUBCOMMANDS
ipfs object patch add-link <root> <name> <ref> - Add a link to a given object.
ipfs object patch append-data <root> <data> - Append data to the data segment of a dag node.
ipfs object patch rm-link <root> <link> - Remove a link from an object.
ipfs object patch set-data <root> <data> - Set the data field of an IPFS object.
Use 'ipfs object patch <subcmd> --help' for more information about each command.
Quick example:
$ tree
.
└── test-directory
├── file-a
└── file-b
$ ipfs add -r test-directory
added QmSJY8R8qM1HWRTxWxtRwtdxTq6Jqgtx5GQ2RvrUJRUoRx test-directory/file-a
added QmeRjufJQ5oNb3PEmDFZeZ9jPuZRbp5Gnaeahcw8ogq7nd test-directory/file-b
added QmVK4zcfWHyEqHmkWqMPNTH1q3LyPndPCoE5PYRfq1V8A2 test-directory
$ echo "c file" >> test-directory/file-c
$ tree
.
└── test-directory
├── file-a
├── file-b
└── file-c
1 directory, 3 files
$ ipfs add test-directory/file-c
added QmPrLX9CiHph7yF5ZtU1ypxxdxgNX3RYLhjcJVSqyCTGr3 file-c
$ ipfs object patch add-link QmVK4zcfWHyEqHmkWqMPNTH1q3LyPndPCoE5PYRfq1V8A2 file-c QmPrLX9CiHph7yF5ZtU1ypxxdxgNX3RYLhjcJVSqyCTGr3
QmZm33yVb5uXAMjZDbL7Q1x69ZTFL6e65sMvYof1R7eh1J
What happened on the example above is:
- Use
tree
to print the directory structure - Add directory with
ipfs add
- Create a new file named
file-c
- Check directory structure again
- Add just
file-c
to IPFS - Use
ipfs object patch add-link
to add a new link to our directory object. - The output returns from the
add-link
command is the new hash to our root-directory with the updated link
$ ipfs object patch add-link QmVK4zcfWHyEqHmkWqMPNTH1q3LyPndPCoE5PYRfq1V8A2 file-c QmPrLX9CiHph7yF5ZtU1ypxxdxgNX3RYLhjcJVSqyCTGr3
Translates to
$ ipfs object patch add-link <root-directory> <link-name> <link-hash>
Where root-directory
is the hash you want to add a link in.
link-name
is the name of that link (for example, the filename)
link-hash
is the hash that link should resolve to.