From fe890554fbf47cafda2a41e04b400d971f1242ad Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 4 Jun 2011 01:37:01 +0100
Subject: insert an InventoryArchiveUtils.FindItemsByPath() to return multiple
items rather than just the first one
---
.../Inventory/Archiver/InventoryArchiveUtils.cs | 45 ++++++++++++++++++----
.../Archiver/InventoryArchiveWriteRequest.cs | 3 --
.../Framework/Scenes/Tests/UserInventoryTests.cs | 3 ++
3 files changed, 40 insertions(+), 11 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs
index dc665c1..e7fb43a 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs
@@ -149,14 +149,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
///
/// Find an item given a PATH_DELIMITOR delimited path starting from the user's root 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.
- ///
+ ///
///
///
/// Inventory service to query
@@ -178,7 +179,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
return FindItemByPath(inventoryService, rootFolder, path);
}
-
+
///
/// Find an item given a PATH_DELIMITOR delimited path starting from this folder.
///
@@ -190,7 +191,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
///
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
///
- ///
+ ///
/// Inventory service to query
/// The folder from which the path starts
/// The path to the required item.
@@ -198,6 +199,35 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
public static InventoryItemBase FindItemByPath(
IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
{
+ List foundItems = FindItemsByPath(inventoryService, startFolder, path);
+
+ if (foundItems.Count != 0)
+ return foundItems[0];
+ else
+ return null;
+ }
+
+ ///
+ /// Find items that match a given PATH_DELIMITOR delimited path starting from this folder.
+ ///
+ ///
+ /// This method does not handle paths that contain multiple delimiters
+ ///
+ /// 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.
+ ///
+ ///
+ /// Inventory service to query
+ /// The folder from which the path starts
+ /// The path to the required item.
+ /// The items that were found with this path. An empty list if no items were found.
+ public static List FindItemsByPath(
+ IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
+ {
+ List foundItems = new List();
+
// If the path isn't just / then trim any starting extraneous slashes
path = path.TrimStart(new char[] { PATH_DELIMITER });
@@ -221,7 +251,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
// m_log.DebugFormat("[INVENTORY ARCHIVE UTILS]: Inspecting item {0} {1}", item.Name, item.ID);
if (item.Name == components[0])
- return item;
+ foundItems.Add(item);
}
}
else
@@ -233,12 +263,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
foreach (InventoryFolderBase folder in contents.Folders)
{
if (folder.Name == components[0])
- return FindItemByPath(inventoryService, folder, components[1]);
+ foundItems.AddRange(FindItemsByPath(inventoryService, folder, components[1]));
}
}
- // We didn't find an item or intermediate folder with the given name
- return null;
+ return foundItems;
}
///
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
index c34a0ec..c2ad079 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
@@ -255,10 +255,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
// The path may point to an item instead
if (inventoryFolder == null)
- {
inventoryItem = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, rootFolder, m_invPath);
- //inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
- }
if (null == inventoryFolder && null == inventoryItem)
{
diff --git a/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs
index bacf7c1..83f0686 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs
@@ -69,6 +69,9 @@ namespace OpenSim.Region.Framework.Tests
= UserInventoryHelpers.GetInventoryItem(scene.InventoryService, user2.PrincipalID, "Objects/item1");
Assert.That(retrievedItem1, Is.Not.Null);
+
+ // Try giving back the freshly received item
+ //scene.GiveInventoryItem(user1.PrincipalID, user2.PrincipalID, retrievedItem1.ID);
}
[Test]
--
cgit v1.1