diff options
author | Justin Clark-Casey (justincc) | 2010-08-27 22:53:02 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-08-27 22:53:02 +0100 |
commit | b4278510f2244c46dc91568998ffe53a74fc5314 (patch) | |
tree | dae93b72ed613b119b748413fa8bf11218ddb69d /OpenSim/Region/DataSnapshot/SnapshotStore.cs | |
parent | refactor: Make IAR tests set up standard iar for loading (diff) | |
parent | Merge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC_OLD-b4278510f2244c46dc91568998ffe53a74fc5314.zip opensim-SC_OLD-b4278510f2244c46dc91568998ffe53a74fc5314.tar.gz opensim-SC_OLD-b4278510f2244c46dc91568998ffe53a74fc5314.tar.bz2 opensim-SC_OLD-b4278510f2244c46dc91568998ffe53a74fc5314.tar.xz |
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/DataSnapshot/SnapshotStore.cs | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/OpenSim/Region/DataSnapshot/SnapshotStore.cs b/OpenSim/Region/DataSnapshot/SnapshotStore.cs index 70cb205..aa3d2ff 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; |
@@ -98,13 +99,21 @@ namespace OpenSim.Region.DataSnapshot | |||
98 | { | 99 | { |
99 | String path = DataFileNameFragment(provider.GetParentScene, provider.Name); | 100 | String path = DataFileNameFragment(provider.GetParentScene, provider.Name); |
100 | 101 | ||
101 | using (XmlTextWriter snapXWriter = new XmlTextWriter(path, Encoding.Default)) | 102 | try |
102 | { | 103 | { |
103 | snapXWriter.Formatting = Formatting.Indented; | 104 | using (XmlTextWriter snapXWriter = new XmlTextWriter(path, Encoding.Default)) |
104 | snapXWriter.WriteStartDocument(); | 105 | { |
105 | data.WriteTo(snapXWriter); | 106 | snapXWriter.Formatting = Formatting.Indented; |
106 | snapXWriter.WriteEndDocument(); | 107 | snapXWriter.WriteStartDocument(); |
108 | data.WriteTo(snapXWriter); | ||
109 | snapXWriter.WriteEndDocument(); | ||
110 | } | ||
111 | } | ||
112 | catch (Exception e) | ||
113 | { | ||
114 | m_log.WarnFormat("[DATASNAPSHOT]: Exception on writing to file {0}: {1}", path, e.Message); | ||
107 | } | 115 | } |
116 | |||
108 | } | 117 | } |
109 | 118 | ||
110 | //mark provider as not stale, parent scene as stale | 119 | //mark provider as not stale, parent scene as stale |
@@ -185,12 +194,19 @@ namespace OpenSim.Region.DataSnapshot | |||
185 | //save snapshot | 194 | //save snapshot |
186 | String path = DataFileNameScene(scene); | 195 | String path = DataFileNameScene(scene); |
187 | 196 | ||
188 | using (XmlTextWriter snapXWriter = new XmlTextWriter(path, Encoding.Default)) | 197 | try |
198 | { | ||
199 | using (XmlTextWriter snapXWriter = new XmlTextWriter(path, Encoding.Default)) | ||
200 | { | ||
201 | snapXWriter.Formatting = Formatting.Indented; | ||
202 | snapXWriter.WriteStartDocument(); | ||
203 | regionElement.WriteTo(snapXWriter); | ||
204 | snapXWriter.WriteEndDocument(); | ||
205 | } | ||
206 | } | ||
207 | catch (Exception e) | ||
189 | { | 208 | { |
190 | snapXWriter.Formatting = Formatting.Indented; | 209 | m_log.WarnFormat("[DATASNAPSHOT]: Exception on writing to file {0}: {1}", path, e.Message); |
191 | snapXWriter.WriteStartDocument(); | ||
192 | regionElement.WriteTo(snapXWriter); | ||
193 | snapXWriter.WriteEndDocument(); | ||
194 | } | 210 | } |
195 | 211 | ||
196 | m_scenes[scene] = false; | 212 | m_scenes[scene] = false; |
@@ -206,15 +222,23 @@ namespace OpenSim.Region.DataSnapshot | |||
206 | #region Helpers | 222 | #region Helpers |
207 | private string DataFileNameFragment(Scene scene, String fragmentName) | 223 | private string DataFileNameFragment(Scene scene, String fragmentName) |
208 | { | 224 | { |
209 | return Path.Combine(m_directory, Path.ChangeExtension(scene.RegionInfo.RegionName + "_" + fragmentName, "xml")); | 225 | return Path.Combine(m_directory, Path.ChangeExtension(Sanitize(scene.RegionInfo.RegionName + "_" + fragmentName), "xml")); |
210 | } | 226 | } |
211 | 227 | ||
212 | private string DataFileNameScene(Scene scene) | 228 | private string DataFileNameScene(Scene scene) |
213 | { | 229 | { |
214 | return Path.Combine(m_directory, Path.ChangeExtension(scene.RegionInfo.RegionName, "xml")); | 230 | return Path.Combine(m_directory, Path.ChangeExtension(Sanitize(scene.RegionInfo.RegionName), "xml")); |
215 | //return (m_snapsDir + Path.DirectorySeparatorChar + scene.RegionInfo.RegionName + ".xml"); | 231 | //return (m_snapsDir + Path.DirectorySeparatorChar + scene.RegionInfo.RegionName + ".xml"); |
216 | } | 232 | } |
217 | 233 | ||
234 | private static string Sanitize(string name) | ||
235 | { | ||
236 | string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars())); | ||
237 | string invalidReStr = string.Format(@"[{0}]", invalidChars); | ||
238 | string newname = Regex.Replace(name, invalidReStr, "_"); | ||
239 | return newname.Replace('.', '_'); | ||
240 | } | ||
241 | |||
218 | private XmlNode MakeRegionNode(Scene scene, XmlDocument basedoc) | 242 | private XmlNode MakeRegionNode(Scene scene, XmlDocument basedoc) |
219 | { | 243 | { |
220 | XmlNode docElement = basedoc.CreateNode(XmlNodeType.Element, "region", ""); | 244 | XmlNode docElement = basedoc.CreateNode(XmlNodeType.Element, "region", ""); |