diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs index 6d598d1c82..2eeb637417 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using OpenMetaverse; using OpenSim.Framework; using OpenSim.Services.Interfaces; @@ -38,6 +39,39 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver public static class InventoryArchiveUtils { public static readonly string PATH_DELIMITER = "/"; + + /// + /// Find a folder given a PATH_DELIMITER delimited path starting from a user's root folder + /// + /// + /// This method does not handle paths that contain multiple delimitors + /// + /// FIXME: We do not yet handle situations where folders 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 + /// + /// + /// User id to search + /// + /// + /// The path to the required folder. + /// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned. + /// + /// null if the folder is not found + public static InventoryFolderBase FindFolderByPath( + IInventoryService inventoryService, UUID userId, string path) + { + InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); + + if (null == rootFolder) + return null; + + return FindFolderByPath(inventoryService, rootFolder, path); + } /// /// Find a folder given a PATH_DELIMITER delimited path starting from this folder @@ -91,6 +125,38 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver // We didn't find a folder with the right name return null; } + + /// + /// 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 + /// + /// + /// The user to search + /// + /// + /// The path to the required item. + /// + /// null if the item is not found + public static InventoryItemBase FindItemByPath( + IInventoryService inventoryService, UUID userId, string path) + { + InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); + + if (null == rootFolder) + return null; + + return FindItemByPath(inventoryService, rootFolder, path); + } /// /// Find an item given a PATH_DELIMITOR delimited path starting from this folder. diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index bdc2802d4c..50fd2b0756 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs @@ -136,8 +136,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests item1.AssetID = asset1.FullID; item1.ID = item1Id; InventoryFolderBase objsFolder - = InventoryArchiveUtils.FindFolderByPath( - scene.InventoryService, scene.InventoryService.GetRootFolder(userId), "Objects"); + = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects"); item1.Folder = objsFolder.ID; scene.AddInventoryItem(userId, item1); @@ -267,10 +266,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests CachedUserInfo userInfo = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); - //InventoryItemBase foundItem = userInfo.RootFolder.FindItemByPath(itemName); InventoryItemBase foundItem - = InventoryArchiveUtils.FindItemByPath( - scene.InventoryService, scene.InventoryService.GetRootFolder(userInfo.UserProfile.ID), itemName); + = InventoryArchiveUtils.FindItemByPath( scene.InventoryService, userInfo.UserProfile.ID, itemName); + Assert.That(foundItem, Is.Not.Null, "Didn't find loaded item"); Assert.That( foundItem.CreatorId, Is.EqualTo(item1.CreatorId),