aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs')
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs46
1 files changed, 32 insertions, 14 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index 187f090..610e279 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -474,6 +474,8 @@ namespace OpenSim.Region.CoreModules.Asset
474 { 474 {
475 using (FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) 475 using (FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
476 { 476 {
477 if (stream.Length == 0) // Empty file will trigger exception below
478 return null;
477 BinaryFormatter bformatter = new BinaryFormatter(); 479 BinaryFormatter bformatter = new BinaryFormatter();
478 480
479 asset = (AssetBase)bformatter.Deserialize(stream); 481 asset = (AssetBase)bformatter.Deserialize(stream);
@@ -531,15 +533,26 @@ namespace OpenSim.Region.CoreModules.Asset
531 return found; 533 return found;
532 } 534 }
533 535
536 // For IAssetService
534 public AssetBase Get(string id) 537 public AssetBase Get(string id)
535 { 538 {
539 AssetBase asset;
540 Get(id, out asset);
541 return asset;
542 }
543
544 public bool Get(string id, out AssetBase asset)
545 {
546 asset = null;
547
536 m_Requests++; 548 m_Requests++;
537 549
538 object dummy; 550 object dummy;
539 if (m_negativeCache.TryGetValue(id, out dummy)) 551 if (m_negativeCache.TryGetValue(id, out dummy))
540 return null; 552 {
553 return false;
554 }
541 555
542 AssetBase asset = null;
543 asset = GetFromWeakReference(id); 556 asset = GetFromWeakReference(id);
544 if (asset != null && m_updateFileTimeOnCacheHit) 557 if (asset != null && m_updateFileTimeOnCacheHit)
545 { 558 {
@@ -578,13 +591,7 @@ namespace OpenSim.Region.CoreModules.Asset
578 GenerateCacheHitReport().ForEach(l => m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0}", l)); 591 GenerateCacheHitReport().ForEach(l => m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0}", l));
579 } 592 }
580 593
581 if(asset == null) 594 return true;
582 {
583
584
585 }
586
587 return asset;
588 } 595 }
589 596
590 public bool Check(string id) 597 public bool Check(string id)
@@ -599,7 +606,9 @@ namespace OpenSim.Region.CoreModules.Asset
599 606
600 public AssetBase GetCached(string id) 607 public AssetBase GetCached(string id)
601 { 608 {
602 return Get(id); 609 AssetBase asset;
610 Get(id, out asset);
611 return asset;
603 } 612 }
604 613
605 public void Expire(string id) 614 public void Expire(string id)
@@ -797,6 +806,9 @@ namespace OpenSim.Region.CoreModules.Asset
797 806
798 return; 807 return;
799 } 808 }
809 catch (UnauthorizedAccessException e)
810 {
811 }
800 finally 812 finally
801 { 813 {
802 if (stream != null) 814 if (stream != null)
@@ -1227,19 +1239,23 @@ namespace OpenSim.Region.CoreModules.Asset
1227 1239
1228 public AssetMetadata GetMetadata(string id) 1240 public AssetMetadata GetMetadata(string id)
1229 { 1241 {
1230 AssetBase asset = Get(id); 1242 AssetBase asset;
1243 Get(id, out asset);
1231 return asset.Metadata; 1244 return asset.Metadata;
1232 } 1245 }
1233 1246
1234 public byte[] GetData(string id) 1247 public byte[] GetData(string id)
1235 { 1248 {
1236 AssetBase asset = Get(id); 1249 AssetBase asset;
1250 Get(id, out asset);
1237 return asset.Data; 1251 return asset.Data;
1238 } 1252 }
1239 1253
1240 public bool Get(string id, object sender, AssetRetrieved handler) 1254 public bool Get(string id, object sender, AssetRetrieved handler)
1241 { 1255 {
1242 AssetBase asset = Get(id); 1256 AssetBase asset;
1257 if (!Get(id, out asset))
1258 return false;
1243 handler(id, sender, asset); 1259 handler(id, sender, asset);
1244 return true; 1260 return true;
1245 } 1261 }
@@ -1270,7 +1286,9 @@ namespace OpenSim.Region.CoreModules.Asset
1270 1286
1271 public bool UpdateContent(string id, byte[] data) 1287 public bool UpdateContent(string id, byte[] data)
1272 { 1288 {
1273 AssetBase asset = Get(id); 1289 AssetBase asset;
1290 if (!Get(id, out asset))
1291 return false;
1274 asset.Data = data; 1292 asset.Data = data;
1275 Cache(asset); 1293 Cache(asset);
1276 return true; 1294 return true;