Move ArchiveConstants to OpenSim.Framework.Archive

- move a couple constants from InventoryArchiveConstants to
  ArchiveConstants, now only one of these is needed
- change InventoryArchiveConstants references to ArchiveConstants
- remove InventoryArchive AssetInventoryServer plugin dependency on
  OpenSim.Region.CodeModules
- trim trailing whitespace
0.6.5-rc1
Mike Mazur 2009-03-12 06:04:17 +00:00
parent f784620780
commit 7b2977d625
8 changed files with 177 additions and 282 deletions

View File

@ -28,7 +28,7 @@
using System.Collections.Generic;
using OpenMetaverse;
namespace OpenSim.Region.CoreModules.World.Archiver
namespace OpenSim.Framework.Archive
{
/// <summary>
/// Constants for the archiving module
@ -45,6 +45,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
/// </summary>
public static readonly string ASSETS_PATH = "assets/";
/// <summary>
/// Path for the inventory data
/// </summary>
public static readonly string INVENTORY_PATH = "inventory/";
/// <summary>
/// Path for the prims file
/// </summary>
@ -54,7 +59,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
/// Path for terrains. Technically these may be assets, but I think it's quite nice to split them out.
/// </summary>
public static readonly string TERRAINS_PATH = "terrains/";
/// <summary>
/// Path for region settings.
/// </summary>
@ -65,6 +70,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
/// </summary>
public static readonly string ASSET_EXTENSION_SEPARATOR = "_";
/// <summary>
/// Used to separate components in an inventory node name
/// </summary>
public static readonly string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__";
/// <summary>
/// Extensions used for asset types in the archive
/// </summary>

View File

@ -35,7 +35,6 @@ using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Archive;
using OpenSim.Framework.Servers;
using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
using log4net;
namespace OpenSim.Grid.AssetInventoryServer.Plugins
@ -146,7 +145,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
MemoryStream ms = new MemoryStream();
GZipStream gzs = new GZipStream(ms, CompressionMode.Compress, true);
TarArchiveWriter archive = new TarArchiveWriter(gzs);
WriteInventoryFolderToArchive(archive, rootFolder, InventoryArchiveConstants.INVENTORY_PATH);
WriteInventoryFolderToArchive(archive, rootFolder, ArchiveConstants.INVENTORY_PATH);
archive.Close();
@ -181,7 +180,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
private static void WriteInventoryFolderToArchive(TarArchiveWriter archive, InventoryFolderWithChildren folder, string path)
{
path += string.Format("{0}{1}{2}/", folder.Name, InventoryArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, folder.ID);
path += string.Format("{0}{1}{2}/", folder.Name, ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, folder.ID);
archive.WriteDir(path);
foreach (InventoryNodeBase inventoryNode in folder.Children.Values)

View File

@ -1,113 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.Collections.Generic;
using OpenMetaverse;
namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
/// <summary>
/// Constants for the inventory archiving module
/// </summary>
public class InventoryArchiveConstants
{
/// <summary>
/// Path for the inventory data
/// </summary>
public static readonly string INVENTORY_PATH = "inventory/";
/// <summary>
/// Path for the assets held in an archive
/// </summary>
public static readonly string ASSETS_PATH = "assets/";
/// <summary>
/// The character the separates the uuid from extension information in an archived asset filename
/// </summary>
public static readonly string ASSET_EXTENSION_SEPARATOR = "_";
/// <summary>
/// Used to separate components in an inventory node name
/// </summary>
public static readonly string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__";
/// <summary>
/// Extensions used for asset types in the archive
/// </summary>
public static readonly IDictionary<sbyte, string> ASSET_TYPE_TO_EXTENSION = new Dictionary<sbyte, string>();
public static readonly IDictionary<string, sbyte> EXTENSION_TO_ASSET_TYPE = new Dictionary<string, sbyte>();
static InventoryArchiveConstants()
{
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Animation] = ASSET_EXTENSION_SEPARATOR + "animation.bvh";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Bodypart] = ASSET_EXTENSION_SEPARATOR + "bodypart.txt";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.CallingCard] = ASSET_EXTENSION_SEPARATOR + "callingcard.txt";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Clothing] = ASSET_EXTENSION_SEPARATOR + "clothing.txt";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Folder] = ASSET_EXTENSION_SEPARATOR + "folder.txt"; // Not sure if we'll ever see this
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Gesture] = ASSET_EXTENSION_SEPARATOR + "gesture.txt";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.ImageJPEG] = ASSET_EXTENSION_SEPARATOR + "image.jpg";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.ImageTGA] = ASSET_EXTENSION_SEPARATOR + "image.tga";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Landmark] = ASSET_EXTENSION_SEPARATOR + "landmark.txt";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LostAndFoundFolder] = ASSET_EXTENSION_SEPARATOR + "lostandfoundfolder.txt"; // Not sure if we'll ever see this
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLBytecode] = ASSET_EXTENSION_SEPARATOR + "bytecode.lso";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLText] = ASSET_EXTENSION_SEPARATOR + "script.lsl";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Notecard] = ASSET_EXTENSION_SEPARATOR + "notecard.txt";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Object] = ASSET_EXTENSION_SEPARATOR + "object.xml";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.RootFolder] = ASSET_EXTENSION_SEPARATOR + "rootfolder.txt"; // Not sure if we'll ever see this
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Simstate] = ASSET_EXTENSION_SEPARATOR + "simstate.bin"; // Not sure if we'll ever see this
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SnapshotFolder] = ASSET_EXTENSION_SEPARATOR + "snapshotfolder.txt"; // Not sure if we'll ever see this
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Sound] = ASSET_EXTENSION_SEPARATOR + "sound.ogg";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV] = ASSET_EXTENSION_SEPARATOR + "sound.wav";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Texture] = ASSET_EXTENSION_SEPARATOR + "texture.jp2";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TextureTGA] = ASSET_EXTENSION_SEPARATOR + "texture.tga";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TrashFolder] = ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"; // Not sure if we'll ever see this
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "animation.bvh"] = (sbyte)AssetType.Animation;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bodypart.txt"] = (sbyte)AssetType.Bodypart;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "callingcard.txt"] = (sbyte)AssetType.CallingCard;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "clothing.txt"] = (sbyte)AssetType.Clothing;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "folder.txt"] = (sbyte)AssetType.Folder;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "gesture.txt"] = (sbyte)AssetType.Gesture;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "image.jpg"] = (sbyte)AssetType.ImageJPEG;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "image.tga"] = (sbyte)AssetType.ImageTGA;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "landmark.txt"] = (sbyte)AssetType.Landmark;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "lostandfoundfolder.txt"] = (sbyte)AssetType.LostAndFoundFolder;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bytecode.lso"] = (sbyte)AssetType.LSLBytecode;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "script.lsl"] = (sbyte)AssetType.LSLText;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "notecard.txt"] = (sbyte)AssetType.Notecard;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "object.xml"] = (sbyte)AssetType.Object;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "rootfolder.txt"] = (sbyte)AssetType.RootFolder;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "simstate.bin"] = (sbyte)AssetType.Simstate;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "snapshotfolder.txt"] = (sbyte)AssetType.SnapshotFolder;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "sound.ogg"] = (sbyte)AssetType.Sound;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "sound.wav"] = (sbyte)AssetType.SoundWAV;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.jp2"] = (sbyte)AssetType.Texture;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"] = (sbyte)AssetType.TrashFolder;
}
}
}

