in IAR utils, return all folders that match a particular path rather than just the first one

0.7-release
Justin Clark-Casey (justincc) 2010-06-18 16:33:34 +01:00 committed by Justin Clark-Casey
parent c980326425
commit e98109765c
4 changed files with 36 additions and 27 deletions

View File

@ -100,11 +100,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
List<InventoryNodeBase> loadedNodes = new List<InventoryNodeBase>(); List<InventoryNodeBase> loadedNodes = new List<InventoryNodeBase>();
InventoryFolderBase rootDestinationFolder List<InventoryFolderBase> folderCandidates
= InventoryArchiveUtils.FindFolderByPath( = InventoryArchiveUtils.FindFolderByPath(
m_scene.InventoryService, m_userInfo.PrincipalID, m_invPath); 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 // 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); m_log.ErrorFormat("[INVENTORY ARCHIVER]: Inventory path {0} does not exist", m_invPath);
@ -112,6 +112,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
return loadedNodes; return loadedNodes;
} }
InventoryFolderBase rootDestinationFolder = folderCandidates[0];
archive = new TarArchiveReader(m_loadStream); archive = new TarArchiveReader(m_loadStream);
// In order to load identically named folders, we need to keep track of the folders that we have already // 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, ref string archivePath,
Dictionary <string, InventoryFolderBase> resolvedFolders) Dictionary <string, InventoryFolderBase> resolvedFolders)
{ {
m_log.DebugFormat("[INVENTORY ARCHIVER]: Resolving destination folder {0}", archivePath);
string originalArchivePath = archivePath; string originalArchivePath = archivePath;
InventoryFolderBase destFolder = null; InventoryFolderBase destFolder = null;
@ -256,8 +259,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{ {
if (resolvedFolders.ContainsKey(archivePath)) if (resolvedFolders.ContainsKey(archivePath))
{ {
// m_log.DebugFormat( m_log.DebugFormat(
// "[INVENTORY ARCHIVER]: Found previously created folder from archive path {0}", archivePath); "[INVENTORY ARCHIVER]: Found previously created folder from archive path {0}", archivePath);
destFolder = resolvedFolders[archivePath]; destFolder = resolvedFolders[archivePath];
} }
else else

View File

@ -55,8 +55,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// ///
/// This method does not handle paths that contain multiple delimitors /// 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 /// FIXME: We have no way of distinguishing folders with the same path
/// XPath like expression
/// ///
/// FIXME: Delimitors which occur in names themselves are not currently escapable. /// 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. /// The path to the required folder.
/// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned. /// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
/// </param> /// </param>
/// <returns>null if the folder is not found</returns> /// <returns>An empty list if the folder is not found, otherwise a list of all folders that match the name</returns>
public static InventoryFolderBase FindFolderByPath( public static List<InventoryFolderBase> FindFolderByPath(
IInventoryService inventoryService, UUID userId, string path) IInventoryService inventoryService, UUID userId, string path)
{ {
InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
if (null == rootFolder) if (null == rootFolder)
return null; return new List<InventoryFolderBase>();
return FindFolderByPath(inventoryService, rootFolder, path); 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 /// 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 /// FIXME: We have no way of distinguishing folders with the same path.
/// XPath like expression
/// ///
/// FIXME: Delimitors which occur in names themselves are not currently escapable. /// 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. /// The path to the required folder.
/// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned. /// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
/// </param> /// </param>
/// <returns>null if the folder is not found</returns> /// <returns>An empty list if the folder is not found, otherwise a list of all folders that match the name</returns>
public static InventoryFolderBase FindFolderByPath( public static List<InventoryFolderBase> FindFolderByPath(
IInventoryService inventoryService, InventoryFolderBase startFolder, string path) IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
{ {
List<InventoryFolderBase> foundFolders = new List<InventoryFolderBase>();
if (path == string.Empty) if (path == string.Empty)
return startFolder; {
foundFolders.Add(startFolder);
return foundFolders;
}
path = path.Trim(); path = path.Trim();
if (path == PATH_DELIMITER.ToString()) if (path == PATH_DELIMITER.ToString())
return startFolder; {
foundFolders.Add(startFolder);
return foundFolders;
}
string[] components = SplitEscapedPath(path); string[] components = SplitEscapedPath(path);
components[0] = UnescapePath(components[0]); components[0] = UnescapePath(components[0]);
@ -127,14 +133,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
if (folder.Name == components[0]) if (folder.Name == components[0])
{ {
if (components.Length > 1) if (components.Length > 1)
return FindFolderByPath(inventoryService, folder, components[1]); foundFolders.AddRange(FindFolderByPath(inventoryService, folder, components[1]));
else else
return folder; foundFolders.Add(folder);
} }
} }
// We didn't find a folder with the right name return foundFolders;
return null;
} }
/// <summary> /// <summary>

View File

@ -249,9 +249,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
else else
{ {
m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER)); m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER));
inventoryFolder List<InventoryFolderBase> candidateFolders
= InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, rootFolder, m_invPath); = 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 // The path may point to an item instead

View File

@ -117,7 +117,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
item1.AssetID = asset1.FullID; item1.AssetID = asset1.FullID;
item1.ID = item1Id; item1.ID = item1Id;
InventoryFolderBase objsFolder InventoryFolderBase objsFolder
= InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects"); = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0];
item1.Folder = objsFolder.ID; item1.Folder = objsFolder.ID;
scene.AddInventoryItem(userId, item1); scene.AddInventoryItem(userId, item1);
@ -327,7 +327,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
item1.AssetID = asset1.FullID; item1.AssetID = asset1.FullID;
item1.ID = item1Id; item1.ID = item1Id;
InventoryFolderBase objsFolder InventoryFolderBase objsFolder
= InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects"); = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0];
item1.Folder = objsFolder.ID; item1.Folder = objsFolder.ID;
scene.AddInventoryItem(userId, item1); scene.AddInventoryItem(userId, item1);
@ -535,9 +535,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
foldersCreated, nodesLoaded); foldersCreated, nodesLoaded);
InventoryFolderBase folder1 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"); 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"); 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<string, InventoryFolderBase>(), new List<InventoryNodeBase>()); new Dictionary<string, InventoryFolderBase>(), new List<InventoryNodeBase>());
InventoryFolderBase folder1Post 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)); Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID));
/* /*
InventoryFolderBase folder2 InventoryFolderBase folder2