Skip to content

Commit 264031a

Browse files
committed
Land rapid7#2324, make retab backups optional
2 parents 4259bc6 + f3ab6d1 commit 264031a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tools/dev/retab.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,32 @@
44
# Replace leading tabs with 2-width spaces.
55
# I'm sure there's a sed/awk/perl oneliner that's
66
# a million times better but this is more readable for me.
7+
#
8+
# Usage:
9+
# metasploit-framework$ ./tools/dev/retab.rb [path]
10+
#
11+
# If local backups are desired, prepend with "MSF_RETAB_BACKUPS" set,
12+
# like so:
13+
# metasploit-framework$ MSF_RETAB_BACKUPS=1 ./tools/dev/retab.rb [path]
714

815
require 'fileutils'
916
require 'find'
1017

1118
dir = ARGV[0] || "."
19+
keep_backups = !!(ENV['MSF_RETAB_BACKUPS'] || ENV['MSF_RETAB_BACKUP'])
20+
puts "Keeping .notab backups" if keep_backups
21+
1222
raise ArgumentError, "Need a filename or directory" unless (dir and File.readable? dir)
1323

1424
Find.find(dir) do |infile|
1525
next unless File.file? infile
1626
next unless infile =~ /rb$/
1727
outfile = infile
18-
backup = "#{infile}.notab"
19-
FileUtils.cp infile, backup
28+
29+
if keep_backups
30+
backup = "#{infile}.notab"
31+
FileUtils.cp infile, backup
32+
end
2033

2134
data = File.open(infile, "rb") {|f| f.read f.stat.size}
2235
fixed = []

0 commit comments

Comments
 (0)