Add a UnixFS `Directory` that hides implementation details and helps to
distinguish *what* is a UnixFS directory.
Replace the `unixfs.io.Directory` structure that contained the HAMT and basic
directory implementations (through inner pointers) with an interface containing
the same methods. Implement those methods in two clearly distinct structures for
each implementation (`BasicDirectory` and `HAMTDirectory`) avoiding pointer
logic and clearly differentiating which implementation does what.
The potential basic to HAMT transition was being hidden behind the `AddChild`
call at the UnixFS layer (changing one implementation pointer with the other
one), it is now being explicitly done at the MFS layer.
Rename the `dirbuilder.go` file to `directory.go` and change the `Directory` MFS
attribute `dirbuilder` to `unixfsDir` to be consistent.
License: MIT
Signed-off-by: Lucas Molas <schomatis@gmail.com>
Keep the code style consistent. since all package alias are lowercase words, no need Camel Peak Name.
License: MIT
Signed-off-by: Spartucus <niubob@163.com>
Instead of checking if Routing is a DHT (because it can now be a tiered
router and still contain a DHT), stash the DHT in a separate field in the IPFS
node (same as we do with the PSRouter).
fixes#5197
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
This makes use of the PersistentDatastore DiskUsage method to
obtain the Repo's storage usage (GetStorageUsage()).
Additionally, the --size-only flag has been added to the
"ipfs repo stat" command. This avoids counting the number of objects
in the repository and returns faster.
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
Namesys returns `ErrResolveRecursion` when it stops recursing due to a depth
limit. It doesn't return success.
Alternative to #5199.
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
Focus on the UnixFS layer and avoid explicit references to protocol buffers
format (used to serialize objects of that layer). Use the `unixfs.FSNode`
structure which it abstracts from the `unixfs.pb.Data` format.
Replace `PBDagReader` field `ftpb.Data` with `ft.FSNode`, renaming it to `file`
(which is the type of UnixFS object represented in the reader) and changing its
comment removing the "cached" reference, as this structure is not used here as a
cache (`PBDagReader` doesn't modify the DAG, it's read-only). Also, removed
unused `ProtoNode` field to avoid confusions, as it would normally be present if
the `FSNode` was in fact used as a cache of the contents of the `ProtoNode`.
An example of the advantage of shifting the focus from the format to the UnixFS
layer is dropping the of use `len(pb.Blocksizes)` in favor of the more clear
`NumChildren()` abstraction.
Added `BlockSize()` accessor.
License: MIT
Signed-off-by: Lucas Molas <schomatis@gmail.com>
This breaks commands like `ipfs update` that expect IPFS to *not* be running.
fixes#5191
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
Remove `Offset()` from the `DagReader` interface. It's not part of the Unix API
and it wasn't used anywhere except for the tests (a helper function was added to
replace it).
License: MIT
Signed-off-by: Lucas Molas <schomatis@gmail.com>
The `Root` structure now explicitly contains a `Directory` (instead of an
`FSNode` interface), use that `Directory`'s `DAGService` instead of its own
`dserv` variable (which was used only once in `closeChild()`). The `DAGService`
in the `Root` and the `Directory` was the same (passed as an argument in the
`NewRoot` initializer function).
This leaves the `Root` structure with only a `Directory` and a `Republisher` and
allows to better rethink its role and whether if those two structures should be
grouped together (and if that group's name should be `Root`).
License: MIT
Signed-off-by: Lucas Molas <schomatis@gmail.com>
Make `Root` value explicitly a `Directory` structure instead of the `FSNode`
interface (which also allowed the `File` type). This helps to make the code
easier to reason about: the root of an MFS layout is always a directory, not a
(single) file.
Rename `GetValue()` to `GetDirectory()` to also make it more explicit, the
renamed function now returns a `Directory` so there is no need for type
assertions that were previously done on the `FSNode` interface to check that it
was actually a `Directory`.
`NewRoot()` now doesn't allow to create `Root` structures from DAG nodes that
contain UnixFS files.
License: MIT
Signed-off-by: Lucas Molas <schomatis@gmail.com>