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
|
try
|
||||||
{
|
{
|
||||||
FileStream tfs = File.Open(assemName + ".text",
|
using (FileStream tfs = File.Open(assemName + ".text",
|
||||||
FileMode.Open, FileAccess.Read);
|
FileMode.Open, FileAccess.Read))
|
||||||
tfs.Read(tdata, 0, tdata.Length);
|
{
|
||||||
tfs.Close();
|
tfs.Read(tdata, 0, tdata.Length);
|
||||||
|
tfs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
assem = new System.Text.ASCIIEncoding().GetString(tdata);
|
assem = new System.Text.ASCIIEncoding().GetString(tdata);
|
||||||
}
|
}
|
||||||
|
@ -1340,9 +1342,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||||
|
|
||||||
try
|
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();
|
fs.Read(data, 0, data.Length);
|
||||||
|
fs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
assem = System.Convert.ToBase64String(data);
|
assem = System.Convert.ToBase64String(data);
|
||||||
}
|
}
|
||||||
|
@ -1358,13 +1362,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||||
|
|
||||||
if (File.Exists(fn + ".map"))
|
if (File.Exists(fn + ".map"))
|
||||||
{
|
{
|
||||||
FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read);
|
using (FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read))
|
||||||
StreamReader msr = new StreamReader(mfs);
|
{
|
||||||
|
using (StreamReader msr = new StreamReader(mfs))
|
||||||
map = msr.ReadToEnd();
|
{
|
||||||
|
map = msr.ReadToEnd();
|
||||||
msr.Close();
|
msr.Close();
|
||||||
mfs.Close();
|
}
|
||||||
|
mfs.Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlElement assemblyData = doc.CreateElement("", "Assembly", "");
|
XmlElement assemblyData = doc.CreateElement("", "Assembly", "");
|
||||||
|
@ -1452,30 +1458,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||||
{
|
{
|
||||||
Byte[] filedata = Convert.FromBase64String(base64);
|
Byte[] filedata = Convert.FromBase64String(base64);
|
||||||
|
|
||||||
FileStream fs = File.Create(path);
|
try
|
||||||
fs.Write(filedata, 0, filedata.Length);
|
{
|
||||||
fs.Close();
|
using (FileStream fs = File.Create(path))
|
||||||
|
{
|
||||||
fs = File.Create(path + ".text");
|
fs.Write(filedata, 0, filedata.Length);
|
||||||
StreamWriter sw = new StreamWriter(fs);
|
fs.Close();
|
||||||
|
}
|
||||||
sw.Write(base64);
|
}
|
||||||
|
catch (IOException ex)
|
||||||
sw.Close();
|
{
|
||||||
fs.Close();
|
// 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());
|
string statepath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
|
||||||
statepath = Path.Combine(statepath, itemID.ToString() + ".state");
|
statepath = Path.Combine(statepath, itemID.ToString() + ".state");
|
||||||
|
|
||||||
FileStream sfs = File.Create(statepath);
|
try
|
||||||
StreamWriter ssw = new StreamWriter(sfs);
|
{
|
||||||
|
using (FileStream sfs = File.Create(statepath))
|
||||||
ssw.Write(stateE.OuterXml);
|
{
|
||||||
|
using (StreamWriter ssw = new StreamWriter(sfs))
|
||||||
ssw.Close();
|
{
|
||||||
sfs.Close();
|
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");
|
XmlNodeList mapL = rootE.GetElementsByTagName("LineMap");
|
||||||
if (mapL.Count > 0)
|
if (mapL.Count > 0)
|
||||||
|
@ -1485,13 +1520,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||||
string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
|
string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
|
||||||
mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
|
mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
|
||||||
|
|
||||||
FileStream mfs = File.Create(mappath);
|
try
|
||||||
StreamWriter msw = new StreamWriter(mfs);
|
{
|
||||||
|
using (FileStream mfs = File.Create(mappath))
|
||||||
msw.Write(mapE.InnerText);
|
{
|
||||||
|
using (StreamWriter msw = new StreamWriter(mfs))
|
||||||
msw.Close();
|
{
|
||||||
mfs.Close();
|
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;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue