From 2db53df6fa4f269afe2bf96661ce955ea0cebf24 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 11 Dec 2010 02:44:37 +0000 Subject: [PATCH] backport iar version checking --- .../Archiver/InventoryArchiveReadRequest.cs | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index 160a9bdfcc..26bc84a947 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs @@ -51,6 +51,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + /// + /// The maximum major version of archive that we can read. Minor versions shouldn't need a max number since version + /// bumps here should be compatible. + /// + public static int MAX_MAJOR_VERSION = 0; + protected TarArchiveReader archive; private CachedUserInfo m_userInfo; @@ -126,7 +132,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver { while ((data = archive.ReadEntry(out filePath, out entryType)) != null) { - if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) + if (filePath == ArchiveConstants.CONTROL_FILE_PATH) + { + LoadControlFile(filePath, data); + } + else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) { if (LoadAsset(filePath, data)) successfulAssetRestores++; @@ -432,5 +442,44 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver return false; } } + + /// + /// Load control file + /// + /// + /// + protected void LoadControlFile(string path, byte[] data) + { + int majorVersion = -1; + int minorVersion = -1; + string version = "ERROR"; + + NameTable nt = new NameTable(); + XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt); + XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None); + XmlTextReader xtr = new XmlTextReader(Encoding.ASCII.GetString(data), XmlNodeType.Document, context); + while (xtr.Read()) + { + if (xtr.NodeType == XmlNodeType.Element) + { + if (xtr.Name.ToString() == "archive") + { + majorVersion = int.Parse(xtr["major_version"]); + minorVersion = int.Parse(xtr["minor_version"]); + version = string.Format("{0}.{1}", majorVersion, minorVersion); + } + } + } + + if (majorVersion > MAX_MAJOR_VERSION) + { + throw new Exception( + string.Format( + "The IAR you are trying to load has major version number of {0} but this version of OpenSim can only load IARs with major version number {1} and below", + majorVersion, MAX_MAJOR_VERSION)); + } + + m_log.InfoFormat("[INVENTORY ARCHIVER]: Loading IAR with version {0}", version); + } } }