aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-01-18 00:12:12 +0000
committerJustin Clark-Casey (justincc)2014-01-18 00:12:12 +0000
commit97fbb8ed45e4827ea7473bac2b792499a9284c3e (patch)
tree33298403ef06fa25828f418248350c8d8ee975cc /OpenSim
parentelminate unnecessary asset != null check in FlotsamAssetCache.UpdateFileCache() (diff)
downloadopensim-SC-97fbb8ed45e4827ea7473bac2b792499a9284c3e.zip
opensim-SC-97fbb8ed45e4827ea7473bac2b792499a9284c3e.tar.gz
opensim-SC-97fbb8ed45e4827ea7473bac2b792499a9284c3e.tar.bz2
opensim-SC-97fbb8ed45e4827ea7473bac2b792499a9284c3e.tar.xz
Elminate some copy/paste in FlotsamAssetCache.CheckFromFileCache() and use using() construct to ensure filestream is always closed
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs43
1 files changed, 10 insertions, 33 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index e1aa460..169412e 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -352,7 +352,6 @@ namespace OpenSim.Region.CoreModules.Asset
352 return false; 352 return false;
353 } 353 }
354 354
355
356 /// <summary> 355 /// <summary>
357 /// Try to get an asset from the file cache. 356 /// Try to get an asset from the file cache.
358 /// </summary> 357 /// </summary>
@@ -390,15 +389,16 @@ namespace OpenSim.Region.CoreModules.Asset
390 389
391 if (File.Exists(filename)) 390 if (File.Exists(filename))
392 { 391 {
393 FileStream stream = null;
394 try 392 try
395 { 393 {
396 stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read); 394 using (FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
397 BinaryFormatter bformatter = new BinaryFormatter(); 395 {
396 BinaryFormatter bformatter = new BinaryFormatter();
398 397
399 asset = (AssetBase)bformatter.Deserialize(stream); 398 asset = (AssetBase)bformatter.Deserialize(stream);
400 399
401 m_DiskHits++; 400 m_DiskHits++;
401 }
402 } 402 }
403 catch (System.Runtime.Serialization.SerializationException e) 403 catch (System.Runtime.Serialization.SerializationException e)
404 { 404 {
@@ -417,12 +417,6 @@ namespace OpenSim.Region.CoreModules.Asset
417 m_log.WarnFormat( 417 m_log.WarnFormat(
418 "[FLOTSAM ASSET CACHE]: Failed to get file {0} for asset {1}. Exception {2} {3}", 418 "[FLOTSAM ASSET CACHE]: Failed to get file {0} for asset {1}. Exception {2} {3}",
419 filename, id, e.Message, e.StackTrace); 419 filename, id, e.Message, e.StackTrace);
420
421 }
422 finally
423 {
424 if (stream != null)
425 stream.Close();
426 } 420 }
427 } 421 }
428 422
@@ -434,36 +428,19 @@ namespace OpenSim.Region.CoreModules.Asset
434 bool found = false; 428 bool found = false;
435 429
436 string filename = GetFileName(id); 430 string filename = GetFileName(id);
431
437 if (File.Exists(filename)) 432 if (File.Exists(filename))
438 { 433 {
439 // actually check if we can open it, and so update expire
440 FileStream stream = null;
441 try 434 try
442 { 435 {
443 stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read); 436 using (FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
444 if (stream != null)
445 { 437 {
446 found = true; 438 if (stream != null)
447 stream.Close(); 439 found = true;
448 } 440 }
449
450 }
451 catch (System.Runtime.Serialization.SerializationException e)
452 {
453 found = false;
454 m_log.ErrorFormat(
455 "[FLOTSAM ASSET CACHE]: Failed to check file {0} for asset {1}. Exception {2} {3}",
456 filename, id, e.Message, e.StackTrace);
457
458 // If there was a problem deserializing the asset, the asset may
459 // either be corrupted OR was serialized under an old format
460 // {different version of AssetBase} -- we should attempt to
461 // delete it and re-cache
462 File.Delete(filename);
463 } 441 }
464 catch (Exception e) 442 catch (Exception e)
465 { 443 {
466 found = false;
467 m_log.ErrorFormat( 444 m_log.ErrorFormat(
468 "[FLOTSAM ASSET CACHE]: Failed to check file {0} for asset {1}. Exception {2} {3}", 445 "[FLOTSAM ASSET CACHE]: Failed to check file {0} for asset {1}. Exception {2} {3}",
469 filename, id, e.Message, e.StackTrace); 446 filename, id, e.Message, e.StackTrace);