From b23160a871fe6a28105d39c9602c35cda75efe4a Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 20 Aug 2009 21:45:49 +0100 Subject: Remove the AssetInventory server from core. It has fallen behind both upstream and the reference implementation to the point where it is no longer usable. It has no known users, and sinnce it doesn't work anymore, it is safe to assume that no one has used it in a long time. --- .../AssetInventoryServerSimplePlugins.addin.xml | 16 - .../Plugins/Simple/SimpleAssetStoragePlugin.cs | 290 ---------- .../Plugins/Simple/SimpleInventoryStoragePlugin.cs | 625 --------------------- .../Plugins/Simple/SimpleUtils.cs | 71 --- 4 files changed, 1002 deletions(-) delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs (limited to 'OpenSim/Grid/AssetInventoryServer/Plugins/Simple') diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml deleted file mode 100644 index cb6959e..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs deleted file mode 100644 index 4ec2d96..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs +++ /dev/null @@ -1,290 +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 OpenSimulator 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; -using System.Reflection; -using System.Collections.Generic; -using System.IO; -using OpenMetaverse; -using OpenSim.Framework; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple -{ - public class SimpleAssetStoragePlugin : IAssetStorageProvider - { - const string EXTENSION_NAME = "SimpleAssetStorage"; // Used in metrics reporting - const string DEFAULT_DATA_DIR = "SimpleAssets"; - const string TEMP_DATA_DIR = "SimpleAssetsTemp"; - - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - AssetInventoryServer server; - Dictionary metadataStorage; - Dictionary filenames; - - public SimpleAssetStoragePlugin() - { - } - - #region Required Interfaces - - public BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata) - { - metadata = null; - BackendResponse ret; - - if (metadataStorage.TryGetValue(assetID, out metadata)) - ret = BackendResponse.Success; - else - ret = BackendResponse.NotFound; - - server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchData(UUID assetID, out byte[] assetData) - { - assetData = null; - string filename; - BackendResponse ret; - - if (filenames.TryGetValue(assetID, out filename)) - { - try - { - assetData = File.ReadAllBytes(filename); - ret = BackendResponse.Success; - } - catch (Exception ex) - { - m_log.ErrorFormat("[SIMPLEASSETSTORAGE]: Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message); - ret = BackendResponse.Failure; - } - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); - return ret; - } - - public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset) - { - asset = new AssetBase(); - AssetMetadata metadata = asset.Metadata; - - string filename; - BackendResponse ret; - - if (metadataStorage.TryGetValue(assetID, out metadata) && - filenames.TryGetValue(assetID, out filename)) - { - try - { - asset.Data = File.ReadAllBytes(filename); - ret = BackendResponse.Success; - } - catch (Exception ex) - { - m_log.ErrorFormat("[SIMPLEASSETSTORAGE]: Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message); - ret = BackendResponse.Failure; - } - - asset.Type = (sbyte) Utils.ContentTypeToSLAssetType(metadata.ContentType); - asset.Local = false; - } - else - { - asset = null; - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); - server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (asset != null && asset.Data != null ? asset.Data.Length : 0), DateTime.Now); - return ret; - } - - public BackendResponse TryCreateAsset(AssetBase asset, out UUID assetID) - { - assetID = asset.FullID = UUID.Random(); - return TryCreateAsset(asset); - } - - public BackendResponse TryCreateAsset(AssetBase asset) - { - BackendResponse ret; - AssetMetadata metadata = asset.Metadata; - - string path; - string filename = String.Format("{0}.{1}", asset.FullID, Utils.ContentTypeToExtension(metadata.ContentType)); - - if (asset.Temporary) - path = Path.Combine(TEMP_DATA_DIR, filename); - else - path = Path.Combine(DEFAULT_DATA_DIR, filename); - - try - { - File.WriteAllBytes(path, asset.Data); - lock (filenames) filenames[asset.FullID] = path; - - // Set the creation date to right now - metadata.CreationDate = DateTime.Now; - - lock (metadataStorage) - metadataStorage[asset.FullID] = metadata; - - ret = BackendResponse.Success; - } - catch (Exception ex) - { - m_log.ErrorFormat("[SIMPLEASSETSTORAGE]: Failed writing data for asset {0} to {1}: {2}", asset.FullID, filename, ex.Message); - ret = BackendResponse.Failure; - } - - server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, asset.FullID, asset.Data.Length, DateTime.Now); - return ret; - } - - public int ForEach(Action action, int start, int count) - { - int rowCount = 0; - - //lock (metadataStorage) - //{ - // foreach (Metadata metadata in metadataStorage.Values) - // { - // action(metadata); - // ++rowCount; - // } - //} - - return rowCount; - } - - #endregion Required Interfaces - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - this.server = server; - - metadataStorage = new Dictionary(); - filenames = new Dictionary(); - - LoadFiles(DEFAULT_DATA_DIR, false); - LoadFiles(TEMP_DATA_DIR, true); - - m_log.InfoFormat("[SIMPLEASSETSTORAGE]: Initialized the store index with metadata for {0} assets", - metadataStorage.Count); - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[SIMPLEASSETSTORAGE]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - WipeTemporary(); - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "SimpleAssetStorage"; } - } - - #endregion IPlugin implementation - - public void WipeTemporary() - { - if (Directory.Exists(TEMP_DATA_DIR)) - { - try { Directory.Delete(TEMP_DATA_DIR); } - catch (Exception ex) { m_log.Error("[SIMPLEASSETSTORAGE]: " + ex.Message); } - } - } - - void LoadFiles(string folder, bool temporary) - { - // Try to create the directory if it doesn't already exist - if (!Directory.Exists(folder)) - { - try { Directory.CreateDirectory(folder); } - catch (Exception ex) - { - m_log.Warn("[SIMPLEASSETSTORAGE]: " + ex.Message); - return; - } - } - - lock (metadataStorage) - { - try - { - string[] assets = Directory.GetFiles(folder); - - for (int i = 0; i < assets.Length; i++) - { - string filename = assets[i]; - byte[] data = File.ReadAllBytes(filename); - - AssetMetadata metadata = new AssetMetadata(); - metadata.CreationDate = File.GetCreationTime(filename); - metadata.Description = String.Empty; - metadata.FullID = SimpleUtils.ParseUUIDFromFilename(filename); - metadata.Name = SimpleUtils.ParseNameFromFilename(filename); - metadata.SHA1 = OpenMetaverse.Utils.SHA1(data); - metadata.Temporary = false; - metadata.ContentType = Utils.ExtensionToContentType(Path.GetExtension(filename).TrimStart('.')); - - // Store the loaded data - metadataStorage[metadata.FullID] = metadata; - filenames[metadata.FullID] = filename; - } - } - catch (Exception ex) - { - m_log.Warn("[SIMPLEASSETSTORAGE]: " + ex.Message); - } - } - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs deleted file mode 100644 index 4010818..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs +++ /dev/null @@ -1,625 +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 OpenSimulator 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; -using System.Reflection; -using System.Collections.Generic; -using System.IO; -using System.Text; -using OpenMetaverse; -using OpenSim.Framework; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple -{ - public class SimpleInventoryStoragePlugin : IInventoryStorageProvider - { - const string EXTENSION_NAME = "SimpleInventoryStorage"; // Used for metrics reporting - const string DEFAULT_INVENTORY_DIR = "SimpleInventory"; - - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - AssetInventoryServer server; - Dictionary inventories = new Dictionary(); - Dictionary> activeGestures = new Dictionary>(); - Utils.InventoryItemSerializer itemSerializer = new Utils.InventoryItemSerializer(); - Utils.InventoryFolderSerializer folderSerializer = new Utils.InventoryFolderSerializer(); - - public SimpleInventoryStoragePlugin() - { - } - - #region Required Interfaces - - public BackendResponse TryFetchItem(Uri owner, UUID itemID, out InventoryItemBase item) - { - item = null; - BackendResponse ret; - - InventoryCollection collection; - if (inventories.TryGetValue(owner, out collection) && collection.Items.TryGetValue(itemID, out item)) - ret = BackendResponse.Success; - else - ret = BackendResponse.NotFound; - - server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchFolder(Uri owner, UUID folderID, out InventoryFolderWithChildren folder) - { - folder = null; - BackendResponse ret; - - InventoryCollection collection; - if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder)) - ret = BackendResponse.Success; - else - ret = BackendResponse.NotFound; - - server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents) - { - contents = null; - BackendResponse ret; - - InventoryCollection collection; - InventoryFolderWithChildren folder; - - if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder)) - { - contents = new InventoryCollection(); - contents.UserID = collection.UserID; - contents.Folders = new Dictionary(); - contents.Items = new Dictionary(); - - foreach (InventoryNodeBase invBase in folder.Children.Values) - { - if (invBase is InventoryItemBase) - { - InventoryItemBase invItem = invBase as InventoryItemBase; - contents.Items.Add(invItem.ID, invItem); - } - else - { - InventoryFolderWithChildren invFolder = invBase as InventoryFolderWithChildren; - contents.Folders.Add(invFolder.ID, invFolder); - } - } - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryFetchFolderContents(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchFolderList(Uri owner, out List folders) - { - folders = null; - BackendResponse ret; - - InventoryCollection collection; - if (inventories.TryGetValue(owner, out collection)) - { - folders = new List(collection.Folders.Values); - return BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryFetchFolderList(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory) - { - inventory = null; - BackendResponse ret; - - if (inventories.TryGetValue(owner, out inventory)) - ret = BackendResponse.Success; - else - ret = BackendResponse.NotFound; - - server.MetricsProvider.LogInventoryFetchInventory(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchActiveGestures(Uri owner, out List gestures) - { - gestures = null; - BackendResponse ret; - - if (activeGestures.TryGetValue(owner, out gestures)) - ret = BackendResponse.Success; - else - ret = BackendResponse.NotFound; - - server.MetricsProvider.LogInventoryFetchActiveGestures(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; - } - - public BackendResponse TryCreateItem(Uri owner, InventoryItemBase item) - { - BackendResponse ret; - - InventoryCollection collection; - if (inventories.TryGetValue(owner, out collection)) - { - // Delete this item first if it already exists - InventoryItemBase oldItem; - if (collection.Items.TryGetValue(item.ID, out oldItem)) - TryDeleteItem(owner, item.ID); - - try - { - // Create the file - SaveItem(item); - - // Add the item to the collection - lock (collection) collection.Items[item.ID] = item; - - // Add the item to its parent folder - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(item.Folder, out parent)) - lock (parent.Children) parent.Children.Add(item.ID, item); - - // Add active gestures to our list - if (item.InvType == (int)InventoryType.Gesture && item.Flags == 1) - { - lock (activeGestures) - activeGestures[owner].Add(item); - } - - ret = BackendResponse.Success; - } - catch (Exception ex) - { - m_log.Error("[SIMPLEINVENTORYSTORAGE]: " + ex.Message); - ret = BackendResponse.Failure; - } - } - else - { - return BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, false, DateTime.Now); - return ret; - } - - public BackendResponse TryCreateFolder(Uri owner, InventoryFolderWithChildren folder) - { - BackendResponse ret; - - InventoryCollection collection; - if (inventories.TryGetValue(owner, out collection)) - { - // Delete this folder first if it already exists - InventoryFolderWithChildren oldFolder; - if (collection.Folders.TryGetValue(folder.ID, out oldFolder)) - TryDeleteFolder(owner, folder.ID); - - try - { - // Create the file - SaveFolder(folder); - - // Add the folder to the collection - lock (collection) collection.Folders[folder.ID] = folder; - - // Add the folder to its parent folder - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(folder.ParentID, out parent)) - lock (parent.Children) parent.Children.Add(folder.ID, folder); - - ret = BackendResponse.Success; - } - catch (Exception ex) - { - m_log.Error("[SIMPLEINVENTORYSTORAGE]: " + ex.Message); - ret = BackendResponse.Failure; - } - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, true, DateTime.Now); - return ret; - } - - public BackendResponse TryCreateInventory(Uri owner, InventoryFolderWithChildren rootFolder) - { - BackendResponse ret; - - lock (inventories) - { - if (!inventories.ContainsKey(owner)) - { - InventoryCollection collection = new InventoryCollection(); - collection.UserID = rootFolder.Owner; - collection.Folders = new Dictionary(); - collection.Folders.Add(rootFolder.ID, rootFolder); - collection.Items = new Dictionary(); - - inventories.Add(owner, collection); - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.Failure; - } - } - - if (ret == BackendResponse.Success) - { - string path = Path.Combine(DEFAULT_INVENTORY_DIR, rootFolder.Owner.ToString()); - try - { - // Create the directory for this agent - Directory.CreateDirectory(path); - - // Create an index.txt containing the UUID and URI for this agent - string[] index = new string[] { rootFolder.Owner.ToString(), owner.ToString() }; - File.WriteAllLines(Path.Combine(path, "index.txt"), index); - - // Create the root folder file - SaveFolder(rootFolder); - } - catch (Exception ex) - { - m_log.Error("[SIMPLEINVENTORYSTORAGE]: " + ex.Message); - ret = BackendResponse.Failure; - } - } - - server.MetricsProvider.LogInventoryCreateInventory(EXTENSION_NAME, ret, DateTime.Now); - return ret; - } - - public BackendResponse TryDeleteItem(Uri owner, UUID itemID) - { - BackendResponse ret; - - InventoryCollection collection; - InventoryItemBase item; - if (inventories.TryGetValue(owner, out collection) && collection.Items.TryGetValue(itemID, out item)) - { - // Remove the item from its parent folder - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(item.Folder, out parent)) - lock (parent.Children) parent.Children.Remove(itemID); - - // Remove the item from the collection - lock (collection) collection.Items.Remove(itemID); - - // Remove from the active gestures list if applicable - if (item.InvType == (int)InventoryType.Gesture) - { - lock (activeGestures) - { - for (int i = 0; i < activeGestures[owner].Count; i++) - { - if (activeGestures[owner][i].ID == itemID) - { - activeGestures[owner].RemoveAt(i); - break; - } - } - } - } - - // Delete the file. We don't know exactly what the file name is, - // so search for it - string path = PathFromURI(owner); - string[] matches = Directory.GetFiles(path, String.Format("*{0}.item", itemID), SearchOption.TopDirectoryOnly); - foreach (string match in matches) - { - try { File.Delete(match); } - catch (Exception ex) { m_log.ErrorFormat("[SIMPLEINVENTORYSTORAGE]: Failed to delete file {0}: {1}", match, ex.Message); } - } - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); - return ret; - } - - public BackendResponse TryDeleteFolder(Uri owner, UUID folderID) - { - BackendResponse ret; - - InventoryCollection collection; - InventoryFolderWithChildren folder; - if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder)) - { - // Remove the folder from its parent folder - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(folder.ParentID, out parent)) - lock (parent.Children) parent.Children.Remove(folderID); - - // Remove the folder from the collection - lock (collection) collection.Items.Remove(folderID); - - // Delete the folder file. We don't know exactly what the file name is, - // so search for it - string path = PathFromURI(owner); - string[] matches = Directory.GetFiles(path, String.Format("*{0}.folder", folderID), SearchOption.TopDirectoryOnly); - foreach (string match in matches) - { - try { File.Delete(match); } - catch (Exception ex) { m_log.ErrorFormat("[SIMPLEINVENTORYSTORAGE]: Failed to delete folder file {0}: {1}", match, ex.Message); } - } - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); - return ret; - } - - public BackendResponse TryPurgeFolder(Uri owner, UUID folderID) - { - BackendResponse ret; - - InventoryCollection collection; - InventoryFolderWithChildren folder; - if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder)) - { - // Delete all of the folder children - foreach (InventoryNodeBase obj in new List(folder.Children.Values)) - { - if (obj is InventoryItemBase) - { - TryDeleteItem(owner, (obj as InventoryItemBase).ID); - } - else - { - InventoryFolderWithChildren childFolder = obj as InventoryFolderWithChildren; - TryPurgeFolder(owner, childFolder.ID); - TryDeleteFolder(owner, childFolder.ID); - } - } - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryPurgeFolder(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); - return ret; - } - - #endregion Required Interfaces - - void SaveItem(InventoryItemBase item) - { - string filename = String.Format("{0}-{1}.item", SanitizeFilename(item.Name), item.ID); - - string path = Path.Combine(DEFAULT_INVENTORY_DIR, item.Owner.ToString()); - path = Path.Combine(path, filename); - - using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write)) - { - itemSerializer.Serialize(stream, item); - stream.Flush(); - } - } - - void SaveFolder(InventoryFolderWithChildren folder) - { - string filename = String.Format("{0}-{1}.folder", SanitizeFilename(folder.Name), folder.ID); - - string path = Path.Combine(DEFAULT_INVENTORY_DIR, folder.Owner.ToString()); - path = Path.Combine(path, filename); - - using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write)) - { - folderSerializer.Serialize(stream, folder); - stream.Flush(); - } - } - - string SanitizeFilename(string filename) - { - string output = filename; - - if (output.Length > 64) - output = output.Substring(0, 64); - - foreach (char i in Path.GetInvalidFileNameChars()) - output = output.Replace(i, '_'); - - return output; - } - - static string PathFromURI(Uri uri) - { - byte[] hash = OpenMetaverse.Utils.SHA1(Encoding.UTF8.GetBytes(uri.ToString())); - StringBuilder digest = new StringBuilder(40); - - // Convert the hash to a hex string - foreach (byte b in hash) - digest.AppendFormat(OpenMetaverse.Utils.EnUsCulture, "{0:x2}", b); - - return Path.Combine(DEFAULT_INVENTORY_DIR, digest.ToString()); - } - - void LoadFiles(string folder) - { - // Try to create the directory if it doesn't already exist - if (!Directory.Exists(folder)) - { - try { Directory.CreateDirectory(folder); } - catch (Exception ex) - { - m_log.Warn("[SIMPLEINVENTORYSTORAGE]: " + ex.Message); - return; - } - } - - try - { - string[] agentFolders = Directory.GetDirectories(DEFAULT_INVENTORY_DIR); - - for (int i = 0; i < agentFolders.Length; i++) - { - string foldername = agentFolders[i]; - string indexPath = Path.Combine(foldername, "index.txt"); - UUID ownerID = UUID.Zero; - Uri owner = null; - - try - { - string[] index = File.ReadAllLines(indexPath); - ownerID = UUID.Parse(index[0]); - owner = new Uri(index[1]); - } - catch (Exception ex) - { - m_log.WarnFormat("[SIMPLEINVENTORYSTORAGE]: Failed loading the index file {0}: {1}", indexPath, ex.Message); - } - - if (ownerID != UUID.Zero && owner != null) - { - // Initialize the active gestures list for this agent - activeGestures.Add(owner, new List()); - - InventoryCollection collection = new InventoryCollection(); - collection.UserID = ownerID; - - // Load all of the folders for this agent - string[] folders = Directory.GetFiles(foldername, "*.folder", SearchOption.TopDirectoryOnly); - collection.Folders = new Dictionary(folders.Length); - - for (int j = 0; j < folders.Length; j++) - { - InventoryFolderWithChildren invFolder = (InventoryFolderWithChildren)folderSerializer.Deserialize( - new FileStream(folders[j], FileMode.Open, FileAccess.Read)); - collection.Folders[invFolder.ID] = invFolder; - } - - // Iterate over the folders collection, adding children to their parents - foreach (InventoryFolderWithChildren invFolder in collection.Folders.Values) - { - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(invFolder.ParentID, out parent)) - parent.Children[invFolder.ID] = invFolder; - } - - // Load all of the items for this agent - string[] files = Directory.GetFiles(foldername, "*.item", SearchOption.TopDirectoryOnly); - collection.Items = new Dictionary(files.Length); - - for (int j = 0; j < files.Length; j++) - { - InventoryItemBase invItem = (InventoryItemBase)itemSerializer.Deserialize( - new FileStream(files[j], FileMode.Open, FileAccess.Read)); - collection.Items[invItem.ID] = invItem; - - // Add items to their parent folders - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(invItem.Folder, out parent)) - parent.Children[invItem.ID] = invItem; - - // Add active gestures to our list - if (invItem.InvType == (int)InventoryType.Gesture && invItem.Flags != 0) - activeGestures[owner].Add(invItem); - } - - inventories.Add(owner, collection); - } - } - } - catch (Exception ex) - { - m_log.ErrorFormat("[SIMPLEINVENTORYSTORAGE]: Failed loading inventory from {0}: {1}", folder, ex.Message); - } - } - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - this.server = server; - - LoadFiles(DEFAULT_INVENTORY_DIR); - - m_log.InfoFormat("[SIMPLEINVENTORYSTORAGE]: Initialized the inventory index with data for {0} avatars", - inventories.Count); - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[SIMPLEINVENTORYSTORAGE]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "SimpleInventoryStorage"; } - } - - #endregion IPlugin implementation - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs deleted file mode 100644 index 0d5c53a..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs +++ /dev/null @@ -1,71 +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 OpenSimulator 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; -using System.IO; -using OpenMetaverse; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple -{ - public static class SimpleUtils - { - public static string ParseNameFromFilename(string filename) - { - filename = Path.GetFileName(filename); - - int dot = filename.LastIndexOf('.'); - int firstDash = filename.IndexOf('-'); - - if (dot - 37 > 0 && firstDash > 0) - return filename.Substring(0, firstDash); - else - return String.Empty; - } - - public static UUID ParseUUIDFromFilename(string filename) - { - int dot = filename.LastIndexOf('.'); - - if (dot > 35) - { - // Grab the last 36 characters of the filename - string uuidString = filename.Substring(dot - 36, 36); - UUID uuid; - UUID.TryParse(uuidString, out uuid); - return uuid; - } - else - { - UUID uuid; - if (UUID.TryParse(Path.GetFileName(filename), out uuid)) - return uuid; - else - return UUID.Zero; - } - } - } -} -- cgit v1.1