Skip to content

Commit

Permalink
Use default_btrfs_subvolume to find out the prefix on new filesystems
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jun 11, 2018
1 parent 6c9462b commit e3a8967
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/y2storage/filesystems/btrfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,12 @@ def restore_unshadowed_subvolumes(devicegraph)
# it lives under the #top_level_btrfs_subvolume. Otherwise, an empty
# string will be taken as the default subvolume name.
#
# If the filesystem does not exists yet, trust the default_btrfs_subvolume
# path as the default one.
#
# @return [String] Default subvolume name
def subvolumes_prefix
return default_btrfs_subvolume.path unless exists_in_raw_probed?
children = top_level_btrfs_subvolume.children.reject { |s| snapper_path?(s.path) }
children.size == 1 ? children.first.path : ""
end
Expand Down
21 changes: 21 additions & 0 deletions test/y2storage/filesystems/btrfs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,12 @@
end

describe "#subvolumes_prefix" do
let(:exists?) { true }

before do
allow(filesystem).to receive(:exists_in_raw_probed?).and_return(exists?)
end

context "when there are no subvolumes" do
let(:dev_name) { "/dev/sda2" }

Expand Down Expand Up @@ -813,6 +819,21 @@
end
end
end

context "when the filesystem does not exist yet" do
let(:exists?) { false }
let(:default_subvolume) do
instance_double(Y2Storage::BtrfsSubvolume, path: "@@")
end

before do
allow(filesystem).to receive(:default_btrfs_subvolume).and_return(default_subvolume)
end

it "returns the default subvolume path" do
expect(filesystem.subvolumes_prefix).to eq("@@")
end
end
end

context "when there are several subvolumes at first level" do
Expand Down

0 comments on commit e3a8967

Please sign in to comment.