From: Tobias DiPasquale Date: 2001-12-09T03:49:44+09:00 Subject: [ruby-talk:27963] stack overflow (was Ruby IDE?? What about using Eclipse??) Hi all, Hearing all about this Eclipse project made me go and pull it down, until I realized that I had it already. So I unzipped it, and like a few select annoying packages that I get from time to time, it installed everything world-writeable. I was so mad that I wrote this Ruby script (below) to change all the permissions back to 755/644 depending on the file type. However, the following script always ends up erroring out (error below). Is it just because the directory is too deep, or is there an error in my recursion? Any help would be appreciated. Thanks in advance! ======================= Code ======================== #!/usr/bin/env ruby def fixPermissions(filename) if FileTest.directory?(filename) File.chmod(0755, filename) printf "%s: changed to 0755\n", filename else if filename =~ /.sh$/ || filename =~ /.so$/ File.chmod(0755, filename) printf "%s: changed to 0755\n", filename else File.chmod(0644, filename) printf "%s: changed to 0644\n", filename end end end def traverseDirectory(files) files.each { |aFile| if FileTest.directory?(aFile) && (aFile != "." || aFile != "..") traverseDirectory(Dir.entries(aFile)) puts "Entering directory " + aFile else fixPermissions(aFile) end } end if __FILE__ == $0 if ARGV.size != 1 puts "Usage: permfix " exit end if !FileTest.exist? ARGV[0] puts "Error: directory " + ARGV[0] + " does not exist!" exit end if !FileTest.directory? ARGV[0] puts "Error: " + ARGV[0] + " is not a directory!" exit end traverseDirectory Dir.entries(ARGV[0]) end ========================= Error ========================= [root@localhost home]# ./permfix eclipse ./permfix:20:in `traverseDirectory': stack level too deep (SystemStackError) from ./permfix:19:in `each' from ./permfix:19:in `traverseDirectory' from ./permfix:21:in `traverseDirectory' from ./permfix:19:in `each' from ./permfix:19:in `traverseDirectory' from ./permfix:21:in `traverseDirectory' from ./permfix:19:in `each' from ./permfix:19:in `traverseDirectory' ... 3168 levels... from ./permfix:21:in `traverseDirectory' from ./permfix:19:in `each' from ./permfix:19:in `traverseDirectory' from ./permfix:45 [root@localhost home]# -- Tobias DiPasquale Solaris System Administrator Electrical and Computer Engineering Dept. Villanova University mailto: anany@ece.vill.edu tel: 610-519-5109