Make sure to delete the output file in case of an exception.
[redact.git] / lib / redact / app.rb
index 351897e2ef4c7e693535af593a5d7192d3d438c8..2cc9dd7cf74b7022948a0d207380bb08127c32ab 100644 (file)
@@ -1,5 +1,5 @@
 #--
-# $Id: app.rb 30 2005-04-23 15:25:21Z tilman $
+# $Id: app.rb 40 2005-05-25 20:19:45Z tilman $
 #
 # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
 #
@@ -66,15 +66,20 @@ module Redact
 
                        amx = compile_embryo
 
-                       Eet::File.open(@options.output, "w") do |ef|
-                               dump_amx(amx, ef)
-
-                               dump_header(ef)
-                               dump_collections(ef)
-                               dump_fonts(ef)
-                               dump_images(ef)
-                               dump_source(ef)
-                               dump_fontmap(ef)
+                       begin
+                               Eet::File.open(@options.output, "w") do |ef|
+                                       dump_amx(amx, ef)
+
+                                       dump_header(ef)
+                                       dump_collections(ef)
+                                       dump_fonts(ef)
+                                       dump_images(ef)
+                                       dump_source(ef)
+                                       dump_fontmap(ef)
+                               end
+                       rescue Exception
+                               File.rm_f(@options.output)
+                               raise
                        end
                end
 
@@ -135,7 +140,8 @@ module Redact
                                                c = "embryo_cc " +
                                                    "-i #{incl}/include " +
                                                    "-o #{tf_out.path} #{tf_in.path}"
-                                               unless system(c)
+                                               system(c)
+                                               unless (0..1).include?($?.exitstatus)
                                                        raise("Cannot compile Embryo code")
                                                end