From 1a2518d19bb447f4d3821cb71e32e712cc99d9c0 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 5 Aug 2011 19:57:47 +0100 Subject: Instead of moving the file to its final place when FlotsamCache writes to disk, copy it instead. This is to eliminate IOException where two threads compete to cache the same file. --- OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index da39202..0c700e3 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -600,7 +600,13 @@ namespace Flotsam.RegionModules.AssetCache stream.Close(); // Now that it's written, rename it so that it can be found. - File.Move(tempname, filename); + // We're doing this as a file copy operation so that if two threads are competing to cache this asset, + // then both suceed instead of one failing when it tries to move the file to a final filename that + // already exists. + // This assumes that the file copy operation is atomic. Assuming this holds, then copying also works + // if another simulator is using the same cache directory. + File.Copy(tempname, filename, true); + File.Delete(tempname); if (m_LogLevel >= 2) m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Cache Stored :: {0}", asset.ID); @@ -635,7 +641,6 @@ namespace Flotsam.RegionModules.AssetCache } #endif } - } } -- cgit v1.1