• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-packager / 15441808734

04 Jun 2025 12:05PM UTC coverage: 37.221% (-0.2%) from 37.407%
15441808734

push

github

web-flow
Merge pull request #659 from yast/huha-no-baseurl-crash

Prevent a crash if a repo doesn't have a baseurl

1 of 1 new or added line in 1 file covered. (100.0%)

123 existing lines in 11 files now uncovered.

4366 of 11730 relevant lines covered (37.22%)

23.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.09
/src/modules/PackageInstallation.rb
1
require "yast"
1✔
2
require "yast2/system_time"
1✔
3

4
# Yast namespace
5
module Yast
1✔
6
  # Perfoms package installation
7
  class PackageInstallationClass < Module
1✔
8
    def main
1✔
9
      Yast.import "Pkg"
1✔
10
      Yast.import "UI"
1✔
11
      textdomain "packager"
1✔
12

13
      Yast.import "Mode"
1✔
14
      Yast.import "Installation"
1✔
15
      Yast.import "Directory"
1✔
16
      Yast.import "Packages"
1✔
17
      Yast.import "PackageSlideShow"
1✔
18
      Yast.import "PackagesUI"
1✔
19

20
      Yast.import "Label"
1✔
21

22
      @download_in_advance = nil
1✔
23
    end
24

25
    def DownloadInAdvance
1✔
26
      @download_in_advance
×
27
    end
28

29
    def SetDownloadInAdvance(enable)
1✔
30
      @download_in_advance = enable
×
31

UNCOV
32
      nil
×
33
    end
34

35
    #  Show a dialog with either the list of failed packages (string failed_packages) or
36
    #  the complete log (string full_log).
37
    def ShowFailedPackages(failed_packages, full_log)
1✔
38
      rbuttons = RadioButtonGroup(
×
39
        VBox(
40
          Left(
41
            RadioButton(
42
              Id(:failed_packages),
43
              Opt(:notify),
44
              # button label
45
              _("&Show Failed Packages List"),
46
              true
47
            )
48
          ),
49
          Left(
50
            RadioButton(
51
              Id(:full_log),
52
              Opt(:notify),
53
              # button label
54
              _("&Show Full Log"),
55
              false
56
            )
57
          )
58
        )
59
      )
60

61
      UI.OpenDialog(
×
62
        Opt(:decorated),
63
        VBox(
64
          HSpacing(40),
65
          # dialog headline
66
          Left(Heading(_("Installation of some Packages Failed"))),
67
          rbuttons,
68
          RichText(Id(:text), Opt(:plainText), full_log),
69
          PushButton(Id(:ok), Opt(:default, :key_F10), Label.OKButton)
70
        )
71
      )
72

73
      loop do
×
74
        ret = Convert.to_symbol(UI.UserInput)
×
75

76
        if [:failed_packages, :full_log].include?(ret)
×
77
          UI.ChangeWidget(
×
78
            Id(:text),
79
            :Value,
80
            UI.QueryWidget(Id(:failed_packages), :Value) ? failed_packages : full_log
×
81
          )
82
          next
×
83
        end
84

85
        break if ret == :ok
×
86
      end
87

88
      UI.CloseDialog
×
89

UNCOV
90
      nil
×
91
    end
92

93
    # commitPackages marked for deletion or installation
94
    # @return [Array] containing [ int successful, list failed, list remaining,
95
    #   list srcremaining, list update_messages ]
96
    def Commit(config)
1✔
97
      config = deep_copy(config)
7✔
98
      # install packages from this media
99

100
      PackageSlideShow.InitPkgData(false)
7✔
101

102
      start_time = Yast2::SystemTime.uptime
7✔
103

104
      # returns [ int successful, list failed, list remaining, list srcremaining ]
105
      Builtins.y2milestone("Calling Pkg::Commit (%1)", config)
7✔
106
      commit_result = Pkg.Commit(config)
7✔
107

108
      if commit_result.nil?
7✔
109
        Builtins.y2error("Commit failed: %1", Pkg.LastError)
1✔
110
        return []
1✔
111
      end
112

113
      installation_time = Yast2::SystemTime.uptime - start_time
6✔
114
      Builtins.y2milestone(
6✔
115
        "Installation took %1 seconds, commit result: %2",
116
        installation_time,
117
        commit_result
118
      )
119

120
      # see if installation of some packages failed
121
      errpacks = Ops.get_list(commit_result, 1, [])
6✔
122
      if Ops.greater_than(Builtins.size(errpacks), 0)
6✔
123
        full_log = Ops.get_string(
×
124
          PackagesUI.GetPackageSummary,
125
          "install_log",
126
          ""
127
        )
128
        ShowFailedPackages(Builtins.mergestring(errpacks, "\n"), full_log)
×
129

130
        old_failed_packs = []
×
131
        if Ops.greater_than(
×
132
          Convert.to_integer(
133
            SCR.Read(path(".target.size"), "/var/lib/YaST2/failed_packages")
134
          ),
135
          0
136
        )
137
          old_failed_packs = Convert.convert(
×
138
            SCR.Read(path(".target.ycp"), "/var/lib/YaST2/failed_packages"),
139
            from: "any",
140
            to:   "list <string>"
141
          )
142
        end
143
        SCR.Write(
×
144
          path(".target.ycp"),
145
          "/var/lib/YaST2/failed_packages",
146
          Builtins.merge(old_failed_packs, errpacks)
147
        )
148
      end
149

150
      PackagesUI.show_update_messages(commit_result) unless Mode.installation || Mode.autoinst
6✔
151

152
      if Mode.normal
6✔
153
        # collect and set installation summary data
154
        summary = PackageSlideShow.GetPackageSummary
5✔
155

156
        Ops.set(summary, "time_seconds", installation_time)
5✔
157
        Ops.set(summary, "success", Builtins.size(errpacks).zero?)
5✔
158
        Ops.set(summary, "remaining", package_names(commit_result[2] || []))
5✔
159
        Ops.set(summary, "install_log", "")
5✔
160

161
        if Ops.greater_than(Builtins.size(errpacks), 0)
5✔
162
          Ops.set(summary, "error", Pkg.LastError)
×
163
          Ops.set(summary, "failed", errpacks)
×
164
        end
165

166
        if commit_result == [-1]
5✔
167
          Ops.set(summary, "error", _("Installation aborted by user."))
×
168
          Ops.set(summary, "success", false)
×
169
        end
170

171
        PackagesUI.SetPackageSummary(summary)
5✔
172
      end
173

174
      deep_copy(commit_result)
6✔
175
    end
176

177
    # commitPackages marked for deletion or installation
178
    # @return [Array] with content [ int successful, list failed, list remaining,
179
    #   list srcremaining, list update_messages ]
180
    def CommitPackages(media_number, packages_installed)
1✔
181
      # this is a backward compatible wrapper for Commit()
182
      Builtins.y2milestone(
×
183
        "CommitPackages (%1,%2): Pkg::TargetGetDU() %3",
184
        media_number,
185
        packages_installed,
186
        Pkg.TargetGetDU
187
      )
188
      Commit("medium_nr" => media_number)
×
189
    end
190

191
    publish function: :DownloadInAdvance, type: "boolean ()"
1✔
192
    publish function: :SetDownloadInAdvance, type: "void (boolean)"
1✔
193
    publish function: :Commit, type: "list (map <string, any>)"
1✔
194
    publish function: :CommitPackages, type: "list (integer, integer)"
1✔
195

196
  private
1✔
197

198
    # Get a human readable list of installed packages
199
    # @param [Array<Hash>] packages list of package data
200
    # @return [Array<String>] list of package names
201
    def package_names(packages)
1✔
202
      packages.map { |p| p["name"] }
5✔
203
    end
204
  end
205

206
  PackageInstallation = PackageInstallationClass.new
1✔
207
  PackageInstallation.main
1✔
208
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc