diff options
author | Melanie | 2009-10-05 10:17:23 +0100 |
---|---|---|
committer | Melanie | 2009-10-05 10:17:23 +0100 |
commit | 0744292b479446eb1ebec828afafacc0189709ca (patch) | |
tree | 3c43b5f425aff61d3625b75b7aef35ce5062ae56 /OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | |
parent | Merge branch 'master' into vehicles (diff) | |
parent | Make the asset connector async Get overload return false if the asset (diff) | |
download | opensim-SC_OLD-0744292b479446eb1ebec828afafacc0189709ca.zip opensim-SC_OLD-0744292b479446eb1ebec828afafacc0189709ca.tar.gz opensim-SC_OLD-0744292b479446eb1ebec828afafacc0189709ca.tar.bz2 opensim-SC_OLD-0744292b479446eb1ebec828afafacc0189709ca.tar.xz |
Merge branch 'master' into vehicles
Diffstat (limited to 'OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index 817e0d4..c0bb70c 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,19 +498,20 @@ 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; | ||
502 | // Make sure the target cache directory exists | ||
503 | string directory = Path.GetDirectoryName(filename); | ||
504 | // Write file first to a temp name, so that it doesn't look | ||
505 | // like it's already cached while it's still writing. | ||
506 | string tempname = Path.Combine(directory, Path.GetRandomFileName()); | ||
496 | try | 507 | try |
497 | { | 508 | { |
498 | // Make sure the target cache directory exists | ||
499 | string directory = Path.GetDirectoryName(filename); | ||
500 | if (!Directory.Exists(directory)) | 509 | if (!Directory.Exists(directory)) |
501 | { | 510 | { |
502 | Directory.CreateDirectory(directory); | 511 | Directory.CreateDirectory(directory); |
503 | } | 512 | } |
504 | 513 | ||
505 | // Write file first to a temp name, so that it doesn't look | 514 | stream = File.Open(tempname, FileMode.Create); |
506 | // like it's already cached while it's still writing. | ||
507 | string tempname = Path.Combine(directory, Path.GetRandomFileName()); | ||
508 | Stream 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(); | 517 | stream.Close(); |
@@ -522,6 +528,9 @@ namespace Flotsam.RegionModules.AssetCache | |||
522 | } | 528 | } |
523 | finally | 529 | finally |
524 | { | 530 | { |
531 | if (stream != null) | ||
532 | stream.Close(); | ||
533 | |||
525 | // Even if the write fails with an exception, we need to make sure | 534 | // 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 | 535 | // that we release the lock on that file, otherwise it'll never get |
527 | // cached | 536 | // cached |