Implement the "delete" path for assets. Adds a new option to allow remote asset deletion in robust handler.

slimupdates2
Melanie 2010-05-09 17:56:52 +01:00
parent 9b22393cf3
commit 60357d3778
11 changed files with 60 additions and 6 deletions

View File

@ -48,5 +48,6 @@ namespace OpenSim.Data
public abstract void Initialise(string connect); public abstract void Initialise(string connect);
public abstract void Initialise(); public abstract void Initialise();
public abstract void Dispose(); public abstract void Dispose();
public abstract bool Delete(string id);
} }
} }

View File

@ -38,6 +38,7 @@ namespace OpenSim.Data
bool ExistsAsset(UUID uuid); bool ExistsAsset(UUID uuid);
List<AssetMetadata> FetchAssetMetadataSet(int start, int count); List<AssetMetadata> FetchAssetMetadataSet(int start, int count);
void Initialise(string connect); void Initialise(string connect);
bool Delete(string id);
} }
public class AssetDataInitialiser : PluginInitialiserBase public class AssetDataInitialiser : PluginInitialiserBase

View File

@ -322,6 +322,10 @@ namespace OpenSim.Data.MSSQL
return retList; return retList;
} }
public override bool Delete(string id)
{
return false;
}
#endregion #endregion
} }
} }

View File

@ -338,6 +338,24 @@ namespace OpenSim.Data.MySQL
return retList; return retList;
} }
public override bool Delete(string id)
{
lock (m_dbLock)
{
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
MySqlCommand cmd = new MySqlCommand("delete from assets where id=?id");
cmd.Parameters.AddWithValue("?id", id);
cmd.ExecuteNonQuery();
cmd.Dispose();
}
}
return true;
}
#endregion #endregion
} }
} }

View File

@ -338,6 +338,11 @@ namespace OpenSim.Data.SQLite
get { return "SQLite Asset storage engine"; } get { return "SQLite Asset storage engine"; }
} }
public override bool Delete(string id)
{
return false;
}
#endregion #endregion
} }
} }

View File

@ -338,6 +338,10 @@ namespace OpenSim.Data.SQLiteLegacy
get { return "SQLite Asset storage engine"; } get { return "SQLite Asset storage engine"; }
} }
public override bool Delete(string id)
{
return false;
}
#endregion #endregion
} }
} }

View File

@ -59,9 +59,11 @@ namespace OpenSim.Server.Handlers.Asset
m_AssetService = m_AssetService =
ServerUtils.LoadPlugin<IAssetService>(assetService, args); ServerUtils.LoadPlugin<IAssetService>(assetService, args);
bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false);
server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); server.AddStreamHandler(new AssetServerGetHandler(m_AssetService));
server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); server.AddStreamHandler(new AssetServerPostHandler(m_AssetService));
server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService)); server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete));
} }
} }
} }

View File

@ -47,11 +47,13 @@ namespace OpenSim.Server.Handlers.Asset
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IAssetService m_AssetService; private IAssetService m_AssetService;
protected bool m_allowDelete;
public AssetServerDeleteHandler(IAssetService service) : public AssetServerDeleteHandler(IAssetService service, bool allowDelete) :
base("DELETE", "/assets") base("DELETE", "/assets")
{ {
m_AssetService = service; m_AssetService = service;
m_allowDelete = allowDelete;
} }
public override byte[] Handle(string path, Stream request, public override byte[] Handle(string path, Stream request,
@ -61,9 +63,9 @@ namespace OpenSim.Server.Handlers.Asset
string[] p = SplitParams(path); string[] p = SplitParams(path);
if (p.Length > 0) if (p.Length > 0 && m_allowDelete)
{ {
// result = m_AssetService.Delete(p[0]); result = m_AssetService.Delete(p[0]);
} }
XmlSerializer xs = new XmlSerializer(typeof(bool)); XmlSerializer xs = new XmlSerializer(typeof(bool));

View File

@ -156,6 +156,17 @@ namespace OpenSim.Services.AssetService
public bool Delete(string id) public bool Delete(string id)
{ {
UUID assetID;
if (!UUID.TryParse(id, out assetID))
return false;
AssetBase asset = m_Database.GetAsset(assetID);
if (asset == null)
return false;
if ((int)(asset.Flags & AssetFlags.Maptile) != 0)
return m_Database.Delete(id);
return false; return false;
} }

View File

@ -60,5 +60,10 @@ namespace OpenSim.Tests.Common.Mock
} }
public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) { return new List<AssetMetadata>(count); } public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) { return new List<AssetMetadata>(count); }
public bool Delete(string id)
{
return false;
}
} }
} }

View File

@ -40,6 +40,7 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
LocalServiceModule = "OpenSim.Services.AssetService.dll:AssetService" LocalServiceModule = "OpenSim.Services.AssetService.dll:AssetService"
DefaultAssetLoader = "OpenSim.Framework.AssetLoader.Filesystem.dll" DefaultAssetLoader = "OpenSim.Framework.AssetLoader.Filesystem.dll"
AssetLoaderArgs = "assets/AssetSets.xml" AssetLoaderArgs = "assets/AssetSets.xml"
AllowRemoteDelete = "false"
; * This configuration loads the inventory server modules. It duplicates ; * This configuration loads the inventory server modules. It duplicates
; * the function of the legacy inventory server ; * the function of the legacy inventory server