Get UUIDGatherer to scan notecards in the graph for asset uuids.

This is to support npc baked texture saving in oars and iars.
May address http://opensimulator.org/mantis/view.php?id=5743
0.7.2-post-fixes
Justin Clark-Casey (justincc) 2011-10-22 02:16:46 +01:00
parent a6eba09dac
commit cf2405385d
5 changed files with 68 additions and 24 deletions

View File

@ -146,9 +146,9 @@ namespace OpenSim.Framework.Tests
Assert.IsFalse(Util.isUUID("FOOBAR67-89ab-Cdef-0123-456789AbCdEf"), Assert.IsFalse(Util.isUUID("FOOBAR67-89ab-Cdef-0123-456789AbCdEf"),
"UUIDs with non-hex characters are recognized as correct UUIDs."); "UUIDs with non-hex characters are recognized as correct UUIDs.");
Assert.IsFalse(Util.isUUID("01234567"), Assert.IsFalse(Util.isUUID("01234567"),
"Too short UUIDs are regognized as correct UUIDs."); "Too short UUIDs are recognized as correct UUIDs.");
Assert.IsFalse(Util.isUUID("01234567-89ab-Cdef-0123-456789AbCdEf0"), Assert.IsFalse(Util.isUUID("01234567-89ab-Cdef-0123-456789AbCdEf0"),
"Too long UUIDs are regognized as correct UUIDs."); "Too long UUIDs are recognized as correct UUIDs.");
Assert.IsFalse(Util.isUUID("01234567-89ab-Cdef-0123+456789AbCdEf"), Assert.IsFalse(Util.isUUID("01234567-89ab-Cdef-0123+456789AbCdEf"),
"UUIDs with wrong format are recognized as correct UUIDs."); "UUIDs with wrong format are recognized as correct UUIDs.");
} }

View File

@ -46,7 +46,6 @@ using System.Threading;
using log4net; using log4net;
using Nini.Config; using Nini.Config;
using Nwc.XmlRpc; using Nwc.XmlRpc;
// using BclExtras;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
using Amib.Threading; using Amib.Threading;
@ -91,8 +90,10 @@ namespace OpenSim.Framework
private static readonly DateTime unixEpoch = private static readonly DateTime unixEpoch =
DateTime.ParseExact("1970-01-01 00:00:00 +0", "yyyy-MM-dd hh:mm:ss z", DateTimeFormatInfo.InvariantInfo).ToUniversalTime(); DateTime.ParseExact("1970-01-01 00:00:00 +0", "yyyy-MM-dd hh:mm:ss z", DateTimeFormatInfo.InvariantInfo).ToUniversalTime();
public static readonly Regex UUIDPattern private static readonly string rawUUIDPattern
= new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
public static readonly Regex PermissiveUUIDPattern = new Regex(rawUUIDPattern);
public static readonly Regex UUIDPattern = new Regex(string.Format("^{0}$", rawUUIDPattern));
public static FireAndForgetMethod DefaultFireAndForgetMethod = FireAndForgetMethod.SmartThreadPool; public static FireAndForgetMethod DefaultFireAndForgetMethod = FireAndForgetMethod.SmartThreadPool;
public static FireAndForgetMethod FireAndForgetMethod = DefaultFireAndForgetMethod; public static FireAndForgetMethod FireAndForgetMethod = DefaultFireAndForgetMethod;

View File

