vala r1370 - in trunk: . ccode gobject



Author: juergbi
Date: Sun May 11 13:57:44 2008
New Revision: 1370
URL: http://svn.gnome.org/viewvc/vala?rev=1370&view=rev

Log:
2008-05-11  Juerg Billeter  <j bitron ch>

	* ccode/valaccodewriter.vala:
	* gobject/valaccodegeneratorsourcefile.vala:

	Fix crash when opening output file fails, fixes bug 466573


Modified:
   trunk/ChangeLog
   trunk/ccode/valaccodewriter.vala
   trunk/gobject/valaccodegeneratorsourcefile.vala

Modified: trunk/ccode/valaccodewriter.vala
==============================================================================
--- trunk/ccode/valaccodewriter.vala	(original)
+++ trunk/ccode/valaccodewriter.vala	Sun May 11 13:57:44 2008
@@ -35,13 +35,6 @@
 		}
 		construct {
 			_filename = value;
-			file_exists = FileUtils.test (_filename, FileTest.EXISTS);
-			if (file_exists) {
-				temp_filename = "%s.valatmp".printf (_filename);
-				stream = FileStream.open (temp_filename, "w");
-			} else {
-				stream = FileStream.open (_filename, "w");
-			}
 		}
 	}
 
@@ -71,7 +64,25 @@
 	public CCodeWriter (string _filename) {
 		filename = _filename;
 	}
-	
+
+	/**
+	 * Opens the file.
+	 *
+	 * @return true if the file has been opened successfully,
+	 *         false otherwise
+	 */
+	public bool open () {
+		file_exists = FileUtils.test (_filename, FileTest.EXISTS);
+		if (file_exists) {
+			temp_filename = "%s.valatmp".printf (_filename);
+			stream = FileStream.open (temp_filename, "w");
+		} else {
+			stream = FileStream.open (_filename, "w");
+		}
+
+		return (stream != null);
+	}
+
 	/**
 	 * Closes the file.
 	 */

Modified: trunk/gobject/valaccodegeneratorsourcefile.vala
==============================================================================
--- trunk/gobject/valaccodegeneratorsourcefile.vala	(original)
+++ trunk/gobject/valaccodegeneratorsourcefile.vala	Sun May 11 13:57:44 2008
@@ -297,6 +297,10 @@
 		}
 
 		var writer = new CCodeWriter (source_file.get_cheader_filename ());
+		if (!writer.open ()) {
+			Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
+			return;
+		}
 		if (comment != null) {
 			comment.write (writer);
 		}
@@ -323,6 +327,10 @@
 		writer.close ();
 		
 		writer = new CCodeWriter (source_file.get_csource_filename ());
+		if (!writer.open ()) {
+			Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
+			return;
+		}
 		writer.line_directives = context.debug;
 		if (comment != null) {
 			comment.write (writer);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]