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.
bulletsim
Justin Clark-Casey (justincc) 2011-08-05 19:57:47 +01:00
parent 94d496cf2b
commit 1a2518d19b
1 changed files with 7 additions and 2 deletions

View File

@ -600,7 +600,13 @@ namespace Flotsam.RegionModules.AssetCache
stream.Close(); stream.Close();
// Now that it's written, rename it so that it can be found. // 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) if (m_LogLevel >= 2)
m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Cache Stored :: {0}", asset.ID); m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Cache Stored :: {0}", asset.ID);
@ -635,7 +641,6 @@ namespace Flotsam.RegionModules.AssetCache
} }
#endif #endif
} }
} }
} }