Module: VerySafeRm::RM

Defined in:
lib/very_safe_rm/rm_one.rb

Class Method Summary collapse

Class Method Details

.check_bang(file) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/very_safe_rm/rm_one.rb', line 26

def self.check_bang(file)
  file.reverse.each_char do |char|
    return false unless char == '!'
    STDERR.print "Did you really want to delete `#{file}? [y/N] "
    return true unless STDIN.gets =~ /^y(es)?$/i
  end
end

.check_force_rm?(file) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'lib/very_safe_rm/rm_one.rb', line 19

def self.check_force_rm?(file)
  return false unless File.exist? \
    File.expand_path("-#{file}.rm", File.dirname(file))
  RM.rm "-#{file}.rm", ['-r', '-f']
  true
end

.rm(file, args) ⇒ Object



3
4
5
6
# File 'lib/very_safe_rm/rm_one.rb', line 3

def self.rm(file, args)
  return if RM.check_bang file
  system ['/bin/rm', $0], *args, '--', file
end

.rm_one(file, args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/very_safe_rm/rm_one.rb', line 8

def self.rm_one(file, args)
  return RM.rm file, [] unless File.exist? file
  filesystem = `stat -fc %T "#{file}"`
  if filesystem == 'nilfs' then RM.rm file, ['-r', '-v', '-f']
  elsif Dir.empty? file then RM.rm file, ['-r', '-f', '-v']
  elsif File.empty? file then RM.rm file, ['-f', '-v']
  elsif RM.check_force_rm? file then RM.rm file, ['-v', *args]
  else RM.rm file, ['-i', '-v', *args]
  end
end