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 for bsc#1084213 and bsc#1084261 #567

Merged
merged 4 commits into from
Mar 9, 2018
Merged

Conversation

ancorgs
Copy link
Contributor

@ancorgs ancorgs commented Mar 8, 2018

@@ -418,6 +418,8 @@ def remove_shadowed_subvols(planned_devices)
subvols_added =
device.respond_to?(:mount_point) && device.mount_point == "/" && @default_subvolumes_used

# Use #dup to avoid bsc#1084213
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would dup the list just when it is assigned from the settings:
https://github.com/ancorgs/yast-storage-ng/blob/b59dafb1b2e7c1d58d35e914907ea7fe7b0ef7dc/src/lib/y2storage/proposal/autoinst_devices_planner.rb#L233

This would avoid possible similar errors in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are at least three assignations of that. So duping all of them looks wrong.

At most, I would define a setter. Like

module Planned::CanBeFormatted
  def subvolumes=(value)
    @subvolumes = value.dup
  end
end

That was indeed my first option, but I somehow though it would have been more surprising. Less rubyist, sort to say.

I don't care much, either solution (the one on this PR or redefining the setter) are acceptable to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So:

  • Solution 1: the one currently on this PR. It's correct but @joseivanlopez pointed that we can make the same error in the future in another part.
  • Solution 2: redefining the setter. It's also correct and doesn't have the mentioned problem, although it has slightly surprising implications (from the OOP rubyist POV).
  • Solution 3: a dup on each assignation as suggested by @joseivanlopez. I don't like it. Very error prone.

I discussed offline with @imobachgs and he would go for 2. Since 2 is also pretty aligned with @joseivanlopez's concerns, I will switch from 1 to 2.

@@ -105,10 +105,13 @@ def remove_shadowed_subvolumes(planned_devices)
planned_devices.each do |device|
next unless device.respond_to?(:subvolumes)

# Use #dup to avoid bsc#1084213
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ancorgs
Copy link
Contributor Author

ancorgs commented Mar 8, 2018

Verified manually that this fixes the reported bug.

@ancorgs ancorgs changed the title Unit test showcasing bsc#1084213 and bsc#1084261 Fix for bsc#1084213 and bsc#1084261 Mar 9, 2018
@ancorgs
Copy link
Contributor Author

ancorgs commented Mar 9, 2018

New solution pushed with -f. I will re-test manually now

@ancorgs
Copy link
Contributor Author

ancorgs commented Mar 9, 2018

New solution also tested manually

Copy link
Contributor

@joseivanlopez joseivanlopez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only something to discuss (think about)

# # most common ruby behavior.
# my_list.first.path = "changed" # This change affects planned.subvolumes
# # because the object is also in that collection (not a deep copy).
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a deep copy? Having a mixed behavior could be confusing. I would expect that if I obtain a new collection, that new collection is totally independent to the original one. Moreover, we should avoid any unwanted change in the original settings when we are configuring the planned devices.

Copy link
Contributor Author

@ancorgs ancorgs Mar 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, a deep copy would be even more unexpected. When I pass a list of objects I'm indeed intent to pass those objects, not a copy of them. Two objects that are not the same object but represent the same thing are a constant source of bugs (they don't work with include?, ==, etc.)

@ancorgs ancorgs merged commit 753627b into yast:master Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants