Add "dump asset" command to the asset service for debugging purposes.

This command dumps the asset with the given id to a file with the same name.
bulletsim
Justin Clark-Casey (justincc) 2011-05-06 00:09:08 +01:00
parent 1bdac6ed19
commit bc49a0bc5d
1 changed files with 43 additions and 0 deletions

View File

@ -26,9 +26,12 @@
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Nini.Config;
using log4net;
using NDesk.Options;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Data;
@ -61,6 +64,13 @@ namespace OpenSim.Services.AssetService
"delete asset <ID>",
"Delete asset from database", HandleDeleteAsset);
MainConsole.Instance.Commands.AddCommand("kfs", false,
"dump asset",
"dump asset <ID>",
"Dump asset to a file",
"The filename is the same as the ID given.",
HandleDumpAsset);
if (m_AssetLoader != null)
{
IConfig assetConfig = config.Configs["AssetService"];
@ -190,6 +200,39 @@ namespace OpenSim.Services.AssetService
return false;
}
void HandleDumpAsset(string module, string[] args)
{
if (args.Length < 3)
{
MainConsole.Instance.Output("Usage is dump asset <ID>");
return;
}
string rawAssetId = args[2];
UUID assetId;
if (!UUID.TryParse(rawAssetId, out assetId))
{
MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid ID format", rawAssetId);
return;
}
AssetBase asset = m_Database.GetAsset(assetId);
if (asset == null)
{
MainConsole.Instance.OutputFormat("ERROR: No asset found with ID {0}", assetId);
return;
}
using (FileStream fs = new FileStream(rawAssetId, FileMode.CreateNew))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
bw.Write(asset.Data);
}
}
}
void HandleShowDigest(string module, string[] args)
{
if (args.Length < 3)