Skip to content

Commit

Permalink
Merge 33521ae into 2e774fa
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed May 14, 2019
2 parents 2e774fa + 33521ae commit e3ded2e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 29 deletions.
7 changes: 7 additions & 0 deletions package/yast2-installation.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Fri May 10 15:07:17 CEST 2019 - schubi@suse.de

- Downloading files: Remounting CD with bind option correctly if
the CD has already been mounted (bsc#1132915).
- 4.1.46

-------------------------------------------------------------------
Fri Mar 15 10:38:35 UTC 2019 - snwint@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-installation.spec
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-installation
Version: 4.1.45
Version: 4.1.46
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
38 changes: 10 additions & 28 deletions src/lib/transfer/file_from_url.rb
Expand Up @@ -182,7 +182,7 @@ def get_file_from_url(scheme:, host:, urlpath:, localfile:,
elsif _Scheme == "file"
file = Builtins.sformat("%1/%2", Installation.sourcedir, _Path) # FIXME: I have doubts this will ever work. Too early.
if Ops.greater_than(SCR.Read(path(".target.size"), file), 0)
cpcmd = Builtins.sformat("cp %1 %2", file, _Localfile)
cpcmd = Builtins.sformat("/bin/cp %1 %2", file, _Localfile)
Builtins.y2milestone("Copy profile: %1", cpcmd)
SCR.Execute(path(".target.bash"), cpcmd)
else
Expand All @@ -194,7 +194,7 @@ def get_file_from_url(scheme:, host:, urlpath:, localfile:,
_Path
)
)
cpcmd = Builtins.sformat("cp %1 %2", _Path, _Localfile)
cpcmd = Builtins.sformat("/bin/cp %1 %2", _Path, _Localfile)
Builtins.y2milestone("Copy profile: %1", cpcmd)
SCR.Execute(path(".target.bash"), cpcmd)
end
Expand All @@ -216,36 +216,18 @@ def get_file_from_url(scheme:, host:, urlpath:, localfile:,
install_url = InstURL.installInf2Url("")
# Builtins.regexpsub can also return nil (bnc#959723)
cdrom_device = install_url ? (Builtins.regexpsub(install_url, "devices=(.*)$", "\\1") || "") : ""
if Installation.boot == "cd" && !cdrom_device.empty?
already_mounted = Ops.add(
Ops.add("grep ", cdrom_device),
" /proc/mounts ;"
)
am = Convert.to_map(
SCR.Execute(path(".target.bash_output"), already_mounted)
)

if Ops.get_integer(am, "exit", -1) == 0 &&
Ops.greater_than(
Builtins.size(Ops.get_string(am, "stdout", "")),
0
)
Builtins.y2warning(
if Installation.boot == "cd" && !cdrom_device.empty?
mtab = File.read("/proc/mounts")
m = mtab.match(/^#{cdrom_device}\s+(\S+)/)
if m
Builtins.y2milestone(
"%1 is already mounted, trying to bind mount...",
cdrom_device
)
cmd = Ops.add(
Ops.add(
Ops.add(
Ops.add("mount -v --bind `grep ", cdrom_device),
" /proc/mounts |cut -f 2 -d \\ ` "
),
mount_point
),
";"
)
am1 = Convert.to_map(
SCR.Execute(path(".target.bash_output"), cmd)
SCR.Execute(path(".target.bash_output"),
"/bin/mount -v --bind #{m[1]} #{mount_point}")
)
if Ops.get_integer(am1, "exit", -1) == 0
ok = true
Expand Down Expand Up @@ -282,7 +264,7 @@ def get_file_from_url(scheme:, host:, urlpath:, localfile:,
end
if ok
cpcmd = Builtins.sformat(
Ops.add(Ops.add("cp ", mount_point), "/%1 %2"),
Ops.add(Ops.add("/bin/cp ", mount_point), "/%1 %2"),
_Path,
_Localfile
)
Expand Down
52 changes: 52 additions & 0 deletions test/file_from_url_test.rb
Expand Up @@ -5,6 +5,8 @@
require "transfer/file_from_url"

describe Yast::Transfer::FileFromUrl do
Yast.import "Installation"

before do
stub_const("Yast::FTP", double(fake_method: nil))
stub_const("Yast::HTTP", double(Get: nil))
Expand Down Expand Up @@ -176,6 +178,56 @@ def Get(scheme, host, urlpath, localfile)
context "when scheme is 'ftp'" do
end
context "when scheme is 'file'" do
let(:scheme) { "file" }
let(:destination) { "/tmp/auto.xml" }
let(:source) { "/oss.xml" }
let(:cd_device) { "/dev/sr0" }
let(:tmp_mount) { "/tmp_dir/tmp_mount" }

before do
allow(Yast::SCR).to receive(:Execute)
.with(Yast::Path.new(".target.bash"), "/bin/cp #{tmp_mount}/#{source} #{destination}")
allow(Yast::SCR).to receive(:Execute)
.with(Yast::Path.new(".target.bash"), "/bin/cp #{source} #{destination}")
allow(Yast::WFM).to receive(:Execute)
.with(Yast::Path.new(".local.umount"), tmp_mount)
allow(Yast::Installation).to receive(:sourcedir).and_return("/mnt")
allow(Yast::Installation).to receive(:boot).and_return("cd")
allow(Yast::InstURL).to receive("installInf2Url").and_return("cd:/?devices=#{cd_device}")
expect(Yast::SCR).to receive(:Read)
.with(Yast::Path.new(".target.size"), "/mnt/#{source}").and_return(0)
expect(Yast::SCR).to receive(:Read)
.with(Yast::Path.new(".target.size"), destination).and_return(0, 10)
end

context "CD has already been mounted multiple times" do
before do
allow(File).to receive(:read).with("/proc/mounts").and_return(
"#{cd_device} /mounts/mp_0005 iso9660 ro,relatime 0 0\n"\
"#{cd_device} /mounts/mp_0006 iso9660 ro,relatime 0 0"
)
end

it "mounts with --bind option and returns true" do
expect(Yast::SCR).to receive(:Execute)
.with(Yast::Path.new(".target.bash_output"), "/bin/mount -v --bind /mounts/mp_0005 #{tmp_mount}")
.and_return("exit" => 0, "stdout" => "ok")
expect(subject.Get(scheme, "", source, destination)).to eq(true)
end
end

context "CD has not been mounted" do
before do
allow(File).to receive(:read).with("/proc/mounts").and_return("")
end

it "mounts CD and returns true" do
expect(Yast::WFM).to receive(:Execute)
.with(Yast::Path.new(".local.mount"), [cd_device, tmp_mount, Yast::Installation.mountlog])
.and_return(true)
expect(subject.Get(scheme, "", source, destination)).to eq(true)
end
end
end
context "when scheme is 'nfs'" do
end
Expand Down

0 comments on commit e3ded2e

Please sign in to comment.