Sha256: 42bea036acaac100376b3f0cfc8e2330cb774a45ebcee9c48e851b2b362a5ace

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

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

    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

    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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
very_safe_rm-0.3.3 lib/very_safe_rm/rm_one.rb