I know that IPFS supports directories additionally to just files. But I don’t quite understand how they work, and more importantly what they can do.
I’m hoping directories might be able to provide a workaround to needing IPNS for every aspect of a dynamic website, as is implied by file immutability. If files could be added to directories in which they may be referenced by a file name, this would make a lot of additional abilities possible.
First of all I wanted to know how you can add a file to a directory or remove it from one. Is there a command of the form “ipfs add my_file.jpg ipns_name.com/my_directory”?
If that’s possible: Can a file be referenced by its file name rather than its hash from a directory?
Lastly: Can directories be given specific rights protected by a key or password? For instance: Only the owner can delete files from the directory, but others can add new files or read existing files.
1 Like
Directories are also immutable. Think of them as files that point to other files.
Unfortunately, we don’t have any built-in support for authentication or encryption. You can layer that on-top of IPFS but you’ll have to do that yourself.
If you’re looking for a way to work with files (mutably) in IPFS, take a look at the ipfs files
command. That gives you a local mutable filesystem stored in ipfs. You can get the current IPFS hash of any file in that filesystem by running ipfs files stat --hash /path/to/my/file
.
1 Like
Now that is very helpful! I had no idea you can also reference files by a filename in IPFS, I thought the hash is all that is ever available. So if I update a file with the right arguments, can I still keep the file name… meaning the “ipfs files” command will return the hash of the updated file for a given name?
So if I update a file with the right arguments, can I still keep the file name… meaning the “ipfs files” command will return the hash of the updated file for a given name?
Yes. The easiest way is to simply overwrite the file but you can also, e.g., write to it with ipfs files write ...
. Eventually, we’d like to provide a separate fuse daemon so you can mount this as a virtual filesystem but we don’t have one yet.
1 Like
Very interesting! Virtual file system would be nice too… in this case the best use would be globally (so you can reference a changing file the same way everywhere).
1 Like