From e98109765c11b4ea9abac3bb24600b1414ef4a36 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 18 Jun 2010 16:33:34 +0100 Subject: [PATCH] in IAR utils, return all folders that match a particular path rather than just the first one --- .../Archiver/InventoryArchiveReadRequest.cs | 13 ++++--- .../Archiver/InventoryArchiveUtils.cs | 35 +++++++++++-------- .../Archiver/InventoryArchiveWriteRequest.cs | 5 +-- .../Archiver/Tests/InventoryArchiverTests.cs | 10 +++--- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index b4f1ed6205..29e992e27f 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs @@ -100,18 +100,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver List loadedNodes = new List(); - InventoryFolderBase rootDestinationFolder + List folderCandidates = InventoryArchiveUtils.FindFolderByPath( m_scene.InventoryService, m_userInfo.PrincipalID, m_invPath); - if (null == rootDestinationFolder) + if (folderCandidates.Count == 0) { // Possibly provide an option later on to automatically create this folder if it does not exist m_log.ErrorFormat("[INVENTORY ARCHIVER]: Inventory path {0} does not exist", m_invPath); return loadedNodes; } - + + InventoryFolderBase rootDestinationFolder = folderCandidates[0]; archive = new TarArchiveReader(m_loadStream); // In order to load identically named folders, we need to keep track of the folders that we have already @@ -246,6 +247,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver ref string archivePath, Dictionary resolvedFolders) { + m_log.DebugFormat("[INVENTORY ARCHIVER]: Resolving destination folder {0}", archivePath); + string originalArchivePath = archivePath; InventoryFolderBase destFolder = null; @@ -256,8 +259,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver { if (resolvedFolders.ContainsKey(archivePath)) { -// m_log.DebugFormat( -// "[INVENTORY ARCHIVER]: Found previously created folder from archive path {0}", archivePath); + m_log.DebugFormat( + "[INVENTORY ARCHIVER]: Found previously created folder from archive path {0}", archivePath); destFolder = resolvedFolders[archivePath]; } else diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs index 47b18d85d4..ca339683ed 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs @@ -55,8 +55,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver /// /// 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: We have no way of distinguishing folders with the same path /// /// FIXME: Delimitors which occur in names themselves are not currently escapable. /// @@ -70,14 +69,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver /// 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( + /// An empty list if the folder is not found, otherwise a list of all folders that match the name + public static List FindFolderByPath( IInventoryService inventoryService, UUID userId, string path) { InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); if (null == rootFolder) - return null; + return new List(); return FindFolderByPath(inventoryService, rootFolder, path); } @@ -88,8 +87,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver /// /// 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: We have no way of distinguishing folders with the same path. /// /// FIXME: Delimitors which occur in names themselves are not currently escapable. /// @@ -103,17 +101,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver /// 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( + /// An empty list if the folder is not found, otherwise a list of all folders that match the name + public static List FindFolderByPath( IInventoryService inventoryService, InventoryFolderBase startFolder, string path) { + List foundFolders = new List(); + if (path == string.Empty) - return startFolder; + { + foundFolders.Add(startFolder); + return foundFolders; + } path = path.Trim(); if (path == PATH_DELIMITER.ToString()) - return startFolder; + { + foundFolders.Add(startFolder); + return foundFolders; + } string[] components = SplitEscapedPath(path); components[0] = UnescapePath(components[0]); @@ -127,14 +133,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver if (folder.Name == components[0]) { if (components.Length > 1) - return FindFolderByPath(inventoryService, folder, components[1]); + foundFolders.AddRange(FindFolderByPath(inventoryService, folder, components[1])); else - return folder; + foundFolders.Add(folder); } } - // We didn't find a folder with the right name - return null; + return foundFolders; } /// diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index 8f3f65b0b6..2c2724e74c 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs @@ -249,9 +249,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver else { m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER)); - inventoryFolder + List candidateFolders = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, rootFolder, m_invPath); - //inventoryFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath); + if (candidateFolders.Count > 0) + inventoryFolder = candidateFolders[0]; } // The path may point to an item instead diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index 00bd27aaba..6bf1219c7f 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs @@ -117,7 +117,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests item1.AssetID = asset1.FullID; item1.ID = item1Id; InventoryFolderBase objsFolder - = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects"); + = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0]; item1.Folder = objsFolder.ID; scene.AddInventoryItem(userId, item1); @@ -327,7 +327,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests item1.AssetID = asset1.FullID; item1.ID = item1Id; InventoryFolderBase objsFolder - = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects"); + = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0]; item1.Folder = objsFolder.ID; scene.AddInventoryItem(userId, item1); @@ -535,9 +535,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests foldersCreated, nodesLoaded); InventoryFolderBase folder1 - = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, "a"); + = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, "a")[0]; Assert.That(folder1, Is.Not.Null, "Could not find folder a"); - InventoryFolderBase folder2 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, "b"); + InventoryFolderBase folder2 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, "b")[0]; Assert.That(folder2, Is.Not.Null, "Could not find folder b"); } @@ -576,7 +576,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests new Dictionary(), new List()); InventoryFolderBase folder1Post - = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName); + = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName)[0]; Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID)); /* InventoryFolderBase folder2