Top Level Namespace

Defined Under Namespace

Modules: Backup, Crypto, GZIP Classes: Archive, EncbsConfig, String

Instance Method Summary collapse

Instance Method Details

#check_mode(file, first, second) ⇒ Object



23
24
25
26
27
# File 'lib/helpers.rb', line 23

def check_mode(file, first, second)
  unless first == second
    puts_fail "Permission wasn't changed for #{file.dark_green}"
  end
end

#check_rights(file, first_uid, first_gid, second_uid, second_gid) ⇒ Object



29
30
31
32
33
# File 'lib/helpers.rb', line 29

def check_rights(file, first_uid, first_gid, second_uid, second_gid)
  unless first_uid == second_uid and first_gid == second_gid
    puts_fail "Group and user wasn't change for #{file.dark_green}"
  end
end

#create_lockObject



35
36
37
38
39
# File 'lib/helpers.rb', line 35

def create_lock
  open("/tmp/encbs.lock", "w") do |f|
    f.print Process.pid
  end
end

#lock_exists?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/helpers.rb', line 45

def lock_exists?
  File.exists? "/tmp/encbs.lock"
end


11
12
13
# File 'lib/helpers.rb', line 11

def print_verbose(msg)
  print msg if $PRINT_VERBOSE
end

#puts_fail(msg) ⇒ Object



1
2
3
4
5
# File 'lib/helpers.rb', line 1

def puts_fail(msg)
  STDERR.puts "#{"Error! ".red}#{msg}"

  exit msg.length
end

#puts_verbose(msg) ⇒ Object



7
8
9
# File 'lib/helpers.rb', line 7

def puts_verbose(msg)
  puts msg if $PRINT_VERBOSE
end

#remove_lockObject



41
42
43
# File 'lib/helpers.rb', line 41

def remove_lock
  FileUtils.rm "/tmp/encbs.lock" if File.exists? "/tmp/encbs.lock"
end

#try_create_dir(dir) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/helpers.rb', line 15

def try_create_dir(dir)
  begin
    FileUtils.mkdir_p dir unless File.directory? dir
  rescue Errno::EACCES
    puts_fail "Permission denied for #{dir.dark_green}"
  end
end