@ -85,5 +85,31 @@ namespace OpenSim.Region.Framework.Scenes.Tests
// We count the uuid as gathered even if the asset itself is missing. // We count the uuid as gathered even if the asset itself is missing.
Assert.That(foundAssetUuids.Count, Is.EqualTo(1)); Assert.That(foundAssetUuids.Count, Is.EqualTo(1));
} }
[Test]
public void TestNotecardAsset()
{
TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure();
UUID ownerId = TestHelpers.ParseTail(0x10);
UUID soAssetId = TestHelpers.ParseTail(0x20);
UUID ncAssetId = TestHelpers.ParseTail(0x30);
SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, ownerId);
AssetBase soAsset = AssetHelpers.CreateAsset(soAssetId, so);
m_assetService.Store(soAsset);
AssetBase ncAsset = AssetHelpers.CreateNotecardAsset(ncAssetId, soAssetId.ToString());
m_assetService.Store(ncAsset);
IDictionary<UUID, AssetType> foundAssetUuids = new Dictionary<UUID, AssetType>();
m_uuidGatherer.GatherAssetUuids(ncAssetId, AssetType.Notecard, foundAssetUuids);
// We count the uuid as gathered even if the asset itself is corrupt.
Assert.That(foundAssetUuids.Count, Is.EqualTo(2));
Assert.That(foundAssetUuids.ContainsKey(ncAssetId));
Assert.That(foundAssetUuids.ContainsKey(soAssetId));
}
} }
} }

View File

