diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs index ee3fc55f59..96853f0526 100644 --- a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs +++ b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs @@ -108,7 +108,7 @@ namespace OpenSim.Framework.Communications.Cache } /// - /// Returns the item if it exists in this folder or any of this folder's subfolders? + /// Returns the item if it exists in this folder or in any of this folder's descendant folders /// /// /// null if the item is not found @@ -197,7 +197,7 @@ namespace OpenSim.Framework.Communications.Cache } /// - /// Find a folder given a PATH_DELIMITOR delimited path. + /// Find a folder given a PATH_DELIMITOR delimited path starting from this folder /// /// This method does not handle paths that contain multiple delimitors /// @@ -208,9 +208,8 @@ namespace OpenSim.Framework.Communications.Cache /// /// /// The path to the required folder. It this is empty then this folder itself is returned. - /// If a folder for the given path is not found, then null is returned. /// - /// + /// null if the folder is not found public InventoryFolderImpl FindFolderByPath(string path) { if (path == string.Empty) @@ -234,6 +233,52 @@ namespace OpenSim.Framework.Communications.Cache // We didn't find a folder with the given name return null; } + + /// + /// Find an item given a PATH_DELIMITOR delimited path starting from this folder. + /// + /// This method does not handle paths that contain multiple delimitors + /// + /// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some + /// XPath like expression + /// + /// FIXME: Delimitors which occur in names themselves are not currently escapable. + /// + /// + /// The path to the required item. + /// + /// null if the item is not found + public InventoryItemBase FindItemByPath(string path) + { + int delimitorIndex = path.IndexOf(PATH_DELIMITER); + string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); + + if (components.Length == 1) + { + lock (Items) + { + foreach (InventoryItemBase item in Items.Values) + { + if (item.Name == components[0]) + return item; + } + } + } + else + { + lock (SubFolders) + { + foreach (InventoryFolderImpl folder in SubFolders.Values) + { + if (folder.Name == components[0]) + return folder.FindItemByPath(components[1]); + } + } + } + + // We didn't find an item or intermediate folder with the given name + return null; + } /// /// Return a copy of the list of child items in this folder @@ -256,7 +301,7 @@ namespace OpenSim.Framework.Communications.Cache } /// - /// Return a copy of the list of immediate child folders in this folder. + /// Return a copy of the list of child folders in this folder. /// public List RequestListOfFolders() { diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 0d471d8e75..828abcb8a4 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -698,27 +698,37 @@ namespace OpenSim } InventoryFolderImpl inventoryFolder = null; + //InventoryItemBase inventoryItem = null; if (userInfo.HasReceivedInventory) { - if (invPath == InventoryFolderImpl.PATH_DELIMITER) + // Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl + // itself (possibly at a small loss in efficiency). + string[] components + = invPath.Split(new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries); + invPath = String.Empty; + foreach (string c in components) + { + invPath += c + InventoryFolderImpl.PATH_DELIMITER; + } + + invPath = invPath.Remove(invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER)); + + // Annoyingly Split actually returns the original string if the input string consists only of delimiters + // Therefore if we still start with a / after the split, then we need the root folder + if (invPath.StartsWith(InventoryFolderImpl.PATH_DELIMITER)) { inventoryFolder = userInfo.RootFolder; } else - { - // Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl - // itself (possibly at a small loss in efficiency). - string[] components - = invPath.Split(new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries); - invPath = String.Empty; - foreach (string c in components) - { - invPath += c + InventoryFolderImpl.PATH_DELIMITER; - } + { + inventoryFolder = userInfo.RootFolder.FindFolderByPath(invPath); + } - inventoryFolder = userInfo.RootFolder.FindFolderByPath(invPath); - } +// if (inventoryFolder == null) +// { +// +// } } else {