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
integration
Justin Clark-Casey (justincc) 2012-08-25 02:00:17 +01:00
parent f8a89a79eb
commit a0d178b284
1 changed files with 49 additions and 16 deletions

View File

@ -229,10 +229,28 @@ namespace OpenSim.Services.InventoryService
public virtual InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) public virtual InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
{ {
// m_log.DebugFormat("[XINVENTORY SERVICE]: Getting folder type {0} for user {1}", type, principalID); // 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( XInventoryFolder[] folders = m_Database.GetFolders(
new string[] { "agentID", "type"}, new string[] { "agentID", "parentFolderID", "type"},
new string[] { principalID.ToString(), ((int)type).ToString() }); new string[] { rootFolder.Owner.ToString(), rootFolder.ID.ToString(), ((int)type).ToString() });
if (folders.Length == 0) if (folders.Length == 0)
{ {
@ -308,23 +326,38 @@ namespace OpenSim.Services.InventoryService
if (check != null) if (check != null)
return false; return false;
if (folder.Type == (short)AssetType.Folder if (folder.Type != (short)AssetType.Folder || folder.Type != (short)AssetType.Unknown)
|| folder.Type == (short)AssetType.Unknown
|| folder.Type == (short)AssetType.OutfitFolder
|| folder.Type == (short)AssetType.CallingCard
|| GetFolderForType(folder.Owner, (AssetType)(folder.Type)) == null)
{ {
XInventoryFolder xFolder = ConvertFromOpenSim(folder); InventoryFolderBase rootFolder = GetRootFolder(folder.Owner);
return m_Database.StoreFolder(xFolder);
} if (rootFolder == null)
else {
{ m_log.WarnFormat(
m_log.WarnFormat( "[XINVENTORY]: Found no root folder for {0} in AddFolder() when looking for {1}",
"[XINVENTORY]: Folder of type {0} already exists when tried to add {1} to {2} for {3}", folder.Owner, folder.Type);
folder.Type, folder.Name, folder.ParentID, folder.Owner);
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) public virtual bool UpdateFolder(InventoryFolderBase folder)