diff options
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLXAssetData.cs')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLXAssetData.cs | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs index 748578b..bb03871 100644 --- a/OpenSim/Data/MySQL/MySQLXAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs | |||
@@ -26,9 +26,11 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | ||
29 | using System.Data; | 30 | using System.Data; |
31 | using System.IO; | ||
32 | using System.IO.Compression; | ||
30 | using System.Reflection; | 33 | using System.Reflection; |
31 | using System.Collections.Generic; | ||
32 | using System.Text; | 34 | using System.Text; |
33 | using log4net; | 35 | using log4net; |
34 | using MySql.Data.MySqlClient; | 36 | using MySql.Data.MySqlClient; |
@@ -139,6 +141,18 @@ namespace OpenSim.Data.MySQL | |||
139 | 141 | ||
140 | asset.Temporary = Convert.ToBoolean(dbReader["temporary"]); | 142 | asset.Temporary = Convert.ToBoolean(dbReader["temporary"]); |
141 | asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); | 143 | asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); |
144 | |||
145 | using (GZipStream decompressionStream = new GZipStream(new MemoryStream(asset.Data), CompressionMode.Decompress)) | ||
146 | { | ||
147 | MemoryStream outputStream = new MemoryStream(); | ||
148 | WebUtil.CopyTo(decompressionStream, outputStream, int.MaxValue); | ||
149 | // int compressedLength = asset.Data.Length; | ||
150 | asset.Data = outputStream.ToArray(); | ||
151 | |||
152 | // m_log.DebugFormat( | ||
153 | // "[XASSET DB]: Decompressed {0} {1} to {2} bytes from {3}", | ||
154 | // asset.ID, asset.Name, asset.Data.Length, compressedLength); | ||
155 | } | ||
142 | } | 156 | } |
143 | } | 157 | } |
144 | } | 158 | } |
@@ -181,9 +195,24 @@ namespace OpenSim.Data.MySQL | |||
181 | assetDescription = asset.Description.Substring(0, 64); | 195 | assetDescription = asset.Description.Substring(0, 64); |
182 | m_log.Warn("[XASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add"); | 196 | m_log.Warn("[XASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add"); |
183 | } | 197 | } |
184 | 198 | ||
185 | string hash = Util.SHA1Hash(asset.Data); | 199 | byte[] compressedData; |
186 | 200 | MemoryStream outputStream = new MemoryStream(); | |
201 | |||
202 | using (GZipStream compressionStream = new GZipStream(outputStream, CompressionMode.Compress, false)) | ||
203 | { | ||
204 | Console.WriteLine(WebUtil.CopyTo(new MemoryStream(asset.Data), compressionStream, int.MaxValue)); | ||
205 | // We have to close the compression stream in order to make sure it writes everything out to the underlying memory output stream. | ||
206 | compressionStream.Close(); | ||
207 | compressedData = outputStream.ToArray(); | ||
208 | } | ||
209 | |||
210 | string hash = Util.SHA1Hash(compressedData); | ||
211 | |||
212 | // m_log.DebugFormat( | ||
213 | // "[XASSET DB]: Compressed data size for {0} {1}, hash {2} is {3}", | ||
214 | // asset.ID, asset.Name, hash, compressedData.Length); | ||
215 | |||
187 | try | 216 | try |
188 | { | 217 | { |
189 | using (MySqlCommand cmd = | 218 | using (MySqlCommand cmd = |
@@ -205,7 +234,6 @@ namespace OpenSim.Data.MySQL | |||
205 | cmd.Parameters.AddWithValue("?access_time", now); | 234 | cmd.Parameters.AddWithValue("?access_time", now); |
206 | cmd.Parameters.AddWithValue("?creator_id", asset.Metadata.CreatorID); | 235 | cmd.Parameters.AddWithValue("?creator_id", asset.Metadata.CreatorID); |
207 | cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags); | 236 | cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags); |
208 | cmd.Parameters.AddWithValue("?data", asset.Data); | ||
209 | cmd.ExecuteNonQuery(); | 237 | cmd.ExecuteNonQuery(); |
210 | } | 238 | } |
211 | } | 239 | } |
@@ -229,7 +257,7 @@ namespace OpenSim.Data.MySQL | |||
229 | dbcon)) | 257 | dbcon)) |
230 | { | 258 | { |
231 | cmd.Parameters.AddWithValue("?hash", hash); | 259 | cmd.Parameters.AddWithValue("?hash", hash); |
232 | cmd.Parameters.AddWithValue("?data", asset.Data); | 260 | cmd.Parameters.AddWithValue("?data", compressedData); |
233 | cmd.ExecuteNonQuery(); | 261 | cmd.ExecuteNonQuery(); |
234 | } | 262 | } |
235 | } | 263 | } |
@@ -422,16 +450,19 @@ namespace OpenSim.Data.MySQL | |||
422 | 450 | ||
423 | public override bool Delete(string id) | 451 | public override bool Delete(string id) |
424 | { | 452 | { |
453 | // m_log.DebugFormat("[XASSETS DB]: Deleting asset {0}", id); | ||
454 | |||
425 | lock (m_dbLock) | 455 | lock (m_dbLock) |
426 | { | 456 | { |
427 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | 457 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
428 | { | 458 | { |
429 | dbcon.Open(); | 459 | dbcon.Open(); |
430 | MySqlCommand cmd = new MySqlCommand("delete from xassetsmeta where id=?id", dbcon); | ||
431 | cmd.Parameters.AddWithValue("?id", id); | ||
432 | cmd.ExecuteNonQuery(); | ||
433 | 460 | ||
434 | cmd.Dispose(); | 461 | using (MySqlCommand cmd = new MySqlCommand("delete from xassetsmeta where id=?id", dbcon)) |
462 | { | ||
463 | cmd.Parameters.AddWithValue("?id", id); | ||
464 | cmd.ExecuteNonQuery(); | ||
465 | } | ||
435 | 466 | ||
436 | // TODO: How do we deal with data from deleted assets? Probably not easily reapable unless we | 467 | // TODO: How do we deal with data from deleted assets? Probably not easily reapable unless we |
437 | // keep a reference count (?) | 468 | // keep a reference count (?) |