View File

@ -51,32 +51,32 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
private CachedUserInfo m_userInfo;
private string m_invPath;
/// <value>
/// The stream from which the inventory archive will be loaded.
/// </value>
private Stream m_loadStream;
CommunicationsManager commsManager;
public InventoryArchiveReadRequest(
CachedUserInfo userInfo, string invPath, string loadPath, CommunicationsManager commsManager)
: this(
userInfo,
invPath,
invPath,
new GZipStream(new FileStream(loadPath, FileMode.Open), CompressionMode.Decompress),
commsManager)
{
}
public InventoryArchiveReadRequest(
CachedUserInfo userInfo, string invPath, Stream loadStream, CommunicationsManager commsManager)
{
m_userInfo = userInfo;
m_invPath = invPath;
m_loadStream = loadStream;
m_loadStream = loadStream;
this.commsManager = commsManager;
}
}
protected InventoryItemBase LoadInvItem(string contents)
{
@ -157,11 +157,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
int failedAssetRestores = 0;
int successfulItemRestores = 0;
List<InventoryNodeBase> nodesLoaded = new List<InventoryNodeBase>();
if (!m_userInfo.HasReceivedInventory)
{
// If the region server has access to the user admin service (by which users are created),
// then we'll assume that it's okay to fiddle with the user's inventory even if they are not on the
// If the region server has access to the user admin service (by which users are created),
// then we'll assume that it's okay to fiddle with the user's inventory even if they are not on the
// server.
//
// FIXME: FetchInventory should probably be assumed to by async anyway, since even standalones might
@ -191,7 +191,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
archive = new TarArchiveReader(m_loadStream);
// In order to load identically named folders, we need to keep track of the folders that we have already
// created
Dictionary <string, InventoryFolderImpl> foldersCreated = new Dictionary<string, InventoryFolderImpl>();
@ -200,18 +200,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
TarArchiveReader.TarEntryType entryType;
while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
{
if (entryType == TarArchiveReader.TarEntryType.TYPE_DIRECTORY)
if (entryType == TarArchiveReader.TarEntryType.TYPE_DIRECTORY)
{
m_log.WarnFormat("[INVENTORY ARCHIVER]: Ignoring directory entry {0}", filePath);
}
else if (filePath.StartsWith(InventoryArchiveConstants.ASSETS_PATH))
}
else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
{
if (LoadAsset(filePath, data))
successfulAssetRestores++;
else
failedAssetRestores++;
}
else if (filePath.StartsWith(InventoryArchiveConstants.INVENTORY_PATH))
else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH))
{
InventoryItemBase item = LoadInvItem(m_asciiEncoding.GetString(data));
@ -219,16 +219,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
// Don't use the item ID that's in the file
item.ID = UUID.Random();
item.Creator = m_userInfo.UserProfile.ID;
item.Owner = m_userInfo.UserProfile.ID;
string fsPath = filePath.Substring(InventoryArchiveConstants.INVENTORY_PATH.Length);
string fsPath = filePath.Substring(ArchiveConstants.INVENTORY_PATH.Length);
fsPath = fsPath.Remove(fsPath.LastIndexOf("/") + 1);
string originalFsPath = fsPath;
m_log.DebugFormat("[INVENTORY ARCHIVER]: Loading to folder {0}", fsPath);
InventoryFolderImpl foundFolder = null;
while (null == foundFolder && fsPath.Length > 0)
{
@ -241,7 +241,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
// Don't include the last slash
int penultimateSlashIndex = fsPath.LastIndexOf("/", fsPath.Length - 2);
if (penultimateSlashIndex >= 0)
{
fsPath = fsPath.Remove(penultimateSlashIndex + 1);
@ -254,42 +254,42 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
fsPath = string.Empty;
foundFolder = rootDestinationFolder;
}
}
}
}
string fsPathSectionToCreate = originalFsPath.Substring(fsPath.Length);
string[] rawDirsToCreate
string[] rawDirsToCreate
= fsPathSectionToCreate.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
int i = 0;
while (i < rawDirsToCreate.Length)
{
m_log.DebugFormat("[INVENTORY ARCHIVER]: Creating folder {0}", rawDirsToCreate[i]);
int identicalNameIdentifierIndex
int identicalNameIdentifierIndex
= rawDirsToCreate[i].LastIndexOf(
InventoryArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR);
ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR);
string folderName = rawDirsToCreate[i].Remove(identicalNameIdentifierIndex);
UUID newFolderId = UUID.Random();
m_userInfo.CreateFolder(
folderName, newFolderId, (ushort)AssetType.Folder, foundFolder.ID);
foundFolder = foundFolder.GetChildFolder(newFolderId);
// Record that we have now created this folder
fsPath += rawDirsToCreate[i] + "/";
m_log.DebugFormat("[INVENTORY ARCHIVER]: Recording creation of fs path {0}", fsPath);
foldersCreated[fsPath] = foundFolder;
if (0 == i)
nodesLoaded.Add(foundFolder);
i++;
}
/*
string[] rawFolders = filePath.Split(new char[] { '/' });
string[] rawFolders = filePath.Split(new char[] { '/' });
// Find the folders that do exist along the path given
int i = 0;
bool noFolder = false;
@ -306,27 +306,27 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
else
{
noFolder = true;
}
}
}
// Create any folders that did not previously exist
while (i < rawFolders.Length)
{
m_log.DebugFormat("[INVENTORY ARCHIVER]: Creating folder {0}", rawFolders[i]);
UUID newFolderId = UUID.Random();
m_userInfo.CreateFolder(
rawFolders[i++], newFolderId, (ushort)AssetType.Folder, foundFolder.ID);
foundFolder = foundFolder.GetChildFolder(newFolderId);
}
*/
}
*/
// Reset folder ID to the one in which we want to load it
item.Folder = foundFolder.ID;
m_userInfo.AddItem(item);
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)
@ -339,7 +339,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
m_log.DebugFormat("[INVENTORY ARCHIVER]: Restored {0} assets", successfulAssetRestores);
m_log.InfoFormat("[INVENTORY ARCHIVER]: Restored {0} items", successfulItemRestores);
return nodesLoaded;
}
@ -353,14 +353,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
//IRegionSerialiser serialiser = scene.RequestModuleInterface<IRegionSerialiser>();
// Right now we're nastily obtaining the UUID from the filename
string filename = assetPath.Remove(0, InventoryArchiveConstants.ASSETS_PATH.Length);
int i = filename.LastIndexOf(InventoryArchiveConstants.ASSET_EXTENSION_SEPARATOR);
string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
int i = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR);
if (i == -1)
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: Could not find extension information in asset path {0} since it's missing the separator {1}. Skipping",
assetPath, InventoryArchiveConstants.ASSET_EXTENSION_SEPARATOR);
assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR);
return false;
}
@ -368,9 +368,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
string extension = filename.Substring(i);
string uuid = filename.Remove(filename.Length - extension.Length);
if (InventoryArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension))
if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension))
{
sbyte assetType = InventoryArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];
sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];
//m_log.DebugFormat("[INVENTORY ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType);

