Skip to content

Commit

Permalink
Fix some issues pointed by Rubocop
Browse files Browse the repository at this point in the history
* Rubocop if finally disabled for lib/transfer/file_from_url.
  • Loading branch information
imobachgs committed Mar 14, 2016
1 parent 4cdca82 commit 4e5e6dd
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 60 deletions.
100 changes: 50 additions & 50 deletions src/lib/transfer/file_from_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

require "yast"


# rubocop:disable all
module Yast::Transfer
module FileFromUrl
include Yast
Expand Down Expand Up @@ -87,7 +87,7 @@ def dirname(filePath)
#
# @return [Boolean] true on success
def get_file_from_url(scheme:, host:, urlpath:, localfile:,
urltok:, destdir:)
urltok:, destdir:)
# adapt sane API to legacy implementation
_Scheme = scheme
_Host = host
Expand Down Expand Up @@ -128,21 +128,21 @@ def get_file_from_url(scheme:, host:, urlpath:, localfile:,
if _Scheme == "http" || _Scheme == "https"
HTTP.easySSL(true)
if Ops.greater_than(
SCR.Read(
path(".target.size"),
"/etc/ssl/clientcerts/client-cert.pem"
),
0
)
SCR.Read(
path(".target.size"),
"/etc/ssl/clientcerts/client-cert.pem"
),
0
)
HTTP.clientCertSSL("/etc/ssl/clientcerts/client-cert.pem")
end
if Ops.greater_than(
SCR.Read(
path(".target.size"),
"/etc/ssl/clientcerts/client-key.pem"
),
0
)
SCR.Read(
path(".target.size"),
"/etc/ssl/clientcerts/client-key.pem"
),
0
)
HTTP.clientKeySSL("/etc/ssl/clientcerts/client-key.pem")
end
res = HTTP.Get(full_url, _Localfile)
Expand Down Expand Up @@ -260,11 +260,11 @@ def get_file_from_url(scheme:, host:, urlpath:, localfile:,
try_again = 10
while Ops.greater_than(try_again, 0)
if !Convert.to_boolean(
WFM.Execute(
path(".local.mount"),
[cdrom_device, mount_point, Installation.mountlog]
)
WFM.Execute(
path(".local.mount"),
[cdrom_device, mount_point, Installation.mountlog]
)
)
# autoyast tried to mount the CD but had no success.
@GET_error = Ops.add(
@GET_error,
Expand Down Expand Up @@ -308,12 +308,12 @@ def get_file_from_url(scheme:, host:, urlpath:, localfile:,
end
elsif _Scheme == "nfs" # NFS
if !Convert.to_boolean(
SCR.Execute(
path(".target.mount"),
[Ops.add(Ops.add(_Host, ":"), dirname(_Path)), mount_point],
"-o noatime,nolock"
)
) &&
SCR.Execute(
path(".target.mount"),
[Ops.add(Ops.add(_Host, ":"), dirname(_Path)), mount_point],
"-o noatime,nolock"
)
) &&
!Convert.to_boolean(
SCR.Execute(
path(".target.mount"),
Expand Down Expand Up @@ -359,12 +359,12 @@ def get_file_from_url(scheme:, host:, urlpath:, localfile:,
SCR.Execute(path(".target.umount"), mount_point)
elsif _Scheme == "cifs" # CIFS
if !Convert.to_boolean(
SCR.Execute(
path(".target.mount"),
[Ops.add(Ops.add("//", _Host), dirname(_Path)), mount_point],
"-t cifs -o guest,ro,noatime"
)
SCR.Execute(
path(".target.mount"),
[Ops.add(Ops.add("//", _Host), dirname(_Path)), mount_point],
"-t cifs -o guest,ro,noatime"
)
)
Builtins.y2warning("Mount failed")
# autoyast tried to mount a NFS directory which failed
@GET_error = Builtins.sformat(
Expand Down Expand Up @@ -409,15 +409,15 @@ def get_file_from_url(scheme:, host:, urlpath:, localfile:,
)

if WFM.Execute(
path(".local.bash"),
path(".local.bash"),
Ops.add(
Ops.add(
Ops.add(
Ops.add(Ops.add(Ops.add("/bin/cp ", mount_point), "/"), _Path),
" "
),
_Localfile
)
) != 0
Ops.add(Ops.add(Ops.add("/bin/cp ", mount_point), "/"), _Path),
" "
),
_Localfile
)
) != 0
Builtins.y2error(
"file %1 can't be retrieved",
Ops.add(Ops.add(mount_point, "/"), _Path)
Expand All @@ -435,13 +435,13 @@ def get_file_from_url(scheme:, host:, urlpath:, localfile:,
disks = _Scheme == "device" ?
Convert.convert(
SCR.Read(path(".probe.disk")),
:from => "any",
:to => "list <map>"
from: "any",
to: "list <map>"
) :
Convert.convert(
SCR.Read(path(".probe.usb")),
:from => "any",
:to => "list <map>"
from: "any",
to: "list <map>"
)
Builtins.foreach(disks) do |m|
if _Scheme == "usb" && Ops.get_string(m, "bus", "USB") != "SCSI"
Expand Down Expand Up @@ -522,18 +522,18 @@ def get_file_from_url(scheme:, host:, urlpath:, localfile:,
next
end
if WFM.Execute(
path(".local.bash"),
path(".local.bash"),
Ops.add(
Ops.add(
Ops.add(
Ops.add(
Ops.add(Ops.add("/bin/cp ", mount_point), "/"),
_Path
),
" "
Ops.add(Ops.add("/bin/cp ", mount_point), "/"),
_Path
),
_Localfile
)
) != 0
" "
),
_Localfile
)
) != 0
# autoyast tried to copy a file but that file can't be found
@GET_error = Builtins.sformat(
_("File %1 cannot be found"),
Expand Down
21 changes: 11 additions & 10 deletions test/file_from_url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def Get(scheme, host, urlpath, localfile)
end

# avoid BuildRequiring a package that we stub entirely anyway
# rubocop:disable ConstantName
Yast::Storage = nil
Yast::StorageDevices = nil
before do
Expand Down Expand Up @@ -45,7 +46,7 @@ def Get(scheme, host, urlpath, localfile)

it "returns false for unknown scheme" do
expect(subject.Get("money_transfer_protocol",
"bank", "account", "pocket")).to eq(false)
"bank", "account", "pocket")).to eq(false)
end

context "when scheme is 'device'" do
Expand Down Expand Up @@ -113,32 +114,32 @@ def Get(scheme, host, urlpath, localfile)
mount_succeeded = {
"/dev/sda" => false,
"/dev/sda4" => true,
"/dev/sda5" => true,
"/dev/sda5" => true
}

mount_succeeded.each do |device, result|
expect(Yast::SCR).to receive(:Execute)
.with(path(".target.mount"),
[device, mount_points[device].last],
"-o noatime")
[device, mount_points[device].last],
"-o noatime")
.and_return(result)
end

expect(Yast::WFM).to receive(:Execute)
.with(path(".local.bash"),
"/bin/cp /mnt_sda1/mypath /localfile")
"/bin/cp /mnt_sda1/mypath /localfile")
.exactly(3).times
.and_return(1, 1, 0) # sda1 fails, sda4 fails, sda5 succeeds

expect(Yast::WFM).to receive(:Execute)
.with(path(".local.bash"),
# "/bin/cp /destdir/tmp_dir/tmp_mount/mypath /localfile")
# Bug: it is wrong if destdir is used
"/bin/cp /tmp_dir/tmp_mount/mypath /localfile")
# "/bin/cp /destdir/tmp_dir/tmp_mount/mypath /localfile")
# Bug: it is wrong if destdir is used
"/bin/cp /tmp_dir/tmp_mount/mypath /localfile")
.exactly(0).times
# .and_return(1, 0) # sda4 fails, sda5 succeeds
# .and_return(1, 0) # sda4 fails, sda5 succeeds

# Bug: local is wrong. nfs and cifs correctly use .target.umount
# Bug: local is wrong. nfs and cifs correctly use .target.umount
expect(Yast::WFM).to receive(:Execute)
.with(path(".local.umount"), "/mnt_sda1")
.exactly(2).times
Expand Down

0 comments on commit 4e5e6dd

Please sign in to comment.