# HG changeset patch
# User Edouard Tisserant
# Date 1598874848 -7200
# Node ID 4ac68ec9786f0c0e8c06f092f47ca4f274f8dce6
# Parent  d46d545ff7b791b54fa7bcefbbbdf79f693d9238
Attempt to workaround problem reported about empty plc.xml after unrelated crash. Now, if etree model is corrupted in a way tostring() would generate an empty string, exception prevents saving.

diff -r d46d545ff7b7 -r 4ac68ec9786f plcopen/plcopen.py
--- a/plcopen/plcopen.py	Fri Aug 28 15:29:35 2020 +0200
+++ b/plcopen/plcopen.py	Mon Aug 31 13:54:08 2020 +0200
@@ -331,12 +331,16 @@
 
 
 def SaveProject(project, filepath):
-    project_file = open(filepath, 'w')
-    project_file.write(etree.tostring(
+    content = etree.tostring(
         project,
         pretty_print=True,
         xml_declaration=True,
-        encoding='utf-8'))
+        encoding='utf-8')
+
+    assert len(content) != 0
+        
+    project_file = open(filepath, 'w')
+    project_file.write(content)
     project_file.close()