diff --git a/CommandLib/export.cs b/CommandLib/export.cs
index 759cbed30..9400002cf 100644
--- a/CommandLib/export.cs
+++ b/CommandLib/export.cs
@@ -73,12 +73,19 @@ namespace CommandLib
private readonly XXHash64 _xxHash = new XXHash64();
- public static bool verbose_debugging = false;
+ private readonly bool _quiet;
- private static void debug(string x)
+ public Export(bool quiet = false)
{
- if (verbose_debugging)
- Console.WriteLine(x);
+ _quiet = quiet;
+ }
+
+ private void Debug(string x)
+ {
+ if (_quiet)
+ return;
+
+ Console.WriteLine(x);
}
private string checksum_sha1(byte[] data)
@@ -108,7 +115,7 @@ namespace CommandLib
return hex(_xxHash.ComputeHash(data));
}
- private static Hashtable parse_checksum_table(string checksum_xml)
+ private Hashtable parse_checksum_table(string checksum_xml)
{
Hashtable table = new Hashtable();
@@ -130,14 +137,14 @@ namespace CommandLib
value = v.Value;
}
- debug(String.Format("adding {0} = {1}", name, value));
+ Debug(String.Format("adding {0} = {1}", name, value));
table.Add(name, value);
}
return table;
}
- private static void compare_tables(Hashtable recomputed, Hashtable original)
+ private void compare_tables(Hashtable recomputed, Hashtable original)
{
foreach (DictionaryEntry x in recomputed)
{
@@ -149,7 +156,7 @@ namespace CommandLib
}
else
{
- debug(String.Format("{0} hash OK", (string)x.Key));
+ Debug(String.Format("{0} hash OK", (string)x.Key));
}
}
}
@@ -162,20 +169,16 @@ namespace CommandLib
return new string(chars);
}
- public delegate void verifyCallback(uint read);
-
- public delegate bool cancellingCallback();
-
///
/// 'input' is the source of the export data, if 'output' is not null then
/// a perfect copy should be echoed there.
///
- public void verify(Stream input, Stream output, cancellingCallback cancelling)
+ public void verify(Stream input, Stream output, Func cancelling)
{
verify(input, output, cancelling, null);
}
- private Header nextHeader(Stream input, Stream output, verifyCallback callback)
+ private Header nextHeader(Stream input, Stream output, Action callback)
{
// Interperate the next bytes from the stream as a Tar header
byte[] bytes = nextData(input, output, callback, Header.length);
@@ -194,7 +197,7 @@ namespace CommandLib
return new Header(bytes);
}
- private byte[] nextData(Stream input, Stream output, verifyCallback callback, uint size)
+ private byte[] nextData(Stream input, Stream output, Action callback, uint size)
{
// Returns the next given number of bytes from the input
byte[] bytes = IO.unmarshal_n(input, size);
@@ -203,7 +206,7 @@ namespace CommandLib
return bytes;
}
- public void verify(Stream input, Stream output, cancellingCallback cancelling, verifyCallback callback)
+ public void verify(Stream input, Stream output, Func cancelling, Action callback)
{
Hashtable recomputed_checksums = new Hashtable();
Hashtable original_checksums = null;
@@ -213,13 +216,13 @@ namespace CommandLib
while (!cancelling())
{
Header header_data = nextHeader(input, output, callback);
- debug(header_data.ToString());
+ Debug(header_data.ToString());
byte[] bytes_data = nextData(input, output, callback, header_data.file_size);
if (header_data.file_name.Equals("ova.xml"))
{
- debug("Skipping ova.xml");
+ Debug("Skipping ova.xml");
}
else if (header_data.file_name.EndsWith("checksum.xml"))
{
@@ -238,7 +241,7 @@ namespace CommandLib
if (!csum.Equals(csum_compare))
throw new BlockChecksumFailed(header_data.file_name, csum, csum_compare);
- debug(String.Format(" has checksum: {0}", csum));
+ Debug(String.Format(" has checksum: {0}", csum));
recomputed_checksums.Add(header_data.file_name, csum);
nextData(input, output, callback, header_checksum.paddingLength()); // Eat the padding for the checksum file
@@ -249,7 +252,7 @@ namespace CommandLib
}
catch (EndOfArchive)
{
- debug("EOF");
+ Debug("EOF");
if (original_checksums != null)
compare_tables(recomputed_checksums, original_checksums);
}
diff --git a/CommandLib/io.cs b/CommandLib/io.cs
index f5a179bb4..7b69cac32 100644
--- a/CommandLib/io.cs
+++ b/CommandLib/io.cs
@@ -58,17 +58,5 @@ namespace CommandLib
unmarshal_n_into(stream, n, buffer);
return buffer;
}
-
- public static void skip(Stream stream, uint n)
- {
- byte[] buffer = new byte[63356];
- while (n > 0)
- {
- uint toread = (uint)buffer.Length;
- if (n < toread) toread = n;
- unmarshal_n_into(stream, toread, buffer);
- n -= toread;
- }
- }
}
}
diff --git a/CommandLib/tar.cs b/CommandLib/tar.cs
index 2df96ce2b..97568fd01 100644
--- a/CommandLib/tar.cs
+++ b/CommandLib/tar.cs
@@ -30,7 +30,6 @@
*/
using System;
-using System.IO;
using System.Text;
namespace CommandLib
@@ -63,10 +62,6 @@ namespace CommandLib
///
class EndOfArchive : ApplicationException
{
- public EndOfArchive()
- {
- }
-
public override string ToString()
{
return "End of tar archive";
@@ -234,44 +229,5 @@ namespace CommandLib
throw new HeaderChecksumFailed(recomputed, chksum);
}
-
- ///
- /// Read a tar header from a stream
- ///
- public static Header fromStream(Stream input)
- {
- byte[] one = IO.unmarshal_n(input, length);
- if (all_zeroes(one))
- {
- byte[] two = IO.unmarshal_n(input, length);
- if (all_zeroes(two))
- throw new EndOfArchive();
- return new Header(two);
- }
-
- return new Header(one);
- }
- }
-
- public class Archive
- {
- public static void list(Stream stream)
- {
- try
- {
- while (true)
- {
- Header x = Header.fromStream(stream);
- Console.WriteLine(x);
- IO.skip(stream, x.file_size);
- IO.skip(stream, x.paddingLength());
- }
-
- }
- catch (EndOfArchive)
- {
- Console.WriteLine("EOF");
- }
- }
}
}
diff --git a/XenModel/Actions/VM/ExportVmAction.cs b/XenModel/Actions/VM/ExportVmAction.cs
index eaa88779d..625ecb143 100644
--- a/XenModel/Actions/VM/ExportVmAction.cs
+++ b/XenModel/Actions/VM/ExportVmAction.cs
@@ -110,7 +110,7 @@ namespace XenAdmin.Actions
log.DebugFormat("Exporting {0} to {1}", VM.Name(), _filename);
// The DownloadFile call will block, so we need a separate thread to poll for task status.
- Thread taskThread = new Thread(progressPoll);
+ Thread taskThread = new Thread(ProgressPoll);
taskThread.Name = "Progress polling thread for ExportVmAction for " + VM.Name().Ellipsise(20);
taskThread.IsBackground = true;
taskThread.Start();
@@ -156,7 +156,7 @@ namespace XenAdmin.Actions
int i = 0;
long filesize = new FileInfo(tmpFile).Length / 50; //Div by 50 to save doing the * 50 in the callback
- Export.verifyCallback callback = size =>
+ void Callback(uint size)
{
read += size;
i++;
@@ -168,7 +168,7 @@ namespace XenAdmin.Actions
PercentComplete = 50 + (int)(read / filesize);
i = 0;
}
- };
+ }
try
{
@@ -178,7 +178,7 @@ namespace XenAdmin.Actions
this.Description = Messages.ACTION_EXPORT_VERIFY;
export = new Export();
- export.verify(fs, null, () => Cancelling, callback);
+ export.verify(fs, null, () => Cancelling, Callback);
}
}
catch (Exception e)
@@ -246,8 +246,6 @@ namespace XenAdmin.Actions
}
}
-
-
private void HttpGet(string filename, Uri uri)
{
using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
@@ -259,7 +257,7 @@ namespace XenAdmin.Actions
}
}
- private void progressPoll()
+ private void ProgressPoll()
{
try
{
diff --git a/xva_verify/verify_main.cs b/xva_verify/verify_main.cs
index 93c68b346..5513ffbd6 100644
--- a/xva_verify/verify_main.cs
+++ b/xva_verify/verify_main.cs
@@ -32,6 +32,7 @@
using System;
using System.IO;
using System.IO.Compression;
+using System.Linq;
using System.Text;
using CommandLib;
@@ -41,30 +42,34 @@ namespace xva_verify
{
public static void Main(string[] args)
{
- Export.verbose_debugging = true;
- if (args.Length < 1 || args.Length > 2)
+ if (args.Length < 1 || args.Length > 3)
{
var sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("Usage").AppendLine();
- sb.AppendLine(" xva_verify []").AppendLine();
+ sb.AppendLine(" xva_verify [ -q]").AppendLine();
sb.AppendLine("where").AppendLine();
sb.AppendLine(" The name of the archive file to verify. Use '-' to read from stdin.");
- sb.AppendLine(" If specified, a copy of the archive file is created with this name.").AppendLine();
+ sb.AppendLine(" If specified, a copy of the archive file is created with this name.");
+ sb.AppendLine(" -q If specified, it switches off verbose debugging.");
+ sb.AppendLine();
Console.WriteLine(sb.ToString());
Environment.Exit(1);
}
+ bool quiet = args.Contains("-q");
+ var fileArgs = args.Where(a => a != "-q").ToArray();
+
try
{
- string filename = args[0];
+ string filename = fileArgs[0];
Stream g = null;
- if (args.Length == 2)
- g = new FileStream(args[1], FileMode.Create);
+ if (fileArgs.Length > 1)
+ g = new FileStream(fileArgs[1], FileMode.Create);
- Stream f = args[0].Equals("-")
+ Stream f = fileArgs[0].Equals("-")
? Console.OpenStandardInput()
: new FileStream(filename, FileMode.Open, FileAccess.Read);
@@ -88,7 +93,7 @@ namespace xva_verify
}
}
- new Export().verify(f, g, () => false);
+ new Export(quiet).verify(f, g, () => false);
}
catch(UnauthorizedAccessException)
{
diff --git a/xva_verify/xva_verify.csproj b/xva_verify/xva_verify.csproj
index 91f4f9793..b43b1c32e 100755
--- a/xva_verify/xva_verify.csproj
+++ b/xva_verify/xva_verify.csproj
@@ -62,7 +62,7 @@
-
+