Class: SafeDb::Obliterate

Inherits:
Controller show all
Defined in:
lib/controller/db/obliterate.rb

Overview

Obliterate the entire safe database by removing a number of folders. This is a drastic action especially as it will terminate all safe sessions on the machine no matter which shell is being used.

This action is recoverable in two ways. The first is a “safe pull” if using a remote repository like git. The second is manual restoration of the obliterated folder which is saved in the safedb-backup-crypts folder.

Instance Method Summary collapse

Methods inherited from Controller

#check_post_conditions, #check_pre_conditions, #flow, #initialize, #open_remote_backend_location, #post_validation, #pre_validation, #read_verse, #set_verse, #update_verse

Constructor Details

This class inherits a constructor from SafeDb::Controller

Instance Method Details

#executeObject

Print message and return if the master crypts directory does not exist. Otherwise make a backup of the folder then obliterate

  • the master crypts folder

  • the branch crypts folder

  • the branch keys folder



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/controller/db/obliterate.rb', line 19

def execute()

    unless ( File.exist?( Indices::MASTER_CRYPTS_FOLDER_PATH ) && File.directory?( Indices::MASTER_CRYPTS_FOLDER_PATH ) )

        puts ""
        puts "  Could not find directory"
        puts "  #{Indices::MASTER_CRYPTS_FOLDER_PATH}"
        puts "  #{Indices::NOTHING_TO_OBLITERATE}"
        puts ""
        return

    end

    backup_folder_name = TimeStamp.yyjjj_hhmm_sst() + "-" + Indices::MASTER_CRYPTS_FOLDER_NAME
    backup_folder_path = File.join( Indices::BACKUP_CRYPTS_FOLDER_PATH, backup_folder_name )
    FileUtils.mkdir_p( backup_folder_path )
    FileUtils.cp_r( "#{Indices::MASTER_CRYPTS_FOLDER_PATH}/.", backup_folder_path )

    FileUtils.remove_dir( Indices::MASTER_CRYPTS_FOLDER_PATH ) if  ( File.exist?( Indices::MASTER_CRYPTS_FOLDER_PATH ) && File.directory?( Indices::MASTER_CRYPTS_FOLDER_PATH ) )
    FileUtils.remove_dir( Indices::BRANCH_CRYPTS_FOLDER_PATH ) if  ( File.exist?( Indices::BRANCH_CRYPTS_FOLDER_PATH ) && File.directory?( Indices::BRANCH_CRYPTS_FOLDER_PATH ) )
    FileUtils.remove_dir( Indices::BRANCH_INDICES_FOLDER_PATH ) if  ( File.exist?( Indices::BRANCH_INDICES_FOLDER_PATH ) && File.directory?( Indices::BRANCH_INDICES_FOLDER_PATH ) )

    puts ""
    puts "  The safe has been successfully obliterated."
    puts "  The obliterated safe database is backed up in this folder."
    puts "  #{backup_folder_path}"
    puts "  safe init   # this will create a new safe"
    puts "  safe pull   # downloads a remote safe db"
    puts ""

    return


end