Fix the windows sharing violations on script crossings

GenericGridServerConcept
Melanie Thielker 2009-02-18 22:32:25 +00:00
parent f1795fd9b0
commit 0086f9bd92
3 changed files with 94 additions and 19 deletions

View File

@ -353,30 +353,58 @@ namespace OpenSim.Region.Framework.Scenes
if (fn == String.Empty)
continue;
FileInfo fi = new FileInfo(assembly);
String filedata = String.Empty;
if (fi == null)
continue;
Byte[] data = new Byte[fi.Length];
try
if (File.Exists(assembly+".text"))
{
FileStream fs = File.Open(assembly, FileMode.Open, FileAccess.Read);
fs.Read(data, 0, data.Length);
fs.Close();
}
catch (Exception e)
{
m_log.DebugFormat("[SOG]: Unable to open script assembly {0}, reason: {1}", assembly, e.Message);
}
FileInfo tfi = new FileInfo(assembly+".text");
if (tfi == null)
continue;
Byte[] tdata = new Byte[tfi.Length];
try
{
FileStream tfs = File.Open(assembly+".text", FileMode.Open, FileAccess.Read);
tfs.Read(tdata, 0, tdata.Length);
tfs.Close();
}
catch (Exception e)
{
m_log.DebugFormat("[SOG]: Unable to open script textfile {0}, reason: {1}", assembly+".text", e.Message);
}
filedata = new System.Text.ASCIIEncoding().GetString(tdata);
}
else
{
FileInfo fi = new FileInfo(assembly);
if (fi == null)
continue;
Byte[] data = new Byte[fi.Length];
try
{
FileStream fs = File.Open(assembly, FileMode.Open, FileAccess.Read);
fs.Read(data, 0, data.Length);
fs.Close();
}
catch (Exception e)
{
m_log.DebugFormat("[SOG]: Unable to open script assembly {0}, reason: {1}", assembly, e.Message);
}
filedata = System.Convert.ToBase64String(data);
}
XmlElement assemblyData = xmldoc.CreateElement("", "Assembly", "");
XmlAttribute assemblyName = xmldoc.CreateAttribute("", "Filename", "");
assemblyName.Value = fn;
assemblyData.Attributes.Append(assemblyName);
assemblyData.InnerText = System.Convert.ToBase64String(data);
assemblyData.InnerText = filedata;
wrapper.AppendChild(assemblyData);
}
@ -441,6 +469,11 @@ namespace OpenSim.Region.Framework.Scenes
FileStream fs = File.Create(path);
fs.Write(filedata, 0, filedata.Length);
fs.Close();
Byte[] textbytes = new System.Text.ASCIIEncoding().GetBytes(asm.InnerText);
fs = File.Create(path+".text");
fs.Write(textbytes, 0, textbytes.Length);
fs.Close();
}
}
break;

View File

@ -343,7 +343,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
// Check this late so the map is generated on sim start
//
if (File.Exists(OutFile))
if (File.Exists(OutFile) && File.Exists(OutFile+".text"))
{
// m_scriptEngine.Log.DebugFormat("[Compiler] Returning existing assembly for {0}", asset);
return OutFile;
@ -579,6 +579,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
}
// m_scriptEngine.Log.DebugFormat("[Compiler] Compiled new assembly "+
// "for {0}", asset);
// Because windows likes to perform exclusive locks, we simply
// write out a textual representation of the file here
//
// Read the binary file into a buffer
//
FileInfo fi = new FileInfo(OutFile);
if (fi == null)
{
string errtext = String.Empty;
errtext += "No compile error. But not able to stat file.";
throw new Exception(errtext);
}
Byte[] data = new Byte[fi.Length];
try
{
FileStream fs = File.Open(OutFile, FileMode.Open, FileAccess.Read);
fs.Read(data, 0, data.Length);
fs.Close();
}
catch (Exception e)
{
string errtext = String.Empty;
errtext += "No compile error. But not able to open file.";
throw new Exception(errtext);
}
// Convert to base64
//
string filetext = System.Convert.ToBase64String(data);
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
Byte[] buf = enc.GetBytes(filetext);
FileStream sfs = File.Create(OutFile+".text");
sfs.Write(buf, 0, buf.Length);
sfs.Close();
return OutFile;
}

View File

@ -744,8 +744,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
if (File.Exists(m_Assemblies[assetID]))
File.Delete(m_Assemblies[assetID]);
if (File.Exists(m_Assemblies[assetID]+".state"))
File.Delete(m_Assemblies[assetID]+".state");
if (File.Exists(m_Assemblies[assetID]+".text"))
File.Delete(m_Assemblies[assetID]+".text");
if (File.Exists(m_Assemblies[assetID]+".mdb"))
File.Delete(m_Assemblies[assetID]+".mdb");