From 5752c1f5c2ee069e2ff5ffc0ff2f186d7454c5c4 Mon Sep 17 00:00:00 2001
From: Jeff Ames
Date: Wed, 28 May 2008 03:44:49 +0000
Subject: Formatting cleanup.
---
.../Modules/World/Archiver/TarArchive.cs | 82 +++++++++++-----------
1 file changed, 41 insertions(+), 41 deletions(-)
(limited to 'OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs')
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs
index 5e5be34..3a7518c 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchive.cs
@@ -34,16 +34,16 @@ using System.Reflection;
using log4net;
namespace OpenSim.Region.Environment
-{
+{
///
/// Temporary code to produce a tar archive in tar v7 format
- ///
+ ///
public class TarArchive
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
-
+
protected Dictionary m_files = new Dictionary();
-
+
protected static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding();
///
@@ -55,7 +55,7 @@ namespace OpenSim.Region.Environment
{
AddFile(filePath, m_asciiEncoding.GetBytes(data));
}
-
+
///
/// Add a file to the tar archive
///
@@ -65,117 +65,117 @@ namespace OpenSim.Region.Environment
{
m_files[filePath] = data;
}
-
+
///
/// Write the raw tar archive data to a file
///
///
public void WriteTar(string archivePath)
{
- BinaryWriter bw = new BinaryWriter(new FileStream(archivePath, FileMode.Create));
+ BinaryWriter bw = new BinaryWriter(new FileStream(archivePath, FileMode.Create));
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");
-
+
+ //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;
- Array.Copy(nameBytes, header, nameSize);
-
+ Array.Copy(nameBytes, header, nameSize);
+
// file mode (8)
byte[] modeBytes = m_asciiEncoding.GetBytes("0000644");
Array.Copy(modeBytes, 0, header, 100, 7);
-
+
// owner user id (8)
byte[] ownerIdBytes = m_asciiEncoding.GetBytes("0000764");
Array.Copy(ownerIdBytes, 0, header, 108, 7);
-
+
// group user id (8)
byte[] groupIdBytes = m_asciiEncoding.GetBytes("0000764");
Array.Copy(groupIdBytes, 0, header, 116, 7);
-
+
// file size in bytes (12)
int fileSize = data.Length;
m_log.DebugFormat("[TAR ARCHIVE]: File size of {0} is {1}", filePath, fileSize);
byte[] fileSizeBytes = ConvertDecimalToPaddedOctalBytes(fileSize, 11);
-
+
Array.Copy(fileSizeBytes, 0, header, 124, 11);
-
+
// last modification time (12)
byte[] lastModTimeBytes = m_asciiEncoding.GetBytes("11017037332");
- Array.Copy(lastModTimeBytes, 0, header, 136, 11);
-
+ Array.Copy(lastModTimeBytes, 0, header, 136, 11);
+
// link indicator (1)
//header[156] = m_asciiEncoding.GetBytes("0")[0];
header[156] = 0;
-
+
Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 329, 7);
Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 337, 7);
-
+
// check sum for header block (8) [calculated last]
Array.Copy(m_asciiEncoding.GetBytes(" "), 0, header, 148, 8);
-
+
int checksum = 0;
foreach (byte b in header)
{
checksum += b;
}
-
+
m_log.DebugFormat("[TAR ARCHIVE]: Decimal header checksum is {0}", checksum);
-
+
byte[] checkSumBytes = ConvertDecimalToPaddedOctalBytes(checksum, 6);
//byte[] checkSumBytes = m_asciiEncoding.GetBytes("007520");
-
+
Array.Copy(checkSumBytes, 0, header, 148, 6);
-
+
header[154] = 0;
-
- // Write out header
+
+ // Write out header
bw.Write(header);
-
+
// Write out data
bw.Write(data);
-
+
int paddingRequired = 512 - (data.Length % 512);
if (paddingRequired > 0)
{
m_log.DebugFormat("Padding data with {0} bytes", paddingRequired);
-
+
byte[] padding = new byte[paddingRequired];
bw.Write(padding);
}
}
-
+
// Write two consecutive 0 blocks to end the archive
byte[] finalZeroPadding = new byte[1024];
bw.Write(finalZeroPadding);
-
+
bw.Close();
}
-
+
public static byte[] ConvertDecimalToPaddedOctalBytes(int d, int padding)
{
- string oString = "";
-
+ string oString = "";
+
while (d > 0)
{
oString = Convert.ToString((byte)'0' + d & 7) + oString;
d >>= 3;
}
-
+
while (oString.Length < padding)
{
oString = "0" + oString;
- }
-
+ }
+
byte[] oBytes = m_asciiEncoding.GetBytes(oString);
-
+
return oBytes;
}
}
--
cgit v1.1