diff options
author | Diva Canto | 2010-08-26 14:19:52 -0700 |
---|---|---|
committer | Diva Canto | 2010-08-26 14:19:52 -0700 |
commit | 6198fe53e6b14eede432b8ce2825fcb4f933ebd8 (patch) | |
tree | bf44e2a92f16da3bf34d8851867d64feae454929 /OpenSim/Region | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC-6198fe53e6b14eede432b8ce2825fcb4f933ebd8.zip opensim-SC-6198fe53e6b14eede432b8ce2825fcb4f933ebd8.tar.gz opensim-SC-6198fe53e6b14eede432b8ce2825fcb4f933ebd8.tar.bz2 opensim-SC-6198fe53e6b14eede432b8ce2825fcb4f933ebd8.tar.xz |
Addresses mantis #4985 -- exceptions in DataSnapshot
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/DataSnapshot/SnapshotStore.cs | 30 |
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; | |||
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Text; | 32 | using System.Text; |
33 | using System.Text.RegularExpressions; | ||
33 | using System.Xml; | 34 | using System.Xml; |
34 | using log4net; | 35 | using log4net; |
35 | using OpenSim.Region.DataSnapshot.Interfaces; | 36 | using 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", ""); |