Make load/save iar slightly better in the face of io failures by always attempting to close the streams

0.6.8-post-fixes
Justin Clark-Casey (justincc) 2009-11-24 18:27:31 +00:00
parent c083ab6824
commit f605d59136
2 changed files with 77 additions and 63 deletions

View File

@ -121,45 +121,51 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
byte[] data;
TarArchiveReader.TarEntryType entryType;
while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
try
{
if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
{
if (LoadAsset(filePath, data))
successfulAssetRestores++;
else
failedAssetRestores++;
if ((successfulAssetRestores) % 50 == 0)
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Loaded {0} assets...",
successfulAssetRestores);
}
else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH))
{
InventoryFolderBase foundFolder
= ReplicateArchivePathToUserInventory(
filePath, TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType,
rootDestinationFolder, foldersCreated, nodesLoaded);
if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
{
InventoryItemBase item = LoadItem(data, foundFolder);
if (item != null)
if (LoadAsset(filePath, data))
successfulAssetRestores++;
else
failedAssetRestores++;
if ((successfulAssetRestores) % 50 == 0)
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Loaded {0} assets...",
successfulAssetRestores);
}
else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH))
{
InventoryFolderBase foundFolder
= ReplicateArchivePathToUserInventory(
filePath, TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType,
rootDestinationFolder, foldersCreated, nodesLoaded);
if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
{
successfulItemRestores++;
// If we're loading an item directly into the given destination folder then we need to record
// it separately from any loaded root folders
if (rootDestinationFolder == foundFolder)
nodesLoaded.Add(item);
InventoryItemBase item = LoadItem(data, foundFolder);
if (item != null)
{
successfulItemRestores++;
// If we're loading an item directly into the given destination folder then we need to record
// it separately from any loaded root folders
if (rootDestinationFolder == foundFolder)
nodesLoaded.Add(item);
}
}
}
}
}
archive.Close();
finally
{
archive.Close();
}
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Successfully loaded {0} assets with {1} failures",

View File

@ -117,19 +117,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
protected void ReceivedAllAssets(ICollection<UUID> assetsFoundUuids, ICollection<UUID> assetsNotFoundUuids)
{
// We're almost done. Just need to write out the control file now
m_archiveWriter.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p1ControlFile());
m_log.InfoFormat("[ARCHIVER]: Added control file to archive.");
{
Exception reportedException = null;
bool succeeded = true;
try
{
{
// We're almost done. Just need to write out the control file now
m_archiveWriter.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p1ControlFile());
m_log.InfoFormat("[ARCHIVER]: Added control file to archive.");
m_archiveWriter.Close();
}
catch (IOException e)
catch (Exception e)
{
m_saveStream.Close();
reportedException = e;
@ -261,39 +261,47 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
//inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
}
m_archiveWriter = new TarArchiveWriter(m_saveStream);
if (inventoryFolder != null)
{
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}",
inventoryFolder.Name, inventoryFolder.ID, m_invPath);
//recurse through all dirs getting dirs and files
SaveInvFolder(inventoryFolder, ArchiveConstants.INVENTORY_PATH, !foundStar);
}
else if (inventoryItem != null)
{
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Found item {0} {1} at {2}",
inventoryItem.Name, inventoryItem.ID, m_invPath);
SaveInvItem(inventoryItem, ArchiveConstants.INVENTORY_PATH);
}
else
if (null == inventoryFolder && null == inventoryItem)
{
// We couldn't find the path indicated
m_saveStream.Close();
string errorMessage = string.Format("Aborted save. Could not find inventory path {0}", m_invPath);
m_log.ErrorFormat("[INVENTORY ARCHIVER]: {0}", errorMessage);
m_module.TriggerInventoryArchiveSaved(
m_id, false, m_userInfo, m_invPath, m_saveStream,
new Exception(errorMessage));
return;
return;
}
m_archiveWriter = new TarArchiveWriter(m_saveStream);
// Don't put all this profile information into the archive right now.
//SaveUsers();
try
{
if (inventoryFolder != null)
{
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}",
inventoryFolder.Name, inventoryFolder.ID, m_invPath);
//recurse through all dirs getting dirs and files
SaveInvFolder(inventoryFolder, ArchiveConstants.INVENTORY_PATH, !foundStar);
}
else if (inventoryItem != null)
{
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Found item {0} {1} at {2}",
inventoryItem.Name, inventoryItem.ID, m_invPath);
SaveInvItem(inventoryItem, ArchiveConstants.INVENTORY_PATH);
}
// Don't put all this profile information into the archive right now.
//SaveUsers();
}
catch (Exception)
{
m_archiveWriter.Close();
throw;
}
new AssetsRequest(
new AssetsArchiver(m_archiveWriter), m_assetUuids.Keys,