Add --skip-assets option to load oar.

This allows you to load an oar without loading its assets.  This is useful if you know that the required assets are already in the asset service, since loading without assets is quicker.
This option will become more useful when the ability to save oars without assets is added, which should happen fairly soon.  At this point there will also be better documentation.
This commit is contained in:
Justin Clark-Casey (justincc)
2010-04-16 22:29:11 +01:00
parent cf46735856
commit bf3956aeb0
5 changed files with 50 additions and 28 deletions

View File

@@ -53,25 +53,30 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding();
private static UTF8Encoding m_utf8Encoding = new UTF8Encoding();
protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding();
protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding();
private Scene m_scene;
private Stream m_loadStream;
private Guid m_requestId;
private string m_errorMessage;
protected Scene m_scene;
protected Stream m_loadStream;
protected Guid m_requestId;
protected string m_errorMessage;
/// <value>
/// Should the archive being loaded be merged with what is already on the region?
/// </value>
private bool m_merge;
protected bool m_merge;
/// <value>
/// Should we ignore any assets when reloading the archive?
/// </value>
protected bool m_skipAssets;
/// <summary>
/// Used to cache lookups for valid uuids.
/// </summary>
private IDictionary<UUID, bool> m_validUserUuids = new Dictionary<UUID, bool>();
public ArchiveReadRequest(Scene scene, string loadPath, bool merge, Guid requestId)
public ArchiveReadRequest(Scene scene, string loadPath, bool merge, bool skipAssets, Guid requestId)
{
m_scene = scene;
@@ -89,14 +94,16 @@ namespace OpenSim.Region.CoreModules.World.Archiver
m_errorMessage = String.Empty;
m_merge = merge;
m_skipAssets = skipAssets;
m_requestId = requestId;
}
public ArchiveReadRequest(Scene scene, Stream loadStream, bool merge, Guid requestId)
public ArchiveReadRequest(Scene scene, Stream loadStream, bool merge, bool skipAssets, Guid requestId)
{
m_scene = scene;
m_loadStream = loadStream;
m_merge = merge;
m_skipAssets = skipAssets;
m_requestId = requestId;
}
@@ -135,7 +142,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{
serialisedSceneObjects.Add(m_utf8Encoding.GetString(data));
}
else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH) && !m_skipAssets)
{
if (LoadAsset(filePath, data))
successfulAssetRestores++;
@@ -178,12 +185,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver
archive.Close();
}
m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);
if (failedAssetRestores > 0)
if (!m_skipAssets)
{
m_log.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores);
m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores);
m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);
if (failedAssetRestores > 0)
{
m_log.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores);
m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores);
}
}
if (!m_merge)

View File

@@ -94,8 +94,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
public void HandleLoadOarConsoleCommand(string module, string[] cmdparams)
{
bool mergeOar = false;
bool skipAssets = false;
OptionSet options = new OptionSet().Add("m|merge", delegate (string v) { mergeOar = v != null; });
options.Add("s|skip-assets", delegate (string v) { skipAssets = v != null; });
List<string> mainParams = options.Parse(cmdparams);
// m_log.DebugFormat("MERGE OAR IS [{0}]", mergeOar);
@@ -105,11 +108,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
if (mainParams.Count > 2)
{
DearchiveRegion(mainParams[2], mergeOar, Guid.Empty);
DearchiveRegion(mainParams[2], mergeOar, skipAssets, Guid.Empty);
}
else
{
DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, mergeOar, Guid.Empty);
DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, mergeOar, skipAssets, Guid.Empty);
}
}
@@ -154,25 +157,25 @@ namespace OpenSim.Region.CoreModules.World.Archiver
public void DearchiveRegion(string loadPath)
{
DearchiveRegion(loadPath, false, Guid.Empty);
DearchiveRegion(loadPath, false, false, Guid.Empty);
}
public void DearchiveRegion(string loadPath, bool merge, Guid requestId)
public void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId)
{
m_log.InfoFormat(
"[ARCHIVER]: Loading archive to region {0} from {1}", m_scene.RegionInfo.RegionName, loadPath);
new ArchiveReadRequest(m_scene, loadPath, merge, requestId).DearchiveRegion();
new ArchiveReadRequest(m_scene, loadPath, merge, skipAssets, requestId).DearchiveRegion();
}
public void DearchiveRegion(Stream loadStream)
{
DearchiveRegion(loadStream, false, Guid.Empty);
DearchiveRegion(loadStream, false, false, Guid.Empty);
}
public void DearchiveRegion(Stream loadStream, bool merge, Guid requestId)
public void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId)
{
new ArchiveReadRequest(m_scene, loadStream, merge, requestId).DearchiveRegion();
new ArchiveReadRequest(m_scene, loadStream, merge, skipAssets, requestId).DearchiveRegion();
}
}
}

View File

@@ -442,7 +442,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
byte[] archive = archiveWriteStream.ToArray();
MemoryStream archiveReadStream = new MemoryStream(archive);
m_archiverModule.DearchiveRegion(archiveReadStream, true, Guid.Empty);
m_archiverModule.DearchiveRegion(archiveReadStream, true, false, Guid.Empty);
SceneObjectPart object1Existing = m_scene.GetSceneObjectPart(part1.Name);
Assert.That(object1Existing, Is.Not.Null, "object1 was not present after merge");