* Simplify CreateFolder() by folding previous special root case into FindFolder()
parent
27a7391d6b
commit
0f716e3ac4
|
@ -239,6 +239,7 @@ namespace OpenSim.Framework.Communications.Cache
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
InventoryFolderImpl folder = RootFolder.FindFolder(folderInfo.ParentID);
|
InventoryFolderImpl folder = RootFolder.FindFolder(folderInfo.ParentID);
|
||||||
|
|
||||||
lock (folder.SubFolders)
|
lock (folder.SubFolders)
|
||||||
{
|
{
|
||||||
if (folder != null)
|
if (folder != null)
|
||||||
|
@ -323,72 +324,40 @@ namespace OpenSim.Framework.Communications.Cache
|
||||||
|
|
||||||
if (HasInventory)
|
if (HasInventory)
|
||||||
{
|
{
|
||||||
if (RootFolder.ID == parentID)
|
InventoryFolderImpl parentFolder = RootFolder.FindFolder(parentID);
|
||||||
|
|
||||||
|
if (null == parentFolder)
|
||||||
{
|
{
|
||||||
InventoryFolderImpl createdFolder = RootFolder.CreateNewSubFolder(folderID, folderName, folderType);
|
m_log.WarnFormat(
|
||||||
|
"[AGENT INVENTORY]: Tried to create folder {0} {1} but the parent {2} does not exist",
|
||||||
|
folderName, folderID, parentID);
|
||||||
|
|
||||||
if (createdFolder != null)
|
return false;
|
||||||
{
|
}
|
||||||
InventoryFolderBase createdBaseFolder = new InventoryFolderBase();
|
|
||||||
createdBaseFolder.Owner = createdFolder.Owner;
|
|
||||||
createdBaseFolder.ID = createdFolder.ID;
|
|
||||||
createdBaseFolder.Name = createdFolder.Name;
|
|
||||||
createdBaseFolder.ParentID = createdFolder.ParentID;
|
|
||||||
createdBaseFolder.Type = createdFolder.Type;
|
|
||||||
createdBaseFolder.Version = createdFolder.Version;
|
|
||||||
|
|
||||||
m_commsManager.InventoryService.AddFolder(createdBaseFolder);
|
InventoryFolderImpl createdFolder = parentFolder.CreateChildFolder(folderID, folderName, folderType);
|
||||||
|
|
||||||
return true;
|
if (createdFolder != null)
|
||||||
}
|
{
|
||||||
else
|
InventoryFolderBase createdBaseFolder = new InventoryFolderBase();
|
||||||
{
|
createdBaseFolder.Owner = createdFolder.Owner;
|
||||||
m_log.WarnFormat(
|
createdBaseFolder.ID = createdFolder.ID;
|
||||||
"[AGENT INVENTORY]: Tried to create folder {0} {1} but the folder already exists",
|
createdBaseFolder.Name = createdFolder.Name;
|
||||||
folderName, folderID);
|
createdBaseFolder.ParentID = createdFolder.ParentID;
|
||||||
|
createdBaseFolder.Type = createdFolder.Type;
|
||||||
|
createdBaseFolder.Version = createdFolder.Version;
|
||||||
|
|
||||||
return false;
|
m_commsManager.InventoryService.AddFolder(createdBaseFolder);
|
||||||
}
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
InventoryFolderImpl folder = RootFolder.FindFolder(parentID);
|
m_log.WarnFormat(
|
||||||
|
"[AGENT INVENTORY]: Tried to create folder {0} {1} but the folder already exists",
|
||||||
|
folderName, folderID);
|
||||||
|
|
||||||
if (folder != null)
|
return false;
|
||||||
{
|
|
||||||
InventoryFolderImpl createdFolder = folder.CreateNewSubFolder(folderID, folderName, folderType);
|
|
||||||
|
|
||||||
if (createdFolder != null)
|
|
||||||
{
|
|
||||||
InventoryFolderBase createdBaseFolder = new InventoryFolderBase();
|
|
||||||
createdBaseFolder.Owner = createdFolder.Owner;
|
|
||||||
createdBaseFolder.ID = createdFolder.ID;
|
|
||||||
createdBaseFolder.Name = createdFolder.Name;
|
|
||||||
createdBaseFolder.ParentID = createdFolder.ParentID;
|
|
||||||
createdBaseFolder.Type = createdFolder.Type;
|
|
||||||
createdBaseFolder.Version = createdFolder.Version;
|
|
||||||
|
|
||||||
m_commsManager.InventoryService.AddFolder(createdBaseFolder);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_log.WarnFormat(
|
|
||||||
"[AGENT INVENTORY]: Tried to create folder {0} {1} but the folder already exists",
|
|
||||||
folderName, folderID);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_log.WarnFormat(
|
|
||||||
"[AGENT INVENTORY]: Could not find parent folder with id {0} in order to create folder {1} {2}",
|
|
||||||
parentID, folderName, folderID);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -69,7 +69,7 @@ namespace OpenSim.Framework.Communications.Cache
|
||||||
/// <param name="folderName"></param>
|
/// <param name="folderName"></param>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
/// <returns>The newly created subfolder. Returns null if the folder already exists</returns>
|
/// <returns>The newly created subfolder. Returns null if the folder already exists</returns>
|
||||||
public InventoryFolderImpl CreateNewSubFolder(LLUUID folderID, string folderName, ushort type)
|
public InventoryFolderImpl CreateChildFolder(LLUUID folderID, string folderName, ushort type)
|
||||||
{
|
{
|
||||||
lock (SubFolders)
|
lock (SubFolders)
|
||||||
{
|
{
|
||||||
|
@ -82,6 +82,7 @@ namespace OpenSim.Framework.Communications.Cache
|
||||||
subFold.ParentID = this.ID;
|
subFold.ParentID = this.ID;
|
||||||
subFold.Owner = Owner;
|
subFold.Owner = Owner;
|
||||||
SubFolders.Add(subFold.ID, subFold);
|
SubFolders.Add(subFold.ID, subFold);
|
||||||
|
|
||||||
return subFold;
|
return subFold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +136,7 @@ namespace OpenSim.Framework.Communications.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete an item from the folder.
|
/// Deletes an item if it exists in this folder or any children
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="folderID"></param>
|
/// <param name="folderID"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
@ -157,6 +158,7 @@ namespace OpenSim.Framework.Communications.Cache
|
||||||
foreach (InventoryFolderImpl folder in SubFolders.Values)
|
foreach (InventoryFolderImpl folder in SubFolders.Values)
|
||||||
{
|
{
|
||||||
found = folder.DeleteItem(itemID);
|
found = folder.DeleteItem(itemID);
|
||||||
|
|
||||||
if (found == true)
|
if (found == true)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
@ -168,37 +170,35 @@ namespace OpenSim.Framework.Communications.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the folder requested if it exists as a descendent of this folder
|
/// Returns the folder requested if it is this folder or is a descendent of this folder. The search is depth
|
||||||
|
/// first.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The requested folder if it exists, null if it does not.</returns>
|
/// <returns>The requested folder if it exists, null if it does not.</returns>
|
||||||
public InventoryFolderImpl FindFolder(LLUUID folderID)
|
public InventoryFolderImpl FindFolder(LLUUID folderID)
|
||||||
{
|
{
|
||||||
InventoryFolderImpl returnFolder = null;
|
if (folderID == ID)
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
lock (SubFolders)
|
lock (SubFolders)
|
||||||
{
|
{
|
||||||
if (SubFolders.ContainsKey(folderID))
|
foreach (InventoryFolderImpl folder in SubFolders.Values)
|
||||||
{
|
{
|
||||||
returnFolder = SubFolders[folderID];
|
InventoryFolderImpl returnFolder = folder.FindFolder(folderID);
|
||||||
}
|
|
||||||
else
|
if (returnFolder != null)
|
||||||
{
|
|
||||||
foreach (InventoryFolderImpl folder in SubFolders.Values)
|
|
||||||
{
|
{
|
||||||
returnFolder = folder.FindFolder(folderID);
|
return returnFolder;
|
||||||
if (returnFolder != null)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnFolder;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the list of items in this folder
|
/// Return the list of child items in this folder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<InventoryItemBase> RequestListOfItems()
|
public List<InventoryItemBase> RequestListOfItems()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue