-
-
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
Fix some weird code in core/coreunix/add.go #5354
Conversation
3e06c90
to
4c44ef8
Compare
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.
The mfs.Root
was changed to be represented only as a directory (#5170), but I may have left some bits of code unchanged behind that may be causing the weirdness.
@@ -201,7 +201,8 @@ func (adder *Adder) Finalize() (ipld.Node, error) { | |||
return nil, err | |||
} | |||
var root mfs.FSNode | |||
root = mr.GetDirectory() | |||
rootdir := mr.GetDirectory() | |||
root = rootdir |
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.
Let's leave only one of these definitions, and we can drop the mfs.FSNode
definition (it will only be an mfs.Directory
), something like:
root := mr.GetDirectory()
or rootDir
if you want to emphasize that we're dealing with a directory here.
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.
@schomatis the only way to drop rootdir is to perform type assertions on an the FSNode root. I think unchecked type assertions are places for potential future bugs. Otherwise I have to check the assertions, which is way worse than having a variable with the right type from the beginning.
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.
root
cannot stay as *mfs.Directory
type because it gets re-assigned an FSNode which may not be a directory.
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.
You need to check that the child of the root is a directory, otherwise more potentially harder-to-find bugs could follow if you allow the root to be an mfs.File
.
Otherwise I have to check the assertions, which is way worse than having a variable with the right type from the beginning.
I'm failing to see the problem, you could have both, making root here explicitly as a directory and check that the child of this directory is also a directory in the posterior assignment.
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.
The child of the root does not need to be a directory. It's ok if it's an FSNode. The code is fine. I think this discussion is just about personal preferences.
@schomatis actually the weirdness was there before your changes |
4c44ef8
to
3443fe6
Compare
|
||
dir := mr.GetDirectory() | ||
|
||
root, err = dir.Child(name) |
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.
We should assert for a directory type here then.
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.
No, it does not need to be a directory
@@ -201,7 +201,8 @@ func (adder *Adder) Finalize() (ipld.Node, error) { | |||
return nil, err | |||
} | |||
var root mfs.FSNode | |||
root = mr.GetDirectory() | |||
rootdir := mr.GetDirectory() | |||
root = rootdir |
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.
You need to check that the child of the root is a directory, otherwise more potentially harder-to-find bugs could follow if you allow the root to be an mfs.File
.
Otherwise I have to check the assertions, which is way worse than having a variable with the right type from the beginning.
I'm failing to see the problem, you could have both, making root here explicitly as a directory and check that the child of this directory is also a directory in the posterior assignment.
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.
You're right, it has to remain as FSNode
, sorry for the confusion @hsanjuan.
Code was just weird. I think it looks better now. License: MIT Signed-off-by: Hector Sanjuan <[email protected]>
3e3a694
to
de72087
Compare
@Stebalien this should be RFM |
Code was just weird. I think it looks better now.
License: MIT
Signed-off-by: Hector Sanjuan [email protected]