From ea4982e4532f0cd2b793375f2c9f54c3c389c552 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 30 May 2008 16:08:28 +0000 Subject: [PATCH] * Successfully pick out prims.xml file from archive --- .../Modules/Avatar/Chat/IRCBridgeModule.cs | 2 +- .../World/Archiver/ArchiveConstants.cs | 45 +++++++++++++++++++ .../World/Archiver/ArchiveReadRequest.cs | 23 +++++++++- .../World/Archiver/ArchiveWriteRequest.cs | 6 +-- .../World/Archiver/TarArchiveReader.cs | 9 +++- 5 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 OpenSim/Region/Environment/Modules/World/Archiver/ArchiveConstants.cs diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs index befa89f875..a7abfb428a 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs @@ -861,4 +861,4 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat m_tcp.Close(); } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveConstants.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveConstants.cs new file mode 100644 index 0000000000..7df6033e5c --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveConstants.cs @@ -0,0 +1,45 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace OpenSim.Region.Environment.Modules.World.Archiver +{ + /// + /// Constants for the archiving module + /// + public class ArchiveConstants + { + /// + /// Path for the assets held in an archive + /// + public static readonly string ASSETS_PATH = "assets/"; + + /// + /// Path for the prims file + /// + public static readonly string PRIMS_PATH = "prims.xml"; + } +} diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs index 268b9b55cb..6ad11ee13c 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs @@ -26,6 +26,7 @@ */ using OpenSim.Region.Environment.Scenes; +using System; using System.Reflection; using log4net; @@ -38,6 +39,8 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + protected static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding(); + private Scene m_scene; private string m_loadPath; @@ -53,6 +56,8 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver { TarArchiveReader archive = new TarArchiveReader(m_loadPath); + string serializedPrims = string.Empty; + // Just test for now by reading first file string filePath = "ERROR"; @@ -60,11 +65,27 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver while ((data = archive.ReadEntry(out filePath)) != null) { m_log.DebugFormat("[ARCHIVER]: Successfully read {0} ({1} bytes) from archive {2}", filePath, data.Length, m_loadPath); + + if (filePath.Equals(ArchiveConstants.PRIMS_PATH)) + { + serializedPrims = m_asciiEncoding.GetString(data); + } } - m_log.DebugFormat("[ARCHIVER]: Reached end of archive"); + m_log.DebugFormat("[ARCHIVER]: Reached end of archive"); archive.Close(); + + if (serializedPrims.Equals(string.Empty)) + { + m_log.ErrorFormat("[ARCHIVER]: Archive did not contain a {0} file", ArchiveConstants.PRIMS_PATH); + return; + } + + // Reload serialized prims + m_log.InfoFormat("[ARCHIVER]: Loading prim data"); + + //m_scene.LoadPrimsFromXml2( } } } diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs index 576286d803..d936df5642 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs @@ -36,7 +36,7 @@ using libsecondlife; using log4net; using Nini.Config; -namespace OpenSim.Region.Environment +namespace OpenSim.Region.Environment.Modules.World.Archiver { /// /// Method called when all the necessary assets for an archive request have been received. @@ -103,7 +103,7 @@ namespace OpenSim.Region.Environment TarArchiveWriter archive = new TarArchiveWriter(); - archive.AddFile("prims.xml", m_serializedEntities); + archive.AddFile(ArchiveConstants.PRIMS_PATH, m_serializedEntities); // It appears that gtar, at least, doesn't need the intermediate directory entries in the tar //archive.AddDir("assets"); @@ -112,7 +112,7 @@ namespace OpenSim.Region.Environment { if (assets[uuid] != null) { - archive.AddFile("assets/" + uuid.ToString() + ".jp2", assets[uuid].Data); + archive.AddFile(ArchiveConstants.ASSETS_PATH + uuid.ToString() + ".jp2", assets[uuid].Data); } else { diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs index aacae951f3..b199d5f816 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs @@ -28,6 +28,7 @@ using System; using System.IO; using System.Reflection; +using System.Text; using log4net; namespace OpenSim.Region.Environment.Modules.World.Archiver @@ -39,13 +40,18 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - protected static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding(); + protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); /// /// Binary reader for the underlying stream /// protected BinaryReader m_br; + /// + /// Used to trim off null chars + /// + protected char[] m_nullCharArray = new char[] { '\0' }; + public TarArchiveReader(string archivePath) { m_br = new BinaryReader(new FileStream(archivePath, FileMode.Open)); @@ -109,6 +115,7 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver byte[] header = m_br.ReadBytes(512); tarHeader.FilePath = m_asciiEncoding.GetString(header, 0, 100); + tarHeader.FilePath = tarHeader.FilePath.Trim(m_nullCharArray); tarHeader.FileSize = ConvertOctalBytesToDecimal(header, 124, 11); return tarHeader;