From 0f716e3ac4d8af67fed7c23994d2c0f53d8eb2ae Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Sun, 4 May 2008 00:06:34 +0000 Subject: * Simplify CreateFolder() by folding previous special root case into FindFolder() --- .../Communications/Cache/CachedUserInfo.cs | 89 +++++++--------------- .../Communications/Cache/InventoryFolderImpl.cs | 34 ++++----- 2 files changed, 46 insertions(+), 77 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs index 6f7c4da..5b84958 100644 --- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs +++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs @@ -239,6 +239,7 @@ namespace OpenSim.Framework.Communications.Cache else { InventoryFolderImpl folder = RootFolder.FindFolder(folderInfo.ParentID); + lock (folder.SubFolders) { if (folder != null) @@ -323,72 +324,40 @@ namespace OpenSim.Framework.Communications.Cache 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); + + return false; + } + + InventoryFolderImpl createdFolder = parentFolder.CreateChildFolder(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; - } + 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 { - 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) - { - 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; - } + return false; } } else diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs index af05af3..c8cec69 100644 --- a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs +++ b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs @@ -69,7 +69,7 @@ namespace OpenSim.Framework.Communications.Cache /// /// /// The newly created subfolder. Returns null if the folder already exists - public InventoryFolderImpl CreateNewSubFolder(LLUUID folderID, string folderName, ushort type) + public InventoryFolderImpl CreateChildFolder(LLUUID folderID, string folderName, ushort type) { lock (SubFolders) { @@ -82,6 +82,7 @@ namespace OpenSim.Framework.Communications.Cache subFold.ParentID = this.ID; subFold.Owner = Owner; SubFolders.Add(subFold.ID, subFold); + return subFold; } } @@ -135,7 +136,7 @@ namespace OpenSim.Framework.Communications.Cache } /// - /// Delete an item from the folder. + /// Deletes an item if it exists in this folder or any children /// /// /// @@ -157,6 +158,7 @@ namespace OpenSim.Framework.Communications.Cache foreach (InventoryFolderImpl folder in SubFolders.Values) { found = folder.DeleteItem(itemID); + if (found == true) { break; @@ -168,37 +170,35 @@ namespace OpenSim.Framework.Communications.Cache } /// - /// 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. /// /// The requested folder if it exists, null if it does not. public InventoryFolderImpl FindFolder(LLUUID folderID) { - InventoryFolderImpl returnFolder = null; + if (folderID == ID) + { + return this; + } lock (SubFolders) { - if (SubFolders.ContainsKey(folderID)) - { - returnFolder = SubFolders[folderID]; - } - else + foreach (InventoryFolderImpl folder in SubFolders.Values) { - foreach (InventoryFolderImpl folder in SubFolders.Values) + InventoryFolderImpl returnFolder = folder.FindFolder(folderID); + + if (returnFolder != null) { - returnFolder = folder.FindFolder(folderID); - if (returnFolder != null) - { - break; - } + return returnFolder; } } } - return returnFolder; + return null; } /// - /// Return the list of items in this folder + /// Return the list of child items in this folder /// public List RequestListOfItems() { -- cgit v1.1