View File

@ -41,47 +41,47 @@ using OpenSim.Region.CoreModules.World.Archiver;
using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
{
public class InventoryArchiveWriteRequest
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected TarArchiveWriter m_archive;
protected UuidGatherer m_assetGatherer;
protected Dictionary<UUID, int> assetUuids = new Dictionary<UUID, int>();
private InventoryArchiverModule m_module;
private CachedUserInfo m_userInfo;
private string m_invPath;
/// <value>
/// The stream to which the inventory archive will be saved.
/// </value>
private Stream m_saveStream;
/// <summary>
/// Constructor
/// </summary>
/// </summary>
public InventoryArchiveWriteRequest(
InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, string savePath)
: this(
module,
userInfo,
invPath,
invPath,
new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress))
{
}
/// <summary>
/// Constructor
/// </summary>
/// </summary>
public InventoryArchiveWriteRequest(
InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, Stream saveStream)
{
m_module = module;
m_userInfo = userInfo;
m_invPath = invPath;
m_saveStream = saveStream;
m_saveStream = saveStream;
m_assetGatherer = new UuidGatherer(m_module.CommsManager.AssetCache);
}
@ -89,22 +89,22 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
AssetsArchiver assetsArchiver = new AssetsArchiver(assetsFound);
assetsArchiver.Archive(m_archive);
Exception reportedException = null;
bool succeeded = true;
try
{
m_archive.Close();
}
}
catch (IOException e)
{
m_saveStream.Close();
m_saveStream.Close();
reportedException = e;
succeeded = false;
}
m_module.TriggerInventoryArchiveSaved(succeeded, m_userInfo, m_invPath, m_saveStream, reportedException);
m_module.TriggerInventoryArchiveSaved(succeeded, m_userInfo, m_invPath, m_saveStream, reportedException);
}
protected void SaveInvItem(InventoryItemBase inventoryItem, string path)
@ -113,9 +113,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
StringWriter sw = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(sw);
writer.Formatting = Formatting.Indented;
writer.WriteStartElement("InventoryItem");
writer.WriteStartElement("Name");
writer.WriteString(inventoryItem.Name);
writer.WriteEndElement();
@ -170,7 +170,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
writer.WriteStartElement("GroupOwned");
writer.WriteString(inventoryItem.GroupOwned.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
m_archive.WriteFile(filename, sw.ToString());
@ -180,43 +180,43 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
protected void SaveInvDir(InventoryFolderImpl inventoryFolder, string path)
{
path +=
path +=
string.Format(
"{0}{1}{2}/",
"{0}{1}{2}/",
inventoryFolder.Name,
InventoryArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR,
ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR,
inventoryFolder.ID);
m_archive.WriteDir(path);
List<InventoryFolderImpl> childFolders = inventoryFolder.RequestListOfFolderImpls();
List<InventoryItemBase> items = inventoryFolder.RequestListOfItems();
List<InventoryItemBase> items = inventoryFolder.RequestListOfItems();
/*
Dictionary identicalFolderNames = new Dictionary<string, int>();
foreach (InventoryFolderImpl folder in inventories)
{
if (!identicalFolderNames.ContainsKey(folder.Name))
identicalFolderNames[folder.Name] = 0;
else
identicalFolderNames[folder.Name] = identicalFolderNames[folder.Name]++;
int folderNameNumber = identicalFolderName[folder.Name];
SaveInvDir(
folder,
folder,
string.Format(
"{0}{1}{2}/",
path, InventoryArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, folderNameNumber));
"{0}{1}{2}/",
path, ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, folderNameNumber));
}
*/
foreach (InventoryFolderImpl childFolder in childFolders)
{
SaveInvDir(childFolder, path);
}
foreach (InventoryItemBase item in items)
{
SaveInvItem(item, path);
@ -232,9 +232,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
InventoryItemBase inventoryItem = null;
if (!m_userInfo.HasReceivedInventory)
{
// If the region server has access to the user admin service (by which users are created),
// then we'll assume that it's okay to fiddle with the user's inventory even if they are not on the
{
// If the region server has access to the user admin service (by which users are created),
// then we'll assume that it's okay to fiddle with the user's inventory even if they are not on the
// server.
//
// FIXME: FetchInventory should probably be assumed to by async anyway, since even standalones might
@ -252,7 +252,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
m_userInfo.FetchInventory();
}
}
// Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl
// itself (possibly at a small loss in efficiency).
string[] components
@ -280,8 +280,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
}
m_archive = new TarArchiveWriter(m_saveStream);
m_archive = new TarArchiveWriter(m_saveStream);
if (null == inventoryFolder)
{
@ -289,16 +289,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
m_saveStream.Close();
m_module.TriggerInventoryArchiveSaved(
false, m_userInfo, m_invPath, m_saveStream,
false, m_userInfo, m_invPath, m_saveStream,
new Exception(string.Format("Could not find inventory entry at path {0}", m_invPath)));
return;
}
else
{
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Found item {0} {1} at {2}",
"[INVENTORY ARCHIVER]: Found item {0} {1} at {2}",
inventoryItem.Name, inventoryItem.ID, m_invPath);
//get and export item info
SaveInvItem(inventoryItem, m_invPath);
}
@ -306,11 +306,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
else
{
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}",
"[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}",
inventoryFolder.Name, inventoryFolder.ID, m_invPath);
//recurse through all dirs getting dirs and files
SaveInvDir(inventoryFolder, InventoryArchiveConstants.INVENTORY_PATH);
SaveInvDir(inventoryFolder, ArchiveConstants.INVENTORY_PATH);
}
new AssetsRequest(assetUuids.Keys, m_module.CommsManager.AssetCache, ReceivedAllAssets).Execute();

