aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs16
1 files changed, 12 insertions, 4 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index 817e0d4..1dc40bc 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -323,13 +323,13 @@ namespace Flotsam.RegionModules.AssetCache
323 string filename = GetFileName(id); 323 string filename = GetFileName(id);
324 if (File.Exists(filename)) 324 if (File.Exists(filename))
325 { 325 {
326 FileStream stream = null;
326 try 327 try
327 { 328 {
328 FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read); 329 stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
329 BinaryFormatter bformatter = new BinaryFormatter(); 330 BinaryFormatter bformatter = new BinaryFormatter();
330 331
331 asset = (AssetBase)bformatter.Deserialize(stream); 332 asset = (AssetBase)bformatter.Deserialize(stream);
332 stream.Close();
333 333
334 UpdateMemoryCache(id, asset); 334 UpdateMemoryCache(id, asset);
335 335
@@ -349,6 +349,11 @@ namespace Flotsam.RegionModules.AssetCache
349 { 349 {
350 LogException(e); 350 LogException(e);
351 } 351 }
352 finally
353 {
354 if (stream != null)
355 stream.Close();
356 }
352 } 357 }
353 358
354 359
@@ -493,6 +498,7 @@ namespace Flotsam.RegionModules.AssetCache
493 498
494 private void WriteFileCache(string filename, AssetBase asset) 499 private void WriteFileCache(string filename, AssetBase asset)
495 { 500 {
501 Stream stream = null;
496 try 502 try
497 { 503 {
498 // Make sure the target cache directory exists 504 // Make sure the target cache directory exists
@@ -505,10 +511,9 @@ namespace Flotsam.RegionModules.AssetCache
505 // Write file first to a temp name, so that it doesn't look 511 // Write file first to a temp name, so that it doesn't look
506 // like it's already cached while it's still writing. 512 // like it's already cached while it's still writing.
507 string tempname = Path.Combine(directory, Path.GetRandomFileName()); 513 string tempname = Path.Combine(directory, Path.GetRandomFileName());
508 Stream stream = File.Open(tempname, FileMode.Create); 514 stream = File.Open(tempname, FileMode.Create);
509 BinaryFormatter bformatter = new BinaryFormatter(); 515 BinaryFormatter bformatter = new BinaryFormatter();
510 bformatter.Serialize(stream, asset); 516 bformatter.Serialize(stream, asset);
511 stream.Close();
512 517
513 // Now that it's written, rename it so that it can be found. 518 // Now that it's written, rename it so that it can be found.
514 File.Move(tempname, filename); 519 File.Move(tempname, filename);
@@ -522,6 +527,9 @@ namespace Flotsam.RegionModules.AssetCache
522 } 527 }
523 finally 528 finally
524 { 529 {
530 if (stream != null)
531 stream.Close();
532
525 // Even if the write fails with an exception, we need to make sure 533 // Even if the write fails with an exception, we need to make sure
526 // that we release the lock on that file, otherwise it'll never get 534 // that we release the lock on that file, otherwise it'll never get
527 // cached 535 // cached