Bug in 0.6.9 sometimes restoring script state causes region console to crash due to unhandled file lock exception. Attempt to resolve by wrapping several instances of file create / read logic in using statements and added some error handling for locked file exceptions. If it is IDisposable, it must be disposed! The close statements are unnecessary but harmless so I have left those in. The end of the using block will close and dispose automagically.
parent
b2ef5658b1
commit
61f9b3c2cf
|
@ -1317,10 +1317,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
|
||||
try
|
||||
{
|
||||
FileStream tfs = File.Open(assemName + ".text",
|
||||
FileMode.Open, FileAccess.Read);
|
||||
using (FileStream tfs = File.Open(assemName + ".text",
|
||||
FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
tfs.Read(tdata, 0, tdata.Length);
|
||||
tfs.Close();
|
||||
}
|
||||
|
||||
assem = new System.Text.ASCIIEncoding().GetString(tdata);
|
||||
}
|
||||
|
@ -1340,9 +1342,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
|
||||
try
|
||||
{
|
||||
FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read);
|
||||
using (FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
fs.Read(data, 0, data.Length);
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
assem = System.Convert.ToBase64String(data);
|
||||
}
|
||||
|
@ -1358,14 +1362,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
|
||||
if (File.Exists(fn + ".map"))
|
||||
{
|
||||
FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read);
|
||||
StreamReader msr = new StreamReader(mfs);
|
||||
|
||||
using (FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
using (StreamReader msr = new StreamReader(mfs))
|
||||
{
|
||||
map = msr.ReadToEnd();
|
||||
|
||||
msr.Close();
|
||||
}
|
||||
mfs.Close();
|
||||
}
|
||||
}
|
||||
|
||||
XmlElement assemblyData = doc.CreateElement("", "Assembly", "");
|
||||
XmlAttribute assemblyName = doc.CreateAttribute("", "Filename", "");
|
||||
|
@ -1452,30 +1458,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
{
|
||||
Byte[] filedata = Convert.FromBase64String(base64);
|
||||
|
||||
FileStream fs = File.Create(path);
|
||||
try
|
||||
{
|
||||
using (FileStream fs = File.Create(path))
|
||||
{
|
||||
fs.Write(filedata, 0, filedata.Length);
|
||||
fs.Close();
|
||||
|
||||
fs = File.Create(path + ".text");
|
||||
StreamWriter sw = new StreamWriter(fs);
|
||||
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// if there already exists a file at that location, it may be locked.
|
||||
m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message);
|
||||
}
|
||||
try
|
||||
{
|
||||
using (FileStream fs = File.Create(path + ".text"))
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(fs))
|
||||
{
|
||||
sw.Write(base64);
|
||||
|
||||
sw.Close();
|
||||
}
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// if there already exists a file at that location, it may be locked.
|
||||
m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string statepath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
|
||||
statepath = Path.Combine(statepath, itemID.ToString() + ".state");
|
||||
|
||||
FileStream sfs = File.Create(statepath);
|
||||
StreamWriter ssw = new StreamWriter(sfs);
|
||||
|
||||
try
|
||||
{
|
||||
using (FileStream sfs = File.Create(statepath))
|
||||
{
|
||||
using (StreamWriter ssw = new StreamWriter(sfs))
|
||||
{
|
||||
ssw.Write(stateE.OuterXml);
|
||||
|
||||
ssw.Close();
|
||||
}
|
||||
sfs.Close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// if there already exists a file at that location, it may be locked.
|
||||
m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message);
|
||||
}
|
||||
|
||||
XmlNodeList mapL = rootE.GetElementsByTagName("LineMap");
|
||||
if (mapL.Count > 0)
|
||||
|
@ -1485,14 +1520,24 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
|
||||
mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
|
||||
|
||||
FileStream mfs = File.Create(mappath);
|
||||
StreamWriter msw = new StreamWriter(mfs);
|
||||
|
||||
try
|
||||
{
|
||||
using (FileStream mfs = File.Create(mappath))
|
||||
{
|
||||
using (StreamWriter msw = new StreamWriter(mfs))
|
||||
{
|
||||
msw.Write(mapE.InnerText);
|
||||
|
||||
msw.Close();
|
||||
}
|
||||
mfs.Close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// if there already exists a file at that location, it may be locked.
|
||||
m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue