allow inventory path specified in "load iar" to start with a / (e.g. /Objects is now valid where it wasn't before)

prebuild-update
Justin Clark-Casey (justincc) 2010-08-27 23:22:49 +01:00
parent b4278510f2
commit 86937d0a0f
3 changed files with 45 additions and 13 deletions

View File

@ -41,7 +41,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// </summary> /// </summary>
public static class InventoryArchiveUtils public static class InventoryArchiveUtils
{ {
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// Character used for escaping the path delimter ("\/") and itself ("\\") in human escaped strings // Character used for escaping the path delimter ("\/") and itself ("\\") in human escaped strings
public static readonly char ESCAPE_CHARACTER = '\\'; public static readonly char ESCAPE_CHARACTER = '\\';
@ -120,6 +120,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
foundFolders.Add(startFolder); foundFolders.Add(startFolder);
return foundFolders; return foundFolders;
} }
// If the path isn't just / then trim any starting extraneous slashes
path = path.TrimStart(new char[] { PATH_DELIMITER });
// m_log.DebugFormat("[INVENTORY ARCHIVE UTILS]: Adjusted path in FindFolderByPath() is [{0}]", path);
string[] components = SplitEscapedPath(path); string[] components = SplitEscapedPath(path);
components[0] = UnescapePath(components[0]); components[0] = UnescapePath(components[0]);
@ -199,6 +204,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
public static InventoryItemBase FindItemByPath( public static InventoryItemBase FindItemByPath(
IInventoryService inventoryService, InventoryFolderBase startFolder, string path) IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
{ {
// If the path isn't just / then trim any starting extraneous slashes
path = path.TrimStart(new char[] { PATH_DELIMITER });
string[] components = SplitEscapedPath(path); string[] components = SplitEscapedPath(path);
components[0] = UnescapePath(components[0]); components[0] = UnescapePath(components[0]);

View File

@ -342,6 +342,30 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
// TODO: Test presence of more files and contents of files. // TODO: Test presence of more files and contents of files.
} }
/// <summary>
/// Test that things work when the load path specified starts with a slash
/// </summary>
[Test]
public void TestLoadIarPathStartsWithSlash()
{
TestHelper.InMethod();
log4net.Config.XmlConfigurator.Configure();
SerialiserModule serialiserModule = new SerialiserModule();
InventoryArchiverModule archiverModule = new InventoryArchiverModule(true);
Scene scene = SceneSetupHelpers.SetupScene("inventory");
SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule);
UserProfileTestUtils.CreateUserWithInventory(scene, m_ua1, "password");
archiverModule.DearchiveInventory(m_ua1.FirstName, m_ua1.LastName, "/Objects", "password", m_iarStream);
InventoryItemBase foundItem1
= InventoryArchiveUtils.FindItemByPath(
scene.InventoryService, m_ua1.PrincipalID, "/Objects/" + m_item1Name);
Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1 in TestLoadIarFolderStartsWithSlash()");
}
/// <summary> /// <summary>
/// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where
/// an account exists with the creator name. /// an account exists with the creator name.

View File

@ -86,7 +86,7 @@ namespace OpenSim.Tests.Common.Mock
{ {
InventoryFolderBase folder = m_folders[folderID]; InventoryFolderBase folder = m_folders[folderID];
m_log.DebugFormat("[MOCK INV DB]: Getting items in folder {0} {1}", folder.Name, folder.ID); // m_log.DebugFormat("[MOCK INV DB]: Getting items in folder {0} {1}", folder.Name, folder.ID);
List<InventoryItemBase> items = new List<InventoryItemBase>(); List<InventoryItemBase> items = new List<InventoryItemBase>();
@ -94,7 +94,7 @@ namespace OpenSim.Tests.Common.Mock
{ {
if (item.Folder == folderID) if (item.Folder == folderID)
{ {
m_log.DebugFormat("[MOCK INV DB]: getInventoryInFolder() adding item {0}", item.Name); // m_log.DebugFormat("[MOCK INV DB]: getInventoryInFolder() adding item {0}", item.Name);
items.Add(item); items.Add(item);
} }
} }
@ -106,7 +106,7 @@ namespace OpenSim.Tests.Common.Mock
public InventoryFolderBase getUserRootFolder(UUID user) public InventoryFolderBase getUserRootFolder(UUID user)
{ {
m_log.DebugFormat("[MOCK INV DB]: Looking for root folder for {0}", user); // m_log.DebugFormat("[MOCK INV DB]: Looking for root folder for {0}", user);
InventoryFolderBase folder = null; InventoryFolderBase folder = null;
m_rootFolders.TryGetValue(user, out folder); m_rootFolders.TryGetValue(user, out folder);
@ -118,7 +118,7 @@ namespace OpenSim.Tests.Common.Mock
{ {
InventoryFolderBase parentFolder = m_folders[parentID]; InventoryFolderBase parentFolder = m_folders[parentID];
m_log.DebugFormat("[MOCK INV DB]: Getting folders in folder {0} {1}", parentFolder.Name, parentFolder.ID); // m_log.DebugFormat("[MOCK INV DB]: Getting folders in folder {0} {1}", parentFolder.Name, parentFolder.ID);
List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
@ -126,9 +126,9 @@ namespace OpenSim.Tests.Common.Mock
{ {
if (folder.ParentID == parentID) if (folder.ParentID == parentID)
{ {
m_log.DebugFormat( // m_log.DebugFormat(
"[MOCK INV DB]: Found folder {0} {1} in {2} {3}", // "[MOCK INV DB]: Found folder {0} {1} in {2} {3}",
folder.Name, folder.ID, parentFolder.Name, parentFolder.ID); // folder.Name, folder.ID, parentFolder.Name, parentFolder.ID);
folders.Add(folder); folders.Add(folder);
} }
@ -152,9 +152,9 @@ namespace OpenSim.Tests.Common.Mock
public void addInventoryFolder(InventoryFolderBase folder) public void addInventoryFolder(InventoryFolderBase folder)
{ {
m_log.DebugFormat( // m_log.DebugFormat(
"[MOCK INV DB]: Adding inventory folder {0} {1} type {2}", // "[MOCK INV DB]: Adding inventory folder {0} {1} type {2}",
folder.Name, folder.ID, (AssetType)folder.Type); // folder.Name, folder.ID, (AssetType)folder.Type);
m_folders[folder.ID] = folder; m_folders[folder.ID] = folder;
@ -187,8 +187,8 @@ namespace OpenSim.Tests.Common.Mock
{ {
InventoryFolderBase folder = m_folders[item.Folder]; InventoryFolderBase folder = m_folders[item.Folder];
m_log.DebugFormat( // m_log.DebugFormat(
"[MOCK INV DB]: Adding inventory item {0} {1} in {2} {3}", item.Name, item.ID, folder.Name, folder.ID); // "[MOCK INV DB]: Adding inventory item {0} {1} in {2} {3}", item.Name, item.ID, folder.Name, folder.ID);
m_items[item.ID] = item; m_items[item.ID] = item;
} }