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.
-
- (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
169 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 |
# File '../../src/modules/FileChanges.rb', line 169 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 |
- (String) ComputeFileChecksum(file)
Compute the checksum of a file
95 96 97 98 99 100 101 102 103 |
# File '../../src/modules/FileChanges.rb', line 95 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)
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File '../../src/modules/FileChanges.rb', line 136 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
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File '../../src/modules/FileChanges.rb', line 109 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 |
# 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" @data_file = "/var/lib/YaST2/file_checksums.ycp" @file_checksums = {} end |
- (Object) ReadSettings
Read the data file containing file checksums
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File '../../src/modules/FileChanges.rb', line 67 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
155 156 157 158 159 160 161 162 |
# File '../../src/modules/FileChanges.rb', line 155 def StoreFileCheckSum(file) ReadSettings() sum = ComputeFileChecksum(file) Ops.set(@file_checksums, file, sum) WriteSettings() nil end |
- (Object) WriteSettings
Write the data file containing checksums
86 87 88 89 90 |
# File '../../src/modules/FileChanges.rb', line 86 def WriteSettings SCR.Write(path(".target.ycp"), @data_file, @file_checksums) nil end |