aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/DataSnapshot/SnapshotStore.cs
diff options
context:
space:
mode:
authorDiva Canto2010-08-26 14:19:52 -0700
committerDiva Canto2010-08-26 14:19:52 -0700
commit6198fe53e6b14eede432b8ce2825fcb4f933ebd8 (patch)
treebf44e2a92f16da3bf34d8851867d64feae454929 /OpenSim/Region/DataSnapshot/SnapshotStore.cs
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-6198fe53e6b14eede432b8ce2825fcb4f933ebd8.zip
opensim-SC_OLD-6198fe53e6b14eede432b8ce2825fcb4f933ebd8.tar.gz
opensim-SC_OLD-6198fe53e6b14eede432b8ce2825fcb4f933ebd8.tar.bz2
opensim-SC_OLD-6198fe53e6b14eede432b8ce2825fcb4f933ebd8.tar.xz
Addresses mantis #4985 -- exceptions in DataSnapshot
Diffstat (limited to 'OpenSim/Region/DataSnapshot/SnapshotStore.cs')
-rw-r--r--OpenSim/Region/DataSnapshot/SnapshotStore.cs30
1 files changed, 23 insertions, 7 deletions
diff --git a/OpenSim/Region/DataSnapshot/SnapshotStore.cs b/OpenSim/Region/DataSnapshot/SnapshotStore.cs
index 70cb205..3977394 100644
--- a/OpenSim/Region/DataSnapshot/SnapshotStore.cs
+++ b/OpenSim/Region/DataSnapshot/SnapshotStore.cs
@@ -30,6 +30,7 @@ using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Reflection; 31using System.Reflection;
32using System.Text; 32using System.Text;
33using System.Text.RegularExpressions;
33using System.Xml; 34using System.Xml;
34using log4net; 35using log4net;
35using OpenSim.Region.DataSnapshot.Interfaces; 36using OpenSim.Region.DataSnapshot.Interfaces;
@@ -185,12 +186,19 @@ namespace OpenSim.Region.DataSnapshot
185 //save snapshot 186 //save snapshot
186 String path = DataFileNameScene(scene); 187 String path = DataFileNameScene(scene);
187 188
188 using (XmlTextWriter snapXWriter = new XmlTextWriter(path, Encoding.Default)) 189 try
189 { 190 {
190 snapXWriter.Formatting = Formatting.Indented; 191 using (XmlTextWriter snapXWriter = new XmlTextWriter(path, Encoding.Default))
191 snapXWriter.WriteStartDocument(); 192 {
192 regionElement.WriteTo(snapXWriter); 193 snapXWriter.Formatting = Formatting.Indented;
193 snapXWriter.WriteEndDocument(); 194 snapXWriter.WriteStartDocument();
195 regionElement.WriteTo(snapXWriter);
196 snapXWriter.WriteEndDocument();
197 }
198 }
199 catch (Exception e)
200 {
201 m_log.WarnFormat("[DATASNAPSHOT]: Exception on writing to file {0}: {1}", path, e.Message);
194 } 202 }
195 203
196 m_scenes[scene] = false; 204 m_scenes[scene] = false;
@@ -206,15 +214,23 @@ namespace OpenSim.Region.DataSnapshot
206 #region Helpers 214 #region Helpers
207 private string DataFileNameFragment(Scene scene, String fragmentName) 215 private string DataFileNameFragment(Scene scene, String fragmentName)
208 { 216 {
209 return Path.Combine(m_directory, Path.ChangeExtension(scene.RegionInfo.RegionName + "_" + fragmentName, "xml")); 217 return Path.Combine(m_directory, Path.ChangeExtension(Sanitize(scene.RegionInfo.RegionName) + "_" + fragmentName, "xml"));
210 } 218 }
211 219
212 private string DataFileNameScene(Scene scene) 220 private string DataFileNameScene(Scene scene)
213 { 221 {
214 return Path.Combine(m_directory, Path.ChangeExtension(scene.RegionInfo.RegionName, "xml")); 222 return Path.Combine(m_directory, Path.ChangeExtension(Sanitize(scene.RegionInfo.RegionName), "xml"));
215 //return (m_snapsDir + Path.DirectorySeparatorChar + scene.RegionInfo.RegionName + ".xml"); 223 //return (m_snapsDir + Path.DirectorySeparatorChar + scene.RegionInfo.RegionName + ".xml");
216 } 224 }
217 225
226 private static string Sanitize(string name)
227 {
228 string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
229 string invalidReStr = string.Format(@"[{0}]", invalidChars);
230 string newname = Regex.Replace(name, invalidReStr, "_");
231 return newname.Replace('.', '_');
232 }
233
218 private XmlNode MakeRegionNode(Scene scene, XmlDocument basedoc) 234 private XmlNode MakeRegionNode(Scene scene, XmlDocument basedoc)
219 { 235 {
220 XmlNode docElement = basedoc.CreateNode(XmlNodeType.Element, "region", ""); 236 XmlNode docElement = basedoc.CreateNode(XmlNodeType.Element, "region", "");