View File

@ -53,31 +53,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
lock (this)
{
Monitor.PulseAll(this);
}
}
}
/// <summary>
/// Test saving a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet).
/// </summary>
[Test]
public void TestSaveIarV0p1()
{
{
//log4net.Config.XmlConfigurator.Configure();
InventoryArchiverModule archiverModule = new InventoryArchiverModule();
Scene scene = SceneSetupHelpers.SetupScene();
SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
CommunicationsManager cm = scene.CommsManager;
// Create user
// Create user
string userFirstName = "Jock";
string userLastName = "Stirrup";
UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
cm.UserAdminService.AddUser(userFirstName, userLastName, string.Empty, string.Empty, 1000, 1000, userId);
CachedUserInfo userInfo = cm.UserProfileCacheService.GetUserDetails(userId);
userInfo.FetchInventory();
// Create asset
SceneObjectGroup object1;
SceneObjectPart part1;
@ -88,81 +88,81 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
Vector3 groupPosition = new Vector3(10, 20, 30);
Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
Vector3 offsetPosition = new Vector3(5, 10, 15);
part1
part1
= new SceneObjectPart(
ownerId, shape, groupPosition, rotationOffset, offsetPosition);
part1.Name = partName;
object1 = new SceneObjectGroup(part1);
}
UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
AssetBase asset1 = new AssetBase();
asset1.FullID = asset1Id;
asset1.Data = Encoding.ASCII.GetBytes(object1.ToXmlString2());
asset1.Data = Encoding.ASCII.GetBytes(object1.ToXmlString2());
cm.AssetCache.AddAsset(asset1);
// Create item
UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
InventoryItemBase item1 = new InventoryItemBase();
item1.Name = "My Little Dog";
item1.AssetID = asset1.FullID;
item1.ID = item1Id;
item1.Folder = userInfo.RootFolder.FindFolderByPath("Objects").ID;
scene.AddInventoryItem(userId, item1);
item1.Folder = userInfo.RootFolder.FindFolderByPath("Objects").ID;
scene.AddInventoryItem(userId, item1);
MemoryStream archiveWriteStream = new MemoryStream();
archiverModule.OnInventoryArchiveSaved += SaveCompleted;
archiverModule.OnInventoryArchiveSaved += SaveCompleted;
lock (this)
{
archiverModule.ArchiveInventory(userFirstName, userLastName, "Objects", archiveWriteStream);
archiverModule.ArchiveInventory(userFirstName, userLastName, "Objects", archiveWriteStream);
Monitor.Wait(this, 60000);
}
}
byte[] archive = archiveWriteStream.ToArray();
byte[] archive = archiveWriteStream.ToArray();
MemoryStream archiveReadStream = new MemoryStream(archive);
TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
InventoryFolderImpl objectsFolder = userInfo.RootFolder.FindFolderByPath("Objects");
//bool gotControlFile = false;
bool gotObject1File = false;
//bool gotObject2File = false;
string expectedObject1FilePath = string.Format(
"{0}{1}/{2}_{3}.xml",
InventoryArchiveConstants.INVENTORY_PATH,
ArchiveConstants.INVENTORY_PATH,
string.Format(
"Objects{0}{1}", InventoryArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, objectsFolder.ID),
"Objects{0}{1}", ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, objectsFolder.ID),
item1.Name,
item1Id);
/*
string expectedObject2FileName = string.Format(
"{0}_{1:000}-{2:000}-{3:000}__{4}.xml",
part2.Name,
Math.Round(part2.GroupPosition.X), Math.Round(part2.GroupPosition.Y), Math.Round(part2.GroupPosition.Z),
part2.UUID);
*/
*/
string filePath;
TarArchiveReader.TarEntryType tarEntryType;
while (tar.ReadEntry(out filePath, out tarEntryType) != null)
{
Console.WriteLine("Got {0}", filePath);
/*
if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
{
gotControlFile = true;
}
*/
if (filePath.StartsWith(InventoryArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml"))
{
if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml"))
{
//string fileName = filePath.Remove(0, "Objects/".Length);
//if (fileName.StartsWith(part1.Name))
//{
Assert.That(filePath, Is.EqualTo(expectedObject1FilePath));
@ -171,7 +171,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
//else if (fileName.StartsWith(part2.Name))
//{
// Assert.That(fileName, Is.EqualTo(expectedObject2FileName));
// gotObject2File = true;
// gotObject2File = true;
//}
}
}
@ -179,8 +179,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
//Assert.That(gotControlFile, Is.True, "No control file in archive");
Assert.That(gotObject1File, Is.True, "No item1 file in archive");
//Assert.That(gotObject2File, Is.True, "No object2 file in archive");
// TODO: Test presence of more files and contents of files.
}
// TODO: Test presence of more files and contents of files.
}
}
}

View File

@ -34,6 +34,7 @@ using System.Xml;
using log4net;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Archive;
namespace OpenSim.Region.CoreModules.World.Archiver
{

View File

@ -118,6 +118,7 @@
</Configuration>
<ReferencePath>../../../bin/</ReferencePath>
<Reference name="OpenMetaverse" />
<Reference name="System"/>
<Reference name="log4net.dll"/>
@ -865,6 +866,36 @@
</Files>
</Project>
<Project name="OpenSim.Grid.AssetInventoryServer.Plugins" path="OpenSim/Grid/AssetInventoryServer/Plugins" type="Library">
<Configuration name="Debug">
<Options>
<OutputPath>../../../../bin/</OutputPath>
</Options>
</Configuration>
<Configuration name="Release">
<Options>
<OutputPath>../../../../bin/</OutputPath>
</Options>
</Configuration>
<ReferencePath>../../../../bin/</ReferencePath>
<Reference name="System"/>
<Reference name="System.Xml"/>
<Reference name="System.Web"/>
<Reference name="OpenMetaverseTypes"/>
<Reference name="OpenMetaverse.StructuredData"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Archive"/>
<Reference name="OpenSim.Framework.Servers"/>
<Reference name="OpenSim.Grid.AssetInventoryServer" />
<Reference name="log4net"/>
<Files>
<Match pattern="*.cs" recurse="false" />
<Match path="Resources" pattern="*.addin.xml" buildAction="EmbeddedResource" recurse="true" />
</Files>
</Project>
<Project name="OpenSim.Grid.AssetInventoryServer.Plugins.Simple" path="OpenSim/Grid/AssetInventoryServer/Plugins/Simple" type="Library">
<Configuration name="Debug">
<Options>
@ -1141,39 +1172,6 @@
</Files>
</Project>
<Project name="OpenSim.Grid.AssetInventoryServer.Plugins" path="OpenSim/Grid/AssetInventoryServer/Plugins" type="Library">
<Configuration name="Debug">
<Options>
<OutputPath>../../../../bin/</OutputPath>
</Options>
</Configuration>
<Configuration name="Release">
<Options>
<OutputPath>../../../../bin/</OutputPath>
</Options>
</Configuration>
<ReferencePath>../../../../bin/</ReferencePath>
<Reference name="System"/>
<Reference name="System.Xml"/>
<Reference name="System.Web"/>
<Reference name="OpenMetaverseTypes"/>
<Reference name="OpenMetaverse.StructuredData"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Archive"/>
<Reference name="OpenSim.Framework.Servers"/>
<Reference name="OpenSim.Grid.AssetInventoryServer" />
<Reference name="log4net"/>
<!-- Needed for InventoryArchiveConstants. Hopefully it can be moved to Framework or something so we don't depend on Region DLLs. -->
<Reference name="OpenSim.Region.CoreModules"/>
<Files>
<Match pattern="*.cs" recurse="false" />
<Match path="Resources" pattern="*.addin.xml" buildAction="EmbeddedResource" recurse="true" />
</Files>
</Project>
<Project name="OpenSim.Region.CoreModules.World.Terrain.DefaultEffects" path="OpenSim/Region/CoreModules/World/Terrain/DefaultEffects" type="Library">
<Configuration name="Debug">
<Options>