Module: Yast2::FsSnapshotStore

Defined in:
library/system/src/lib/yast2/fs_snapshot_store.rb

Overview

Goal of this module is to provide easy to use api to store id of pre snapshots, so post snapshots can be then easy to make.

Class Method Summary collapse

Class Method Details

.clean(purpose) ⇒ Object

Cleans store content of given purpose



62
63
64
# File 'library/system/src/lib/yast2/fs_snapshot_store.rb', line 62

def self.clean(purpose)
  Yast::SCR.Execute(Yast::Path.new(".target.remove"), snapshot_path(purpose))
end

.load(purpose) ⇒ Object

Loads id of pre snapshot for given purpose @param purpose of snapshot like “upgrade” @raise if writing to file failed @return



48
49
50
51
52
53
54
55
56
57
58
59
# File 'library/system/src/lib/yast2/fs_snapshot_store.rb', line 48

def self.load(purpose)
  content = Yast::SCR.Read(
    Yast::Path.new(".target.string"),
    snapshot_path(purpose)
  )

  if !content || content !~ /^\d+$/
    raise "Failed to read Pre Snapshot id for #{purpose} from store. See logs."
  end

  content.to_i
end

.save(purpose, snapshot_id) ⇒ Object

Stores pre snapshot with given id and purpose @param purpose of snapshot like “upgrade” @raise if writing to file failed



34
35
36
37
38
39
40
41
42
# File 'library/system/src/lib/yast2/fs_snapshot_store.rb', line 34

def self.save(purpose, snapshot_id)
  result = Yast::SCR.Write(
    Yast::Path.new(".target.string"),
    snapshot_path(purpose),
    snapshot_id.to_s
  )

  raise "Failed to write Pre Snapshot id for #{purpose} to store. See logs." unless result
end