From 4e7dd0d9193155b22f0d8da1e0758b39652f4c41 Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Sat, 12 Jul 2008 18:54:21 +0000
Subject: * Start compressing archives
---
OpenSim/Region/Application/OpenSimBase.cs | 2 +-
.../Modules/World/Archiver/ArchiveReadRequest.cs | 7 ++--
.../World/Archiver/ArchiveWriteRequestExecution.cs | 3 +-
.../Modules/World/Archiver/TarArchiveReader.cs | 42 ++++++++++------------
.../Modules/World/Archiver/TarArchiveWriter.cs | 12 +++----
.../Region/Environment/Scenes/SceneObjectGroup.cs | 2 +-
6 files changed, 32 insertions(+), 36 deletions(-)
(limited to 'OpenSim')
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs
index 37daf88..c6061e1 100644
--- a/OpenSim/Region/Application/OpenSimBase.cs
+++ b/OpenSim/Region/Application/OpenSimBase.cs
@@ -68,7 +68,7 @@ namespace OpenSim
///
/// The file use to load and save an opensim archive if none has been specified
///
- protected const string DEFAULT_OAR_BACKUP_FILENAME = "scene.oar.tar";
+ protected const string DEFAULT_OAR_BACKUP_FILENAME = "scene_oar.tar.gz";
public string m_physicsEngine;
public string m_meshEngineName;
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs
index 0f179f4..0e37197 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs
@@ -32,6 +32,7 @@ using OpenSim.Region.Environment.Modules.World.Terrain;
using System;
using System.Collections.Generic;
using System.IO;
+using System.IO.Compression;
using System.Reflection;
using System.Xml;
using libsecondlife;
@@ -60,8 +61,10 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
}
protected void DearchiveRegion()
- {
- TarArchiveReader archive = new TarArchiveReader(m_loadPath);
+ {
+ TarArchiveReader archive
+ = new TarArchiveReader(
+ new GZipStream(new FileStream(m_loadPath, FileMode.Open), CompressionMode.Decompress));
//AssetsDearchiver dearchiver = new AssetsDearchiver(m_scene.AssetCache);
List serialisedSceneObjects = new List();
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestExecution.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestExecution.cs
index f8c8b73..e980650 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestExecution.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequestExecution.cs
@@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.IO.Compression;
using System.Reflection;
using System.Xml;
using libsecondlife;
@@ -110,7 +111,7 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
AssetsArchiver assetsArchiver = new AssetsArchiver(assets);
assetsArchiver.Archive(archive);
- archive.WriteTar(m_savePath);
+ archive.WriteTar(new GZipStream(new FileStream(m_savePath, FileMode.Create), CompressionMode.Compress));
m_log.InfoFormat("[ARCHIVER]: Wrote out OpenSimulator archive {0}", m_savePath);
}
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs
index 463e172..67f27b8 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs
@@ -52,23 +52,13 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
///
protected char[] m_nullCharArray = new char[] { '\0' };
- public TarArchiveReader(string archivePath)
- {
- m_br = new BinaryReader(new FileStream(archivePath, FileMode.Open));
- }
-
///
- /// Are we at the end of the archive?
+ /// Generate a tar reader which reads from the given stream.
///
- ///
- public bool AtEof()
+ ///
+ public TarArchiveReader(Stream s)
{
- // If we've reached the end of the archive we'll be in null block territory, which means
- // the next byte will be 0
- if (m_br.PeekChar() == 0)
- return true;
-
- return false;
+ m_br = new BinaryReader(s);
}
///
@@ -79,11 +69,11 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
public byte[] ReadEntry(out string filePath)
{
filePath = String.Empty;
-
- if (AtEof())
- return null;
-
+
TarHeader header = ReadHeader();
+
+ if (null == header)
+ return null;
filePath = header.FilePath;
byte[] data = m_br.ReadBytes(header.FileSize);
@@ -105,14 +95,18 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
///
/// Read the next 512 byte chunk of data as a tar header.
- /// This method assumes we are not at the end of the archive
///
- /// A tar header struct.
+ /// A tar header struct. null if we have reached the end of the archive.
protected TarHeader ReadHeader()
- {
- TarHeader tarHeader = new TarHeader();
-
+ {
byte[] header = m_br.ReadBytes(512);
+
+ // If we've reached the end of the archive we'll be in null block territory, which means
+ // the next byte will be 0
+ if (header[0] == 0)
+ return null;
+
+ TarHeader tarHeader = new TarHeader();
tarHeader.FilePath = m_asciiEncoding.GetString(header, 0, 100);
tarHeader.FilePath = tarHeader.FilePath.Trim(m_nullCharArray);
@@ -147,7 +141,7 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
}
}
- public struct TarHeader
+ public class TarHeader
{
public string FilePath;
public int FileSize;
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveWriter.cs b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveWriter.cs
index 1301eb3..afb0a91 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveWriter.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveWriter.cs
@@ -79,21 +79,19 @@ namespace OpenSim.Region.Environment
}
///
- /// Write the raw tar archive data to a file
+ /// Write the raw tar archive data to a stream. The stream will be closed on completion.
///
+ /// Stream to which to write the data
///
- public void WriteTar(string archivePath)
+ public void WriteTar(Stream s)
{
- BinaryWriter bw = new BinaryWriter(new FileStream(archivePath, FileMode.Create));
+ BinaryWriter bw = new BinaryWriter(s);
foreach (string filePath in m_files.Keys)
{
byte[] header = new byte[512];
byte[] data = m_files[filePath];
- //string filePath = "test.txt";
- //byte[] data = m_asciiEncoding.GetBytes("hello\n");
-
// file path field (100)
byte[] nameBytes = m_asciiEncoding.GetBytes(filePath);
int nameSize = (nameBytes.Length >= 100) ? 100 : nameBytes.Length;
@@ -149,7 +147,6 @@ namespace OpenSim.Region.Environment
m_log.DebugFormat("[TAR ARCHIVE WRITER]: Decimal header checksum is {0}", checksum);
byte[] checkSumBytes = ConvertDecimalToPaddedOctalBytes(checksum, 6);
- //byte[] checkSumBytes = m_asciiEncoding.GetBytes("007520");
Array.Copy(checkSumBytes, 0, header, 148, 6);
@@ -176,6 +173,7 @@ namespace OpenSim.Region.Environment
byte[] finalZeroPadding = new byte[1024];
bw.Write(finalZeroPadding);
+ bw.Flush();
bw.Close();
}
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
index eafb882..f2c94c8 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
@@ -2014,7 +2014,7 @@ namespace OpenSim.Region.Environment.Scenes
{
foreach (SceneObjectPart parts in m_parts.Values)
{
- if(part.Scale.X > 10.0 || part.Scale.Y > 10.0 || part.Scale.Z > 10.0)
+ if (part.Scale.X > 10.0 || part.Scale.Y > 10.0 || part.Scale.Z > 10.0)
{
data[47] = 0; // Reset physics
break;
--
cgit v1.1