From 30c36a3960b5a307a2315b8acf79474186779ad8 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 25 Aug 2012 02:00:17 +0100 Subject: [PATCH] Following on from f8a89a79, do not allow more than one 'type' folder (e.g. calling cards) to be created in the base "My Inventory" user folder. This is to accomodate situations where viewers will create more than one 'type' subfolder (e.g. calling cards) But at the same time to prevent multiple such 'system' folders (those in the base "My Inventory" user folder). This also makes GetFolderForType() only return a folder in the base "My Inventory" folder, if such a type folder exists --- .../InventoryService/XInventoryService.cs | 65 ++++++++++++++----- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/OpenSim/Services/InventoryService/XInventoryService.cs b/OpenSim/Services/InventoryService/XInventoryService.cs index e10e0be82c..deacd5a4b4 100644 --- a/OpenSim/Services/InventoryService/XInventoryService.cs +++ b/OpenSim/Services/InventoryService/XInventoryService.cs @@ -229,10 +229,28 @@ namespace OpenSim.Services.InventoryService public virtual InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) { // m_log.DebugFormat("[XINVENTORY SERVICE]: Getting folder type {0} for user {1}", type, principalID); + + InventoryFolderBase rootFolder = GetRootFolder(principalID); + + if (rootFolder == null) + { + m_log.WarnFormat( + "[XINVENTORY]: Found no root folder for {0} in GetFolderForType() when looking for {1}", + principalID, type); + + return null; + } + + return GetSystemFolderForType(rootFolder, type); + } + + private InventoryFolderBase GetSystemFolderForType(InventoryFolderBase rootFolder, AssetType type) + { +// m_log.DebugFormat("[XINVENTORY SERVICE]: Getting folder type {0} for user {1}", type, principalID); XInventoryFolder[] folders = m_Database.GetFolders( - new string[] { "agentID", "type"}, - new string[] { principalID.ToString(), ((int)type).ToString() }); + new string[] { "agentID", "parentFolderID", "type"}, + new string[] { rootFolder.Owner.ToString(), rootFolder.ID.ToString(), ((int)type).ToString() }); if (folders.Length == 0) { @@ -308,23 +326,38 @@ namespace OpenSim.Services.InventoryService if (check != null) return false; - if (folder.Type == (short)AssetType.Folder - || folder.Type == (short)AssetType.Unknown - || folder.Type == (short)AssetType.OutfitFolder - || folder.Type == (short)AssetType.CallingCard - || GetFolderForType(folder.Owner, (AssetType)(folder.Type)) == null) + if (folder.Type != (short)AssetType.Folder || folder.Type != (short)AssetType.Unknown) { - XInventoryFolder xFolder = ConvertFromOpenSim(folder); - return m_Database.StoreFolder(xFolder); - } - else - { - m_log.WarnFormat( - "[XINVENTORY]: Folder of type {0} already exists when tried to add {1} to {2} for {3}", - folder.Type, folder.Name, folder.ParentID, folder.Owner); + InventoryFolderBase rootFolder = GetRootFolder(folder.Owner); + + if (rootFolder == null) + { + m_log.WarnFormat( + "[XINVENTORY]: Found no root folder for {0} in AddFolder() when looking for {1}", + folder.Owner, folder.Type); + + return false; + } + + // Check we're not trying to add this as a system folder. + if (folder.ParentID == rootFolder.ID) + { + InventoryFolderBase existingSystemFolder + = GetSystemFolderForType(rootFolder, (AssetType)folder.Type); + + if (existingSystemFolder != null) + { + m_log.WarnFormat( + "[XINVENTORY]: System folder of type {0} already exists when tried to add {1} to {2} for {3}", + folder.Type, folder.Name, folder.ParentID, folder.Owner); + + return false; + } + } } - return false; + XInventoryFolder xFolder = ConvertFromOpenSim(folder); + return m_Database.StoreFolder(xFolder); } public virtual bool UpdateFolder(InventoryFolderBase folder)