Addresses mantis #4985 -- exceptions in DataSnapshot
parent
f575ae56cf
commit
828ba2e2b6
|
@ -30,6 +30,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using log4net;
|
using log4net;
|
||||||
using OpenSim.Region.DataSnapshot.Interfaces;
|
using OpenSim.Region.DataSnapshot.Interfaces;
|
||||||
|
@ -185,6 +186,8 @@ namespace OpenSim.Region.DataSnapshot
|
||||||
//save snapshot
|
//save snapshot
|
||||||
String path = DataFileNameScene(scene);
|
String path = DataFileNameScene(scene);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
using (XmlTextWriter snapXWriter = new XmlTextWriter(path, Encoding.Default))
|
using (XmlTextWriter snapXWriter = new XmlTextWriter(path, Encoding.Default))
|
||||||
{
|
{
|
||||||
snapXWriter.Formatting = Formatting.Indented;
|
snapXWriter.Formatting = Formatting.Indented;
|
||||||
|
@ -192,6 +195,11 @@ namespace OpenSim.Region.DataSnapshot
|
||||||
regionElement.WriteTo(snapXWriter);
|
regionElement.WriteTo(snapXWriter);
|
||||||
snapXWriter.WriteEndDocument();
|
snapXWriter.WriteEndDocument();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("[DATASNAPSHOT]: Exception on writing to file {0}: {1}", path, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
m_scenes[scene] = false;
|
m_scenes[scene] = false;
|
||||||
|
|
||||||
|
@ -206,15 +214,23 @@ namespace OpenSim.Region.DataSnapshot
|
||||||
#region Helpers
|
#region Helpers
|
||||||
private string DataFileNameFragment(Scene scene, String fragmentName)
|
private string DataFileNameFragment(Scene scene, String fragmentName)
|
||||||
{
|
{
|
||||||
return Path.Combine(m_directory, Path.ChangeExtension(scene.RegionInfo.RegionName + "_" + fragmentName, "xml"));
|
return Path.Combine(m_directory, Path.ChangeExtension(Sanitize(scene.RegionInfo.RegionName) + "_" + fragmentName, "xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private string DataFileNameScene(Scene scene)
|
private string DataFileNameScene(Scene scene)
|
||||||
{
|
{
|
||||||
return Path.Combine(m_directory, Path.ChangeExtension(scene.RegionInfo.RegionName, "xml"));
|
return Path.Combine(m_directory, Path.ChangeExtension(Sanitize(scene.RegionInfo.RegionName), "xml"));
|
||||||
//return (m_snapsDir + Path.DirectorySeparatorChar + scene.RegionInfo.RegionName + ".xml");
|
//return (m_snapsDir + Path.DirectorySeparatorChar + scene.RegionInfo.RegionName + ".xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string Sanitize(string name)
|
||||||
|
{
|
||||||
|
string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
|
||||||
|
string invalidReStr = string.Format(@"[{0}]", invalidChars);
|
||||||
|
string newname = Regex.Replace(name, invalidReStr, "_");
|
||||||
|
return newname.Replace('.', '_');
|
||||||
|
}
|
||||||
|
|
||||||
private XmlNode MakeRegionNode(Scene scene, XmlDocument basedoc)
|
private XmlNode MakeRegionNode(Scene scene, XmlDocument basedoc)
|
||||||
{
|
{
|
||||||
XmlNode docElement = basedoc.CreateNode(XmlNodeType.Element, "region", "");
|
XmlNode docElement = basedoc.CreateNode(XmlNodeType.Element, "region", "");
|
||||||
|
|
Loading…
Reference in New Issue