Class: AFI
- Inherits:
-
Object
- Object
- AFI
- Defined in:
- lib/afinus.rb
Constant Summary collapse
- MAX_RANDOM_NUMBER =
99_999_999_999_999_999
Instance Method Summary collapse
-
#clean!(recursive: false) ⇒ Object
Clean all files!.
-
#enter(dir) ⇒ Object
Enter start directory or exit.
- #execute!(directory, opts = {}) ⇒ Object
-
#fill_empty_space!(bytes) ⇒ Object
Fill empty space on partition.
-
#initialize ⇒ AFI
constructor
Start counters.
-
#remove_directories!(recursive: false) ⇒ Object
Remove Directories.
-
#rewrite(file) ⇒ Object
Overwrite and Null file.
-
#truncate_file(file, bytes_array = [50, 100, 50]) ⇒ Object
end of rewrite.
Constructor Details
#initialize ⇒ AFI
Start counters
9 10 11 12 13 14 15 |
# File 'lib/afinus.rb', line 9 def initialize @c_file = 0 @c_dir = 0 @c_err = 0 @c_byte = 0 @dirs = [] end |
Instance Method Details
#clean!(recursive: false) ⇒ Object
Clean all files!
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/afinus.rb', line 55 def clean!(recursive: false) collect(recursive && :recursive).each do |file| if File.directory?(file) @c_dir += 1 printer(@c_dir.to_s.yellow.bold, file, 'Directory Found!'.white) Dir.rmdir(file) if Dir.empty?(file) @dirs << file else begin rewrite(file) if File.writable?(file) rescue puts '>> FOLDER DO NOT EXIST OR PERMISSION DENIED <<'.red.bold end end puts "\n[#{@c_dir}] directories counted".white end end |
#enter(dir) ⇒ Object
Enter start directory or exit
32 33 34 35 36 37 38 |
# File 'lib/afinus.rb', line 32 def enter(dir) Dir.chdir(dir) print_working_dir rescue puts "\n >> FOLDER DO NOT EXIST OR PERMISSION DENIED <<\n".red.bold exit(1) end |
#execute!(directory, opts = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/afinus.rb', line 17 def execute!(directory, opts = {}) recursive = opts[:recursive].is_a?(TrueClass) @start_time = Time.now enter(directory) fill_empty_space!(512_000) # Fill empty space before recursive clean! clean!(recursive: recursive) remove_directories!(recursive: recursive) @end_time = Time.now print_info print_thank_you end |
#fill_empty_space!(bytes) ⇒ Object
Fill empty space on partition
43 44 45 46 47 48 49 50 |
# File 'lib/afinus.rb', line 43 def fill_empty_space!(bytes) @start_time = Time.now create_random_files(bytes) rescue @end_time = Time.now puts "\n[#{@c_byte}] files created in [#{(@end_time - @start_time).round(3)}] seconds".white print_delimiter end |
#remove_directories!(recursive: false) ⇒ Object
Remove Directories
77 78 79 80 |
# File 'lib/afinus.rb', line 77 def remove_directories!(recursive: false) collect(recursive && :recursive).select { |file| File.directory?(file) } .each { |dir| Dir.rmdir(dir) } end |
#rewrite(file) ⇒ Object
Overwrite and Null file
83 84 85 86 87 88 89 90 91 |
# File 'lib/afinus.rb', line 83 def rewrite(file) truncate_file(file) File.delete(file) @c_file += 1 printer(@c_file.to_s.yellow, file.white, 'Overwritten, Nulled, Removed!'.yellow) rescue @c_err += 1 printer(@c_err.to_s.red, file.white.bold, 'NOT PROCESSED => PERMISSION PROBLEM?'.red.bold) end |
#truncate_file(file, bytes_array = [50, 100, 50]) ⇒ Object
end of rewrite
95 96 97 98 99 100 101 |
# File 'lib/afinus.rb', line 95 def truncate_file(file, bytes_array = [50, 100, 50]) bytes_array = Array(bytes_array) bytes_array.each do |bytes| File.write(file, Random.new.bytes(bytes).to_s) File.truncate(file, 0) end end |