* Start compressing archives

0.6.0-stable
Justin Clarke Casey 2008-07-12 18:54:21 +00:00
parent 4ff529bdaf
commit 4e7dd0d919
6 changed files with 32 additions and 36 deletions

View File

@ -68,7 +68,7 @@ namespace OpenSim
/// <summary>
/// The file use to load and save an opensim archive if none has been specified
/// </summary>
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;

View File

@ -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;
@ -61,7 +62,9 @@ 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<string> serialisedSceneObjects = new List<string>();

View File

@ -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);
}

View File

@ -52,23 +52,13 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
/// </summary>
protected char[] m_nullCharArray = new char[] { '\0' };
public TarArchiveReader(string archivePath)
{
m_br = new BinaryReader(new FileStream(archivePath, FileMode.Open));
}
/// <summary>
/// Are we at the end of the archive?
/// Generate a tar reader which reads from the given stream.
/// </summary>
/// <returns></returns>
public bool AtEof()
/// <param name="s"></param>
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);
}
/// <summary>
@ -80,11 +70,11 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
{
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,15 +95,19 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
/// <summary>
/// Read the next 512 byte chunk of data as a tar header.
/// This method assumes we are not at the end of the archive
/// </summary>
/// <returns>A tar header struct.</returns>
/// <returns>A tar header struct. null if we have reached the end of the archive.</returns>
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);
tarHeader.FileSize = ConvertOctalBytesToDecimal(header, 124, 11);
@ -147,7 +141,7 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
}
}
public struct TarHeader
public class TarHeader
{
public string FilePath;
public int FileSize;

View File

@ -79,21 +79,19 @@ namespace OpenSim.Region.Environment
}
/// <summary>
/// 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.
/// </summary>
/// <param name="s">Stream to which to write the data</param>
/// <returns></returns>
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();
}

View File

@ -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;