backport iar version checking

0.7-post-fixes
Justin Clark-Casey (justincc) 2010-12-11 02:44:37 +00:00
parent ed0d7e3b60
commit ed97a42664
1 changed files with 51 additions and 2 deletions

View File

@ -50,6 +50,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 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.
/// </summary>
public static int MAX_MAJOR_VERSION = 0;
protected TarArchiveReader archive; protected TarArchiveReader archive;
private UserAccount m_userInfo; private UserAccount m_userInfo;
@ -126,7 +132,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{ {
while ((data = archive.ReadEntry(out filePath, out entryType)) != null) 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)) if (LoadAsset(filePath, data))
successfulAssetRestores++; successfulAssetRestores++;
@ -448,5 +458,44 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
return false; return false;
} }
} }
/// <summary>
/// Load control file
/// </summary>
/// <param name="path"></param>
/// <param name="data"></param>
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);
}
} }
} }