diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index 60d1720ba7..b4f1ed6205 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs @@ -219,40 +219,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver CreateFoldersForPath(destFolder, archivePathSectionToCreate, resolvedFolders, loadedNodes); return destFolder; - - /* - string[] rawFolders = filePath.Split(new char[] { '/' }); - - // Find the folders that do exist along the path given - int i = 0; - bool noFolder = false; - InventoryFolderImpl foundFolder = rootDestinationFolder; - while (!noFolder && i < rawFolders.Length) - { - InventoryFolderImpl folder = foundFolder.FindFolderByPath(rawFolders[i]); - if (null != folder) - { - m_log.DebugFormat("[INVENTORY ARCHIVER]: Found folder {0}", folder.Name); - foundFolder = folder; - i++; - } - else - { - noFolder = true; - } - } - - // Create any folders that did not previously exist - while (i < rawFolders.Length) - { - m_log.DebugFormat("[INVENTORY ARCHIVER]: Creating folder {0}", rawFolders[i]); - - UUID newFolderId = UUID.Random(); - m_userInfo.CreateFolder( - rawFolders[i++], newFolderId, (ushort)AssetType.Folder, foundFolder.ID); - foundFolder = foundFolder.GetChildFolder(newFolderId); - } - */ } /// diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index 59cd386c0c..00bd27aaba 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs @@ -279,7 +279,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests public void TestIarV0_1WithEscapedChars() { TestHelper.InMethod(); - log4net.Config.XmlConfigurator.Configure(); +// log4net.Config.XmlConfigurator.Configure(); string itemName = "You & you are a mean/man/"; string humanEscapedItemName = @"You & you are a mean\/man\/"; @@ -505,7 +505,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests /// Test replication of an archive path to the user's inventory. /// [Test] - public void TestReplicateArchivePathToUserInventory() + public void TestNewIarPath() { TestHelper.InMethod(); //log4net.Config.XmlConfigurator.Configure(); @@ -540,5 +540,51 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests InventoryFolderBase folder2 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, "b"); Assert.That(folder2, Is.Not.Null, "Could not find folder b"); } + + /// + /// Test replication of a partly existing archive path to the user's inventory. + /// + [Test] + public void TestPartExistingIarPath() + { + TestHelper.InMethod(); + //log4net.Config.XmlConfigurator.Configure(); + + Scene scene = SceneSetupHelpers.SetupScene("inventory"); + UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene); + + string folder1ExistingName = "a"; + string folder2Name = "b"; + string itemName = "c.lsl"; + + InventoryFolderBase folder1 + = UserInventoryTestUtils.CreateInventoryFolder( + scene.InventoryService, ua1.PrincipalID, folder1ExistingName); + + string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random()); + string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random()); + string itemArchiveName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random()); + + string itemArchivePath + = string.Format( + "{0}{1}{2}{3}", + ArchiveConstants.INVENTORY_PATH, folder1ArchiveName, folder2ArchiveName, itemArchiveName); + + new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null) + .ReplicateArchivePathToUserInventory( + itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID), + new Dictionary(), new List()); + + InventoryFolderBase folder1Post + = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName); + Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID)); + /* + InventoryFolderBase folder2 + = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1Post, "b"); + Assert.That(folder2, Is.Not.Null); + InventoryItemBase item = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, folder2, itemName); + Assert.That(item, Is.Not.Null); + */ + } } } \ No newline at end of file diff --git a/OpenSim/Tests/Common/Setup/AssetHelpers.cs b/OpenSim/Tests/Common/Setup/AssetHelpers.cs index 6dc993f069..f9a80b05b2 100644 --- a/OpenSim/Tests/Common/Setup/AssetHelpers.cs +++ b/OpenSim/Tests/Common/Setup/AssetHelpers.cs @@ -36,25 +36,29 @@ namespace OpenSim.Tests.Common public class AssetHelpers { /// - /// Create an asset from the given data + /// Create a notecard asset with a random uuid and dummy text. /// - public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, byte[] data, UUID creatorID) + /// /param> + /// + public static AssetBase CreateAsset(UUID creatorId) { - AssetBase asset = new AssetBase(assetUuid, assetUuid.ToString(), (sbyte)assetType, creatorID.ToString()); - asset.Data = data; - return asset; - } - - /// - /// Create an asset from the given data - /// - public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, string data, UUID creatorID) - { - return CreateAsset(assetUuid, assetType, Encoding.ASCII.GetBytes(data), creatorID); + return CreateAsset(UUID.Random(), AssetType.Notecard, "hello", creatorId); } /// - /// Create an asset from the given scene object + /// Create and store a notecard asset with a random uuid and dummy text. + /// + /// /param> + /// + public static AssetBase CreateAsset(Scene scene, UUID creatorId) + { + AssetBase asset = CreateAsset(UUID.Random(), AssetType.Notecard, "hello", creatorId); + scene.AssetService.Store(asset); + return asset; + } + + /// + /// Create an asset from the given scene object. /// /// /// @@ -67,5 +71,23 @@ namespace OpenSim.Tests.Common Encoding.ASCII.GetBytes(SceneObjectSerializer.ToXml2Format(sog)), sog.OwnerID); } + + /// + /// Create an asset from the given data. + /// + public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, string data, UUID creatorID) + { + return CreateAsset(assetUuid, assetType, Encoding.ASCII.GetBytes(data), creatorID); + } + + /// + /// Create an asset from the given data. + /// + public static AssetBase CreateAsset(UUID assetUuid, AssetType assetType, byte[] data, UUID creatorID) + { + AssetBase asset = new AssetBase(assetUuid, assetUuid.ToString(), (sbyte)assetType, creatorID.ToString()); + asset.Data = data; + return asset; + } } } diff --git a/OpenSim/Tests/Common/Setup/UserInventoryTestUtils.cs b/OpenSim/Tests/Common/Setup/UserInventoryTestUtils.cs index 7e0c5672df..c57363aa94 100644 --- a/OpenSim/Tests/Common/Setup/UserInventoryTestUtils.cs +++ b/OpenSim/Tests/Common/Setup/UserInventoryTestUtils.cs @@ -28,6 +28,7 @@ using System; using OpenMetaverse; using OpenSim.Framework; +using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Interfaces; namespace OpenSim.Tests.Common @@ -39,6 +40,23 @@ namespace OpenSim.Tests.Common { public static readonly string PATH_DELIMITER = "/"; + public static InventoryItemBase CreateInventoryItem( + Scene scene, string itemName, UUID itemId, string folderPath, UUID userId) + { + InventoryItemBase item = new InventoryItemBase(); + item.Name = itemName; + item.AssetID = AssetHelpers.CreateAsset(scene, userId).FullID; + item.ID = itemId; + + // Really quite bad since the objs folder could be moved in the future and confuse the tests + InventoryFolderBase objsFolder = scene.InventoryService.GetFolderForType(userId, AssetType.Object); + + item.Folder = objsFolder.ID; + scene.AddInventoryItem(userId, item); + + return item; + } + /// /// Create inventory folders starting from the user's root folder. ///