Skip to content
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

Merged
merged 1 commit into from
Aug 14, 2018

Conversation

hsanjuan
Copy link
Contributor

@hsanjuan hsanjuan commented Aug 8, 2018

Code was just weird. I think it looks better now.

License: MIT
Signed-off-by: Hector Sanjuan hector@protocol.ai

@hsanjuan hsanjuan self-assigned this Aug 8, 2018
@hsanjuan hsanjuan requested a review from Kubuxu as a code owner August 8, 2018 22:53
@ghost ghost added the status/in-progress In progress label Aug 8, 2018
@hsanjuan hsanjuan added topic/core Topic core exp/novice Someone with a little familiarity can pick up labels Aug 8, 2018
Copy link
Contributor

@schomatis schomatis left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@hsanjuan
Copy link
Contributor Author

@schomatis actually the weirdness was there before your changes


dir := mr.GetDirectory()

root, err = dir.Child(name)
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor

@schomatis schomatis left a 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 <hector@protocol.ai>
@hsanjuan
Copy link
Contributor Author

@Stebalien this should be RFM

@Stebalien Stebalien merged commit 56ba44e into master Aug 14, 2018
@ghost ghost removed the status/in-progress In progress label Aug 14, 2018
@Stebalien Stebalien deleted the fix/coreunix/add/improvs branch August 14, 2018 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exp/novice Someone with a little familiarity can pick up topic/core Topic core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants