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.

Defined Under Namespace

Classes: IOError

Class Method Summary collapse

Class Method Details

.clean(purpose) ⇒ Object

Cleans store content of given purpose



66
67
68
# File 'library/system/src/lib/yast2/fs_snapshot_store.rb', line 66

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

Raises:



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

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

  raise IOError, "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 purpose of snapshot like "upgrade" @raise if writing to file failed

Raises:



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

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 IOError, "Failed to write Pre Snapshot id for #{purpose} to store. See logs." unless result
end