From: <jh...@us...> - 2010-08-12 06:24:58
|
Revision: 209 http://etch.svn.sourceforge.net/etch/?rev=209&view=rev Author: jheiss Date: 2010-08-12 06:24:51 +0000 (Thu, 12 Aug 2010) Log Message: ----------- In the test_nested_target method in test_actions.rb there was a section of code which called Tempfile.new('etchtest').path, then immediately deleted the file and replaced it with a directory. The Tempfile object would get garbage collected later and Tempfile would throw an error attempting to delete what was now a directory. Replace that with a call to deleted_tempfile so that Tempfile doesn't try to clean things up later. Replace a bunch of instances of Tempfile.new('etchtest').path with a new method released_tempfile, which explicitly does a close! on the Tempfile and then recreates the file. It may be overly paranoid of me, but it seems that depending on Ruby to more or less immediately garbage collect the Tempfile object is not ideal. Modified Paths: -------------- trunk/test/etchtest.rb trunk/test/test_actions.rb trunk/test/test_attributes.rb trunk/test/test_auth.rb trunk/test/test_commands.rb trunk/test/test_delete.rb trunk/test/test_depend.rb trunk/test/test_file.rb trunk/test/test_history.rb trunk/test/test_link.rb trunk/test/test_local_requests.rb trunk/test/test_nodegroups.rb trunk/test/test_options.rb trunk/test/test_outputcapture.rb trunk/test/test_scripts.rb trunk/test/test_transitions.rb Modified: trunk/test/etchtest.rb =================================================================== --- trunk/test/etchtest.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/etchtest.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -11,12 +11,32 @@ SERVERDIR = "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/server" CLIENTDIR = "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/client" + # Creates a temporary file via Tempfile, capture the filename, tell Tempfile + # to clean up, then return the path. This gives the caller a filename that + # they should be able to write to, that was recently unused and unique, and + # that Tempfile won't try to clean up later. This can be useful when the + # caller might want a path to use for symlinks, directories, etc. where + # Tempfile might choke trying to clean up what it expects to be a plain + # file. + def deleted_tempfile + tmpfile = Tempfile.new('etchtest') + tmppath = tmpfile.path + tmpfile.close! + tmppath + end + # Creates a file via Tempfile but then arranges for Tempfile to release it + # so that the caller doesn't have to worry about Tempfile cleaning it up + # later at an inopportune time. It is up to the caller to ensure the file + # is cleaned up. + def released_tempfile + tmppath = deleted_tempfile + File.open(tmppath, 'w') {|file|} + tmppath + end # Haven't found a Ruby method for creating temporary directories, # so create a temporary file and replace it with a directory. def tempdir - tmpfile = Tempfile.new('etchtest') - tmpdir = tmpfile.path - tmpfile.close! + tmpdir = deleted_tempfile Dir.mkdir(tmpdir) tmpdir end Modified: trunk/test/test_actions.rb =================================================================== --- trunk/test/test_actions.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_actions.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -11,7 +11,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository @@ -23,7 +23,7 @@ #puts "Using #{@testbase} as client working directory" # Generate another file to use as our link target - @destfile = Tempfile.new('etchtest').path + @destfile = released_tempfile #puts "Using #{@destfile} as link destination file" end @@ -345,8 +345,7 @@ # that /etc/foo exist first. # - nestedtargetdir = Tempfile.new('etchtest').path - File.delete(nestedtargetdir) + nestedtargetdir = deleted_tempfile nestedtargetfile = File.join(nestedtargetdir, 'etchnestedtest') FileUtils.mkdir_p("#{@repodir}/source/#{nestedtargetfile}") @@ -377,6 +376,8 @@ # Verify that the file was created properly assert_equal(sourcecontents, get_file_contents(nestedtargetfile), 'nested target with test') + + FileUtils.rm_rf(nestedtargetdir) end def test_action_with_xml_escape Modified: trunk/test/test_attributes.rb =================================================================== --- trunk/test/test_attributes.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_attributes.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -13,7 +13,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository Modified: trunk/test/test_auth.rb =================================================================== --- trunk/test/test_auth.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_auth.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -14,7 +14,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository Modified: trunk/test/test_commands.rb =================================================================== --- trunk/test/test_commands.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_commands.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -11,7 +11,7 @@ def setup # Generate a file to use as a target in commands - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository @@ -249,7 +249,7 @@ # testname = 'command with file dependency' - targetfile2 = Tempfile.new('etchtest').path + targetfile2 = released_tempfile FileUtils.mkdir_p("#{@repodir}/source/#{targetfile2}") File.open("#{@repodir}/source/#{targetfile2}/config.xml", 'w') do |file| file.puts <<-EOF Modified: trunk/test/test_delete.rb =================================================================== --- trunk/test/test_delete.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_delete.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -11,7 +11,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository @@ -23,7 +23,7 @@ #puts "Using #{@testbase} as client working directory" # Generate another file to use as our link target - @destfile = Tempfile.new('etchtest').path + @destfile = released_tempfile #puts "Using #{@destfile} as link destination file" end Modified: trunk/test/test_depend.rb =================================================================== --- trunk/test/test_depend.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_depend.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -11,9 +11,9 @@ def setup # Generate a couple of files to use as our etch target/destinations - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" - @targetfile2 = Tempfile.new('etchtest').path + @targetfile2 = released_tempfile #puts "Using #{@targetfile2} as 2nd target file" # Generate a directory for our test repository Modified: trunk/test/test_file.rb =================================================================== --- trunk/test/test_file.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_file.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -11,7 +11,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository Modified: trunk/test/test_history.rb =================================================================== --- trunk/test/test_history.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_history.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -12,7 +12,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository @@ -256,7 +256,7 @@ # # Generate another file to use as our link target - @destfile = Tempfile.new('etchtest').path + @destfile = released_tempfile # Make the original target a link File.delete(@targetfile) Modified: trunk/test/test_link.rb =================================================================== --- trunk/test/test_link.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_link.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -12,7 +12,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Delete the target file so that we're starting with nothing. Creating @@ -28,8 +28,8 @@ #puts "Using #{@testbase} as client working directory" # Generate a couple more files to use as our link targets - @destfile = Tempfile.new('etchtest').path - @destfile2 = Tempfile.new('etchtest').path + @destfile = released_tempfile + @destfile2 = released_tempfile #puts "Using #{@destfile} as link destination file" end Modified: trunk/test/test_local_requests.rb =================================================================== --- trunk/test/test_local_requests.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_local_requests.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -11,7 +11,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository Modified: trunk/test/test_nodegroups.rb =================================================================== --- trunk/test/test_nodegroups.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_nodegroups.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -11,7 +11,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository Modified: trunk/test/test_options.rb =================================================================== --- trunk/test/test_options.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_options.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -11,7 +11,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository @@ -136,7 +136,7 @@ </config> EOF end - targetfile2 = Tempfile.new('etchtest').path + targetfile2 = released_tempfile FileUtils.mkdir_p("#{@repodir}/source/#{targetfile2}") File.open("#{@repodir}/source/#{targetfile2}/config.xml", 'w') do |file| file.puts <<-EOF @@ -150,7 +150,7 @@ </config> EOF end - targetfile3 = Tempfile.new('etchtest').path + targetfile3 = released_tempfile FileUtils.mkdir_p("#{@repodir}/source/#{targetfile3}") File.open("#{@repodir}/source/#{targetfile3}/config.xml", 'w') do |file| file.puts <<-EOF @@ -172,7 +172,7 @@ end end - cmdtargetfile1 = Tempfile.new('etchtest').path + cmdtargetfile1 = released_tempfile FileUtils.mkdir_p("#{@repodir}/commands/etchtest1") File.open("#{@repodir}/commands/etchtest1/commands.xml", 'w') do |file| file.puts <<-EOF @@ -188,7 +188,7 @@ </commands> EOF end - cmdtargetfile2 = Tempfile.new('etchtest').path + cmdtargetfile2 = released_tempfile FileUtils.mkdir_p("#{@repodir}/commands/etchtest2") File.open("#{@repodir}/commands/etchtest2/commands.xml", 'w') do |file| file.puts <<-EOF @@ -204,7 +204,7 @@ </commands> EOF end - cmdtargetfile3 = Tempfile.new('etchtest').path + cmdtargetfile3 = released_tempfile FileUtils.mkdir_p("#{@repodir}/commands/etchtest3") File.open("#{@repodir}/commands/etchtest3/commands.xml", 'w') do |file| file.puts <<-EOF @@ -266,8 +266,8 @@ # testname = 'command line file requests with depends' - targetfile2 = Tempfile.new('etchtest').path - targetfile3 = Tempfile.new('etchtest').path + targetfile2 = released_tempfile + targetfile3 = released_tempfile FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| file.puts <<-EOF @@ -333,8 +333,8 @@ # testname = 'mixed command line requests with depends' - targetfile2 = Tempfile.new('etchtest').path - targetfile3 = Tempfile.new('etchtest').path + targetfile2 = released_tempfile + targetfile3 = released_tempfile FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| file.puts <<-EOF @@ -384,7 +384,7 @@ end end - cmdtargetfile1 = Tempfile.new('etchtest').path + cmdtargetfile1 = released_tempfile FileUtils.mkdir_p("#{@repodir}/commands/etchtest1") File.open("#{@repodir}/commands/etchtest1/commands.xml", 'w') do |file| file.puts <<-EOF Modified: trunk/test/test_outputcapture.rb =================================================================== --- trunk/test/test_outputcapture.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_outputcapture.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -15,7 +15,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository Modified: trunk/test/test_scripts.rb =================================================================== --- trunk/test/test_scripts.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_scripts.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -12,7 +12,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository @@ -233,7 +233,7 @@ end # Generate a file to use as our link target - @destfile = Tempfile.new('etchtest').path + @destfile = released_tempfile File.open("#{@repodir}/source/#{@targetfile}/link.script", 'w') do |file| file.puts("@contents << '#{@destfile}'") end Modified: trunk/test/test_transitions.rb =================================================================== --- trunk/test/test_transitions.rb 2010-06-28 22:02:45 UTC (rev 208) +++ trunk/test/test_transitions.rb 2010-08-12 06:24:51 UTC (rev 209) @@ -12,7 +12,7 @@ def setup # Generate a file to use as our etch target/destination - @targetfile = Tempfile.new('etchtest').path + @targetfile = released_tempfile #puts "Using #{@targetfile} as target file" # Generate a directory for our test repository @@ -24,7 +24,7 @@ #puts "Using #{@testbase} as client working directory" # Generate another file to use as our link target - @destfile = Tempfile.new('etchtest').path + @destfile = released_tempfile end # This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |