From 7b2977d625d46718fe39051c778c477022153cc1 Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Thu, 12 Mar 2009 06:04:17 +0000 Subject: 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 --- .../Archiver/InventoryArchiveConstants.cs | 113 ------------------- .../Archiver/InventoryArchiveReadRequest.cs | 92 +++++++-------- .../Archiver/InventoryArchiveWriteRequest.cs | 94 ++++++++-------- .../Archiver/Tests/InventoryArchiverTests.cs | 76 ++++++------- .../CoreModules/World/Archiver/ArchiveConstants.cs | 123 --------------------- .../CoreModules/World/Archiver/AssetsDearchiver.cs | 1 + 6 files changed, 132 insertions(+), 367 deletions(-) delete mode 100644 OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveConstants.cs delete mode 100644 OpenSim/Region/CoreModules/World/Archiver/ArchiveConstants.cs (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveConstants.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveConstants.cs deleted file mode 100644 index e2bce16..0000000 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveConstants.cs +++ /dev/null @@ -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 -{ - /// - /// Constants for the inventory archiving module - /// - public class InventoryArchiveConstants - { - /// - /// Path for the inventory data - /// - public static readonly string INVENTORY_PATH = "inventory/"; - - /// - /// Path for the assets held in an archive - /// - public static readonly string ASSETS_PATH = "assets/"; - - /// - /// The character the separates the uuid from extension information in an archived asset filename - /// - public static readonly string ASSET_EXTENSION_SEPARATOR = "_"; - - /// - /// Used to separate components in an inventory node name - /// - public static readonly string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__"; - - /// - /// Extensions used for asset types in the archive - /// - public static readonly IDictionary ASSET_TYPE_TO_EXTENSION = new Dictionary(); - public static readonly IDictionary EXTENSION_TO_ASSET_TYPE = new Dictionary(); - - 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; - } - } -} diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index 5de8adc..d794f00 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs @@ -51,32 +51,32 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver private CachedUserInfo m_userInfo; private string m_invPath; - + /// /// The stream from which the inventory archive will be loaded. /// 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 nodesLoaded = new List(); - + 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 foldersCreated = new Dictionary(); @@ -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(); // 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); diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index 71c4740..364dc28 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs @@ -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 assetUuids = new Dictionary(); - + private InventoryArchiverModule m_module; private CachedUserInfo m_userInfo; private string m_invPath; - + /// /// The stream to which the inventory archive will be saved. /// private Stream m_saveStream; - + /// /// Constructor - /// + /// public InventoryArchiveWriteRequest( InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, string savePath) : this( module, userInfo, - invPath, + invPath, new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress)) { } - + /// /// Constructor - /// + /// 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 childFolders = inventoryFolder.RequestListOfFolderImpls(); - List items = inventoryFolder.RequestListOfItems(); - + List items = inventoryFolder.RequestListOfItems(); + /* Dictionary identicalFolderNames = new Dictionary(); - + 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(); diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index ef7f93f..ea72f08 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs @@ -53,31 +53,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests lock (this) { Monitor.PulseAll(this); - } + } } - + /// /// Test saving a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet). /// [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. + } } } diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveConstants.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveConstants.cs deleted file mode 100644 index f5f1fdb..0000000 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveConstants.cs +++ /dev/null @@ -1,123 +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.World.Archiver -{ - /// - /// Constants for the archiving module - /// - public class ArchiveConstants - { - /// - /// The location of the archive control file - /// - public static readonly string CONTROL_FILE_PATH = "archive.xml"; - - /// - /// Path for the assets held in an archive - /// - public static readonly string ASSETS_PATH = "assets/"; - - /// - /// Path for the prims file - /// - public static readonly string OBJECTS_PATH = "objects/"; - - /// - /// Path for terrains. Technically these may be assets, but I think it's quite nice to split them out. - /// - public static readonly string TERRAINS_PATH = "terrains/"; - - /// - /// Path for region settings. - /// - public static readonly string SETTINGS_PATH = "settings/"; - - /// - /// The character the separates the uuid from extension information in an archived asset filename - /// - public static readonly string ASSET_EXTENSION_SEPARATOR = "_"; - - /// - /// Extensions used for asset types in the archive - /// - public static readonly IDictionary ASSET_TYPE_TO_EXTENSION = new Dictionary(); - public static readonly IDictionary EXTENSION_TO_ASSET_TYPE = new Dictionary(); - - static ArchiveConstants() - { - 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; - } - } -} diff --git a/OpenSim/Region/CoreModules/World/Archiver/AssetsDearchiver.cs b/OpenSim/Region/CoreModules/World/Archiver/AssetsDearchiver.cs index cb267d7..67562a9 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/AssetsDearchiver.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/AssetsDearchiver.cs @@ -34,6 +34,7 @@ using System.Xml; using log4net; using OpenMetaverse; using OpenSim.Framework; +using OpenSim.Framework.Archive; namespace OpenSim.Region.CoreModules.World.Archiver { -- cgit v1.1