-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mfs: make Root
value a Directory
#5170
mfs: make Root
value a Directory
#5170
Conversation
Root
value a Directory
Root
value a Directory
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>
Root
value a Directory
Root
value a Directory
Take advantage of the (now accessible) directory in root and try to remove the |
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>
Done. Ready for review. |
@@ -172,12 +171,11 @@ func Mkdir(r *Root, pth string, opts MkdirOpts) error { | |||
return nil | |||
} | |||
|
|||
// Lookup extracts the root directory and performs a lookup under it. | |||
// TODO: Now that the root is always a directory, can this function | |||
// be collapsed with `DirLookup`? Or at least be made a method of `Root`? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is used in many places within the code. I would be okay with making this a method of Root but would not collapse it with DirLookup
and DirLookup
will work on any directory and not just the root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is a step in the right direction (although I think we may not want a Root
at all but we can discuss that in the relevant comment).
@@ -118,14 +118,7 @@ func loadRoot(ctx context.Context, rt *keyRoot, ipfs *core.IpfsNode, name string | |||
|
|||
rt.root = root | |||
|
|||
switch val := root.GetValue().(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I need to get better about submitting comments instead of editing them till my browser crashes and they disappear...
This is the one real reason to allow the root to be something other than a directory. However, really, the "root" is just a way to tie a file/directory in an MFS tree to a publisher. I'd rather just:
- Hold a directory directly as you suggested here MFS Root vs MFS File/Directory #5066 (comment).
- Provide some way to "watch" files/directories.
Currently, we have the childCloser
but I wonder if we want a more general system. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I need to get better about submitting comments instead of editing them till my browser crashes and they disappear...
I'm glad I'm not the only one, I'm seriously considering submitting a feature request to GitHub that would allow me to explicitly save my drafts..
Thoughts?
I was considering adding that logic to the directory implementation of childCloser
, if the directory has a parent call the parent's closeChild
(current behavior), if not (you are the root) call the republisher and tell it things have changed. That would require every directory to be aware of the republisher, either with a pointer to it or some other way (which is not nice). Anyway, I need to keep studying how the republisher works and see if I can come up with something better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of a more general purpose notification boadcast system where users could register and unregister any number of notifiees (where the parent directory would register itself as a notifiee).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate a bit more on that? I thought the directory was the notifier (I may be misunderstanding the word notifiee, that's the one that receives the notification, right?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated:
You can save a code comment with a "Start Review", comments will be visible only to you until you send the review.
As discussed in #5066 (comment) and #5066 (comment) (different consecutive comments).