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


64
65
66
# File 'library/system/src/lib/yast2/fs_snapshot_store.rb', line 64

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[String] purpose of snapshot like "upgrade" @raise[RuntimeError] if writing to file failed @return[Fixnum]


52
53
54
55
56
57
58
59
60
61
# File 'library/system/src/lib/yast2/fs_snapshot_store.rb', line 52

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

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

  content.to_i
end

.save(purpose, snapshot_id) ⇒ Object

Stores pre snapshot with given id and purpose @param[String] purpose of snapshot like "upgrade" @raise[RuntimeError] if writing to file failed


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'library/system/src/lib/yast2/fs_snapshot_store.rb', line 32

def self.save(purpose, snapshot_id)
  # Ensure the directory is there (bsc#1159562)
  Yast::SCR.Execute(
    Yast::Path.new(".target.bash"),
    "/bin/mkdir -p #{snapshot_dir_path}"
  )

  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