From fcab3510b379c812d675ef57ae7000f23d3a624b Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Thu, 26 Mar 2009 14:28:00 +0000 Subject: Avoid writing script state to the filesystem if the state has not changed. Remove the unneccessary double check that was only used to provide a meaningless warning message for a corner case. --- .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index bcd4ccd..3884138 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -92,6 +92,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private StateSource m_stateSource; private bool m_postOnRez; private bool m_startedFromSavedState = false; + private string m_CurrentState = String.Empty; //private ISponsor m_ScriptSponsor; private Dictionary, KeyValuePair> @@ -870,21 +871,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance string xml = ScriptSerializer.Serialize(this); - try - { - FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state")); - System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); - Byte[] buf = enc.GetBytes(xml); - fs.Write(buf, 0, buf.Length); - fs.Close(); - } - catch(Exception e) - { - m_log.Error("Unable to save xml\n"+e.ToString()); - } - if (!File.Exists(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state"))) + if (m_CurrentState != xml) { - throw new Exception("Completed persistence save, but no file was created"); + try + { + FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state")); + System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); + Byte[] buf = enc.GetBytes(xml); + fs.Write(buf, 0, buf.Length); + fs.Close(); + } + catch(Exception e) + { + m_log.Error("Unable to save xml\n"+e.ToString()); + } + //if (!File.Exists(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state"))) + //{ + // throw new Exception("Completed persistence save, but no file was created"); + //} + m_CurrentState = xml; } } -- cgit v1.1