@ -62,12 +62,12 @@ namespace OpenSim.Region.Framework.Scenes
/// Used as a temporary store of an asset which represents an object. This can be a null if no appropriate /// Used as a temporary store of an asset which represents an object. This can be a null if no appropriate
/// asset was found by the asset service. /// asset was found by the asset service.
/// </summary> /// </summary>
protected AssetBase m_requestedObjectAsset; private AssetBase m_requestedObjectAsset;
/// <summary> /// <summary>
/// Signal whether we are currently waiting for the asset service to deliver an asset. /// Signal whether we are currently waiting for the asset service to deliver an asset.
/// </summary> /// </summary>
protected bool m_waitingForObjectAsset; private bool m_waitingForObjectAsset;
public UuidGatherer(IAssetService assetCache) public UuidGatherer(IAssetService assetCache)
{ {
@ -103,9 +103,13 @@ namespace OpenSim.Region.Framework.Scenes
{ {
GetGestureAssetUuids(assetUuid, assetUuids); GetGestureAssetUuids(assetUuid, assetUuids);
} }
else if (AssetType.Notecard == assetType)
{
GetTextEmbeddedAssetUuids(assetUuid, assetUuids);
}
else if (AssetType.LSLText == assetType) else if (AssetType.LSLText == assetType)
{ {
GetScriptAssetUuids(assetUuid, assetUuids); GetTextEmbeddedAssetUuids(assetUuid, assetUuids);
} }
else if (AssetType.Object == assetType) else if (AssetType.Object == assetType)
{ {
@ -194,7 +198,7 @@ namespace OpenSim.Region.Framework.Scenes
/// <summary> /// <summary>
/// The callback made when we request the asset for an object from the asset service. /// The callback made when we request the asset for an object from the asset service.
/// </summary> /// </summary>
protected void AssetReceived(string id, Object sender, AssetBase asset) private void AssetReceived(string id, Object sender, AssetBase asset)
{ {
lock (this) lock (this)
{ {
@ -238,23 +242,25 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
/// <param name="scriptUuid"></param> /// <param name="scriptUuid"></param>
/// <param name="assetUuids">Dictionary in which to record the references</param> /// <param name="assetUuids">Dictionary in which to record the references</param>
protected void GetScriptAssetUuids(UUID scriptUuid, IDictionary<UUID, AssetType> assetUuids) private void GetTextEmbeddedAssetUuids(UUID embeddingAssetId, IDictionary<UUID, AssetType> assetUuids)
{ {
AssetBase scriptAsset = GetAsset(scriptUuid); m_log.DebugFormat("[ASSET GATHERER]: Getting assets for asset {0}", embeddingAssetId);
if (null != scriptAsset) AssetBase embeddingAsset = GetAsset(embeddingAssetId);
if (null != embeddingAsset)
{ {
string script = Utils.BytesToString(scriptAsset.Data); string script = Utils.BytesToString(embeddingAsset.Data);
//m_log.DebugFormat("[ARCHIVER]: Script {0}", script); m_log.DebugFormat("[ARCHIVER]: Script {0}", script);
MatchCollection uuidMatches = Util.UUIDPattern.Matches(script); MatchCollection uuidMatches = Util.PermissiveUUIDPattern.Matches(script);
//m_log.DebugFormat("[ARCHIVER]: Found {0} matches in script", uuidMatches.Count); m_log.DebugFormat("[ARCHIVER]: Found {0} matches in text", uuidMatches.Count);
foreach (Match uuidMatch in uuidMatches) foreach (Match uuidMatch in uuidMatches)
{ {
UUID uuid = new UUID(uuidMatch.Value); UUID uuid = new UUID(uuidMatch.Value);
//m_log.DebugFormat("[ARCHIVER]: Recording {0} in script", uuid); m_log.DebugFormat("[ARCHIVER]: Recording {0} in text", uuid);
// Assume AssetIDs embedded in scripts are textures // Assume AssetIDs embedded are textures.
assetUuids[uuid] = AssetType.Texture; assetUuids[uuid] = AssetType.Texture;
} }
} }
@ -265,7 +271,7 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
/// <param name="wearableAssetUuid"></param> /// <param name="wearableAssetUuid"></param>
/// <param name="assetUuids">Dictionary in which to record the references</param> /// <param name="assetUuids">Dictionary in which to record the references</param>
protected void GetWearableAssetUuids(UUID wearableAssetUuid, IDictionary<UUID, AssetType> assetUuids) private void GetWearableAssetUuids(UUID wearableAssetUuid, IDictionary<UUID, AssetType> assetUuids)
{ {
AssetBase assetBase = GetAsset(wearableAssetUuid); AssetBase assetBase = GetAsset(wearableAssetUuid);
@ -292,7 +298,7 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
/// <param name="sceneObject"></param> /// <param name="sceneObject"></param>
/// <param name="assetUuids"></param> /// <param name="assetUuids"></param>
protected void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary<UUID, AssetType> assetUuids) private void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary<UUID, AssetType> assetUuids)
{ {
AssetBase objectAsset = GetAsset(sceneObjectUuid); AssetBase objectAsset = GetAsset(sceneObjectUuid);
@ -321,7 +327,7 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
/// <param name="gestureUuid"></param> /// <param name="gestureUuid"></param>
/// <param name="assetUuids"></param> /// <param name="assetUuids"></param>
protected void GetGestureAssetUuids(UUID gestureUuid, IDictionary<UUID, AssetType> assetUuids) private void GetGestureAssetUuids(UUID gestureUuid, IDictionary<UUID, AssetType> assetUuids)
{ {
AssetBase assetBase = GetAsset(gestureUuid); AssetBase assetBase = GetAsset(gestureUuid);
if (null == assetBase) if (null == assetBase)

View File

@ -47,13 +47,24 @@ namespace OpenSim.Tests.Common
} }
/// <summary> /// <summary>
/// Create a notecard asset with a random uuid and dummy text. /// Create a notecard asset with dummy text and a random owner.
/// </summary> /// </summary>
/// <param name="assetId">/param> /// <param name="assetId">/param>
/// <returns></returns> /// <returns></returns>
public static AssetBase CreateNotecardAsset(UUID id) public static AssetBase CreateNotecardAsset(UUID assetId)
{ {
return CreateAsset(id, AssetType.Notecard, "hello", UUID.Random()); return CreateNotecardAsset(assetId, "hello");
}
/// <summary>
/// Create a notecard asset with a random owner.
/// </summary>
/// <param name="assetId">/param>
/// <param name="text"></param>
/// <returns></returns>
public static AssetBase CreateNotecardAsset(UUID assetId, string text)
{
return CreateAsset(assetId, AssetType.Notecard, text, UUID.Random());
} }
// /// <summary> // /// <summary>