diff options
author | Justin Clarke Casey | 2008-05-30 15:18:40 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-05-30 15:18:40 +0000 |
commit | f26eeab3d4e3dd5f20d888479e70c984d9f11777 (patch) | |
tree | 1d4daf33c9412b844b681809b123e8c2a87355e1 | |
parent | while investigating why IRCBridgeModule.Close() was having no effect, i (diff) | |
download | opensim-SC-f26eeab3d4e3dd5f20d888479e70c984d9f11777.zip opensim-SC-f26eeab3d4e3dd5f20d888479e70c984d9f11777.tar.gz opensim-SC-f26eeab3d4e3dd5f20d888479e70c984d9f11777.tar.bz2 opensim-SC-f26eeab3d4e3dd5f20d888479e70c984d9f11777.tar.xz |
* Read all files from tar archive
* No reload functionality implemented yet
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs | 8 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs | 58 |
2 files changed, 55 insertions, 11 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs index c3f8d2b..268b9b5 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs | |||
@@ -56,9 +56,13 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
56 | // Just test for now by reading first file | 56 | // Just test for now by reading first file |
57 | string filePath = "ERROR"; | 57 | string filePath = "ERROR"; |
58 | 58 | ||
59 | byte[] data = archive.Read(out filePath); | 59 | byte[] data; |
60 | while ((data = archive.ReadEntry(out filePath)) != null) | ||
61 | { | ||
62 | m_log.DebugFormat("[ARCHIVER]: Successfully read {0} ({1} bytes) from archive {2}", filePath, data.Length, m_loadPath); | ||
63 | } | ||
60 | 64 | ||
61 | m_log.DebugFormat("[ARCHIVER]: Successfully read {0} ({1} bytes) from archive {2}", filePath, data.Length, m_loadPath); | 65 | m_log.DebugFormat("[ARCHIVER]: Reached end of archive"); |
62 | 66 | ||
63 | archive.Close(); | 67 | archive.Close(); |
64 | } | 68 | } |
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs index 80641e3..aacae95 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs | |||
@@ -27,8 +27,8 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | //using System.Reflection; | 30 | using System.Reflection; |
31 | //using log4net; | 31 | using log4net; |
32 | 32 | ||
33 | namespace OpenSim.Region.Environment.Modules.World.Archiver | 33 | namespace OpenSim.Region.Environment.Modules.World.Archiver |
34 | { | 34 | { |
@@ -37,9 +37,9 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
37 | /// </summary> | 37 | /// </summary> |
38 | public class TarArchiveReader | 38 | public class TarArchiveReader |
39 | { | 39 | { |
40 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 40 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
41 | 41 | ||
42 | protected static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding(); | 42 | protected static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding(); |
43 | 43 | ||
44 | /// <summary> | 44 | /// <summary> |
45 | /// Binary reader for the underlying stream | 45 | /// Binary reader for the underlying stream |
@@ -51,19 +51,59 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
51 | m_br = new BinaryReader(new FileStream(archivePath, FileMode.Open)); | 51 | m_br = new BinaryReader(new FileStream(archivePath, FileMode.Open)); |
52 | } | 52 | } |
53 | 53 | ||
54 | public byte[] Read(out string filePath) | 54 | /// <summary> |
55 | /// Are we at the end of the archive? | ||
56 | /// </summary> | ||
57 | /// <returns></returns> | ||
58 | public bool AtEof() | ||
59 | { | ||
60 | // If we've reached the end of the archive we'll be in null block territory, which means | ||
61 | // the next byte will be 0 | ||
62 | if (m_br.PeekChar() == 0) | ||
63 | return true; | ||
64 | |||
65 | return false; | ||
66 | } | ||
67 | |||
68 | /// <summary> | ||
69 | /// Read the next entry in the tar file. | ||
70 | /// </summary> | ||
71 | /// <param name="filePath"></param> | ||
72 | /// <returns>the data for the entry. Returns null if there are no more entries</returns> | ||
73 | public byte[] ReadEntry(out string filePath) | ||
55 | { | 74 | { |
56 | TarHeader header = ReadHeader(); | 75 | filePath = String.Empty; |
76 | |||
77 | if (AtEof()) | ||
78 | return null; | ||
79 | |||
80 | TarHeader header = ReadHeader(); | ||
81 | |||
57 | filePath = header.FilePath; | 82 | filePath = header.FilePath; |
58 | return m_br.ReadBytes(header.FileSize); | 83 | byte[] data = m_br.ReadBytes(header.FileSize); |
84 | |||
85 | m_log.DebugFormat("[TAR ARCHIVE READER]: filePath {0}, fileSize {1}", filePath, header.FileSize); | ||
86 | |||
87 | // Read the rest of the empty padding in the 512 byte block | ||
88 | if (header.FileSize % 512 != 0) | ||
89 | { | ||
90 | int paddingLeft = 512 - (header.FileSize % 512); | ||
91 | |||
92 | m_log.DebugFormat("[TAR ARCHIVE READER]: Reading {0} padding bytes", paddingLeft); | ||
93 | |||
94 | m_br.ReadBytes(paddingLeft); | ||
95 | } | ||
96 | |||
97 | return data; | ||
59 | } | 98 | } |
60 | 99 | ||
61 | /// <summary> | 100 | /// <summary> |
62 | /// Read the next 512 byte chunk of data as a tar header. | 101 | /// Read the next 512 byte chunk of data as a tar header. |
102 | /// This method assumes we are not at the end of the archive | ||
63 | /// </summary> | 103 | /// </summary> |
64 | /// <returns>A tar header struct</returns> | 104 | /// <returns>A tar header struct.</returns> |
65 | protected TarHeader ReadHeader() | 105 | protected TarHeader ReadHeader() |
66 | { | 106 | { |
67 | TarHeader tarHeader = new TarHeader(); | 107 | TarHeader tarHeader = new TarHeader(); |
68 | 108 | ||
69 | byte[] header = m_br.ReadBytes(512); | 109 | byte[] header = m_br.ReadBytes(512); |