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
fe60b6783d
commit
6352fc5f57
|
@ -1343,10 +1343,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.Read(tdata, 0, tdata.Length);
|
||||||
tfs.Close();
|
tfs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
assem = new System.Text.ASCIIEncoding().GetString(tdata);
|
assem = new System.Text.ASCIIEncoding().GetString(tdata);
|
||||||
}
|
}
|
||||||
|
@ -1366,9 +1368,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.Read(data, 0, data.Length);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
assem = System.Convert.ToBase64String(data);
|
assem = System.Convert.ToBase64String(data);
|
||||||
}
|
}
|
||||||
|
@ -1384,14 +1388,16 @@ 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", "");
|
||||||
XmlAttribute assemblyName = doc.CreateAttribute("", "Filename", "");
|
XmlAttribute assemblyName = doc.CreateAttribute("", "Filename", "");
|
||||||
|
@ -1478,30 +1484,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||||
{
|
{
|
||||||
Byte[] filedata = Convert.FromBase64String(base64);
|
Byte[] filedata = Convert.FromBase64String(base64);
|
||||||
|
|
||||||
FileStream fs = File.Create(path);
|
try
|
||||||
|
{
|
||||||
|
using (FileStream fs = File.Create(path))
|
||||||
|
{
|
||||||
fs.Write(filedata, 0, filedata.Length);
|
fs.Write(filedata, 0, filedata.Length);
|
||||||
fs.Close();
|
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.Write(base64);
|
||||||
|
|
||||||
sw.Close();
|
sw.Close();
|
||||||
|
}
|
||||||
fs.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))
|
||||||
|
{
|
||||||
|
using (StreamWriter ssw = new StreamWriter(sfs))
|
||||||
|
{
|
||||||
ssw.Write(stateE.OuterXml);
|
ssw.Write(stateE.OuterXml);
|
||||||
|
|
||||||
ssw.Close();
|
ssw.Close();
|
||||||
|
}
|
||||||
sfs.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)
|
||||||
|
@ -1511,14 +1546,24 @@ 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))
|
||||||
|
{
|
||||||
|
using (StreamWriter msw = new StreamWriter(mfs))
|
||||||
|
{
|
||||||
msw.Write(mapE.InnerText);
|
msw.Write(mapE.InnerText);
|
||||||
|
|
||||||
msw.Close();
|
msw.Close();
|
||||||
|
}
|
||||||
mfs.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