Class: Yast::FileChangesClass
- Inherits:
-
Module
- Object
- Module
- Yast::FileChangesClass
- Defined in:
- ../../src/modules/FileChanges.rb
Instance Method Summary (collapse)
-
- (Boolean) CheckFiles(files)
Check files if any of them were changed Issue a question whether to continue if some were chaned.
-
- (Boolean) CheckNewCreatedFiles(files)
Check if any of the possibly new created files is really new Issue a question whether to continue if such file was manually created.
-
- (String) ComputeFileChecksum(file)
Compute the checksum of a file.
-
- (Boolean) FileChanged(file)
Check if a file was modified externally (without YaST).
-
- (Boolean) FileChangedFromPackage(file)
Check if file was modified compared to the one distributed with the RPM package.
- - (Object) main
-
- (Object) ReadSettings
Read the data file containing file checksums.
-
- (Object) StoreFileCheckSum(file)
Store checksum of a file to the store.
-
- (Object) WriteSettings
Write the data file containing checksums.
Instance Method Details
- (Boolean) CheckFiles(files)
Check files if any of them were changed Issue a question whether to continue if some were chaned
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File '../../src/modules/FileChanges.rb', line 170 def CheckFiles(files) files = deep_copy(files) files = Builtins.filter(files) { |f| FileChanged(f) } if Ops.greater_than(Builtins.size(files), 0) # Continue/Cancel question, %1 is a file name msg = _( "File %1 has been changed manually.\nYaST might lose some of the changes.\n" ) if Ops.greater_than(Builtins.size(files), 1) # Continue/Cancel question, %1 is a coma separated list of file names msg = _( "Files %1 have been changed manually.\nYaST might lose some of the changes" ) end msg = Builtins.sformat(msg, Builtins.mergestring(files, ", ")) popup_file = "/filechecks_non_verbose" if {} == SCR.Read( path(".target.stat"), Ops.add(Directory.vardir, popup_file) ) content = VBox( Label(msg), Left(CheckBox(Id(:disable), _("Do not show this message anymore"))), ButtonBox( PushButton(Id(:ok), Opt(:okButton), Label.ContinueButton), PushButton(Id(:cancel), Opt(:cancelButton), Label.CancelButton) ) ) UI.OpenDialog(content) UI.SetFocus(:ok) ret = UI.UserInput Builtins.y2milestone("ret = %1", ret) if ret == :ok && Convert.to_boolean(UI.QueryWidget(:disable, :Value)) Builtins.y2milestone("Disabled checksum popups") SCR.Write( path(".target.string"), Ops.add(Directory.vardir, popup_file), "" ) end UI.CloseDialog if ret == :ok return true else return false end else # return Popup::ContinueCancel (msg); return true end end true end |
- (Boolean) CheckNewCreatedFiles(files)
Check if any of the possibly new created files is really new Issue a question whether to continue if such file was manually created
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File '../../src/modules/FileChanges.rb', line 231 def CheckNewCreatedFiles(files) new_files = files - @file_checksums.keys if new_files.size > 0 # Continue/Cancel question, %s is a file name msg = _("File %s has been created manually.\nYaST might lose this file.") if new_files.size > 1 # Continue/Cancel question, %s is a comma separated list of file names msg = _( "Files %s have been created manually.\nYaST might lose these files." ) end msg = msg % new_files.join(", ") popup_file = "/filechecks_non_verbose" popup_file_path = File.join(Directory.vardir, popup_file) if !FileUtils.Exists(popup_file_path) content = VBox( Label(msg), Left(CheckBox(Id(:disable), Message.DoNotShowMessageAgain())), ButtonBox( PushButton(Id(:ok), Opt(:okButton), Label.ContinueButton()), PushButton(Id(:cancel), Opt(:cancelButton), Label.CancelButton()) ) ) UI.OpenDialog(content) UI.SetFocus(:ok) ret = UI.UserInput Builtins.y2milestone("ret = %1", ret) if ret == :ok && UI.QueryWidget(:disable, :Value) Builtins.y2milestone("Disabled checksum popups") SCR.Write( path(".target.string"), popup_file_path, "" ) end UI.CloseDialog return ret == :ok else return true end end true end |
- (String) ComputeFileChecksum(file)
Compute the checksum of a file
96 97 98 99 100 101 102 103 104 |
# File '../../src/modules/FileChanges.rb', line 96 def ComputeFileChecksum(file) # See also FileUtils::MD5sum() cmd = Builtins.sformat("/usr/bin/md5sum %1", file) out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) # note: it also contains file name, but since it is only to be compared # it does not matter sum = Ops.get_string(out, "stdout", "") sum end |
- (Boolean) FileChanged(file)
Check if a file was modified externally (without YaST)
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File '../../src/modules/FileChanges.rb', line 137 def FileChanged(file) # when generating AutoYaST configuration, they are not written back return false if Mode.config ReadSettings() ret = false if Builtins.haskey(@file_checksums, file) Builtins.y2milestone("Comparing file %1 to stored checksum", file) sum = ComputeFileChecksum(file) ret = !(sum == Ops.get(@file_checksums, file, "")) else Builtins.y2milestone("Comparing file %1 to RPM database", file) ret = FileChangedFromPackage(file) end Builtins.y2milestone("File differs: %1", ret) ret end |
- (Boolean) FileChangedFromPackage(file)
Check if file was modified compared to the one distributed with the RPM package
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File '../../src/modules/FileChanges.rb', line 110 def FileChangedFromPackage(file) # queryformat: no trailing newline! cmd = Builtins.sformat( "/bin/rpm -qf %1 --qf %%{NAME}-%%{VERSION}-%%{RELEASE}", file ) out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) package = Ops.get_string(out, "stdout", "") Builtins.y2milestone("Package owning %1: %2", file, package) return false if package == "" || Ops.get_integer(out, "exit", -1) != 0 cmd = Builtins.sformat("rpm -V %1 |grep ' %2$'", package, file) out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) changes = Ops.get_string(out, "stdout", "") Builtins.y2milestone("File possibly changed: %1", changes) lines = Builtins.splitstring(changes, "\n") changed = false Builtins.foreach(lines) do |line| changed = true if Builtins.regexpmatch(line, "^S") changed = true if Builtins.regexpmatch(line, "^..5") changed = true if Builtins.regexpmatch(line, "^.......T") end changed end |
- (Object) main
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File '../../src/modules/FileChanges.rb', line 51 def main Yast.import "UI" textdomain "base" Yast.import "Mode" Yast.import "Popup" Yast.import "Directory" Yast.import "Label" Yast.import "FileUtils" @data_file = "/var/lib/YaST2/file_checksums.ycp" @file_checksums = {} end |
- (Object) ReadSettings
Read the data file containing file checksums
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File '../../src/modules/FileChanges.rb', line 68 def ReadSettings if Ops.less_or_equal( Convert.to_integer(SCR.Read(path(".target.size"), @data_file)), 0 ) @file_checksums = {} return end @file_checksums = Convert.convert( SCR.Read(path(".target.ycp"), @data_file), from: "any", to: "map <string, string>" ) @file_checksums = {} if @file_checksums.nil? nil end |
- (Object) StoreFileCheckSum(file)
Store checksum of a file to the store
156 157 158 159 160 161 162 163 |
# File '../../src/modules/FileChanges.rb', line 156 def StoreFileCheckSum(file) ReadSettings() sum = ComputeFileChecksum(file) Ops.set(@file_checksums, file, sum) WriteSettings() nil end |
- (Object) WriteSettings
Write the data file containing checksums
87 88 89 90 91 |
# File '../../src/modules/FileChanges.rb', line 87 def WriteSettings SCR.Write(path(".target.ycp"), @data_file, @file_checksums) nil end |