Permalink
Browse files

Added some sanity checks before deleting root or 1st level folder

  • Loading branch information...
1 parent 48b020f commit 8a67dc7ecca0a44a90bbbe550a4efccd31795660 @horaci horaci committed Jan 20, 2011
Showing with 15 additions and 1 deletion.
  1. +15 −1 bin/mandy-rm
View
@@ -18,7 +18,11 @@ OptionParser.new do |opts|
opts.on("-c", "--conf HADOOP_CONF", "Use this cluster xml config file.") do |config|
options.config = config
end
-
+
+ opts.on("-f", "--force", "Use this paramter to force deletion of a relative folder, root folder or 1st level folder (like /home or /tmp)") do
+ options.force = true
+ end
+
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
@@ -28,4 +32,14 @@ end.parse!
file = ARGV[0]
config = options.config || 'cluster.xml'
+if !options.force and file =~ /^[^\/]/
+ puts "mandy-rm: Cowardly refusing to delete a relative folder. Use -f parameter to force command."
+ exit
+end
+
+if !options.force and File.expand_path(file).split("/").size <= 2
+ puts "mandy-rm: Cowardly refusing to delete a root or 1st level folder. Use -f parameter to force command."
+ exit
+end
+
`$HADOOP_HOME/bin/hadoop fs -conf #{config} -rmr #{file}`

0 comments on commit 8a67dc7

Please sign in to comment.