From 76b21860e9f727391849c9b38c620b9bc16e4312 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 8 Sep 2009 16:12:15 +0100
Subject: refactor iar name generation slightly change the format of item
archive names
---
.../Archiver/InventoryArchiveWriteRequest.cs | 67 +++++++++++++++++++---
.../Archiver/Tests/InventoryArchiverTests.cs | 31 ++++------
2 files changed, 71 insertions(+), 27 deletions(-)
(limited to 'OpenSim/Region/CoreModules/Avatar/Inventory')
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
index dee4a5d..b178772 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
@@ -138,7 +138,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
protected void SaveInvItem(InventoryItemBase inventoryItem, string path)
{
- string filename = string.Format("{0}{1}_{2}.xml", path, inventoryItem.Name, inventoryItem.ID);
+ string filename = path + CreateArchiveItemName(inventoryItem);
// Record the creator of this item for user record purposes (which might go away soon)
m_userUuids[inventoryItem.CreatorIdAsUuid] = 1;
@@ -162,12 +162,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
if (saveThisFolderItself)
{
- path +=
- string.Format(
- "{0}{1}{2}/",
- inventoryFolder.Name,
- ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR,
- inventoryFolder.ID);
+ path += CreateArchiveFolderName(inventoryFolder);
// We need to make sure that we record empty folders
m_archiveWriter.WriteDir(path);
@@ -356,5 +351,63 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
}
}
+
+ ///
+ /// Create the archive name for a particular folder.
+ ///
+ ///
+ /// These names are prepended with an inventory folder's UUID so that more than one folder can have the
+ /// same name
+ ///
+ ///
+ ///
+ public static string CreateArchiveFolderName(InventoryFolderBase folder)
+ {
+ return CreateArchiveFolderName(folder.Name, folder.ID);
+ }
+
+ ///
+ /// Create the archive name for a particular item.
+ ///
+ ///
+ /// These names are prepended with an inventory item's UUID so that more than one item can have the
+ /// same name
+ ///
+ ///
+ ///
+ public static string CreateArchiveItemName(InventoryItemBase item)
+ {
+ return CreateArchiveItemName(item.Name, item.ID);
+ }
+
+ ///
+ /// Create an archive folder name given its constituent components
+ ///
+ ///
+ ///
+ ///
+ public static string CreateArchiveFolderName(string name, UUID id)
+ {
+ return string.Format(
+ "{0}{1}{2}/",
+ name,
+ ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR,
+ id);
+ }
+
+ ///
+ /// Create an archive item name given its constituent components
+ ///
+ ///
+ ///
+ ///
+ public static string CreateArchiveItemName(string name, UUID id)
+ {
+ return string.Format(
+ "{0}{1}{2}.xml",
+ name,
+ ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR,
+ id);
+ }
}
}
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
index d579a81..5461ea2 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
@@ -153,19 +153,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
//bool gotControlFile = false;
bool gotObject1File = false;
//bool gotObject2File = false;
+ string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1);
string expectedObject1FilePath = string.Format(
- "{0}{1}/{2}_{3}.xml",
+ "{0}{1}{2}",
ArchiveConstants.INVENTORY_PATH,
- string.Format(
- "Objects{0}{1}", ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, objsFolder.ID),
- item1.Name,
- item1Id);
-
-// string expectedObject2FileName = string.Format(
-// "{0}_{1:000}-{2:000}-{3:000}__{4}.xml",
-// part2.Name,
-// Math.Round(part2.GroupPosition.X), Math.Round(part2.GroupPosition.Y), Math.Round(part2.GroupPosition.Z),
-// part2.UUID);
+ InventoryArchiveWriteRequest.CreateArchiveFolderName(objsFolder),
+ expectedObject1FileName);
string filePath;
TarArchiveReader.TarEntryType tarEntryType;
@@ -187,7 +180,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
//
// if (fileName.StartsWith(part1.Name))
// {
- Assert.That(filePath, Is.EqualTo(expectedObject1FilePath));
+ Assert.That(expectedObject1FilePath, Is.EqualTo(filePath));
gotObject1File = true;
// }
// else if (fileName.StartsWith(part2.Name))
@@ -385,16 +378,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
string folder2Name = "b";
string itemName = "c.lsl";
- string folder1ArchiveName
- = string.Format(
- "{0}{1}{2}", folder1Name, ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, UUID.Random());
- string folder2ArchiveName
- = string.Format(
- "{0}{1}{2}", folder2Name, ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, UUID.Random());
+ string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1Name, 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, itemName);
+ "{0}{1}{2}{3}",
+ ArchiveConstants.INVENTORY_PATH, folder1ArchiveName, folder2ArchiveName, itemArchiveName);
//Console.WriteLine("userInfo.RootFolder 2: {0}", userInfo.RootFolder);
--
cgit v1.1