Merge branch 'master' of ssh://MyConnection/var/git/opensim

remotes/origin/0.6.7-post-fixes
Teravus Ovares (Dan Olivares) 2009-09-08 04:43:17 -04:00
commit f0e2fd426b
12 changed files with 488 additions and 144 deletions

View File

@ -154,10 +154,10 @@ namespace OpenSim.Data.Tests
);
}
[Test]
private void T012_EstateSettingsRandomStorage()
//[Test]
// Currently fails occasionally
public void T012_EstateSettingsRandomStorage()
{
// Letting estate store generate rows to database for us
EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID);
new PropertyScrambler<EstateSettings>().Scramble(originalSettings);

View File

@ -42,6 +42,7 @@ using OpenSim.Framework.Communications.Osp;
using OpenSim.Framework.Serialization;
using OpenSim.Framework.Serialization.External;
using OpenSim.Region.CoreModules.World.Archiver;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
@ -55,32 +56,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
private CachedUserInfo m_userInfo;
private string m_invPath;
/// <value>
/// We only use this to request modules
/// </value>
protected Scene m_scene;
/// <value>
/// The stream from which the inventory archive will be loaded.
/// </value>
private Stream m_loadStream;
protected CommunicationsManager m_commsManager;
protected IAssetService m_assetService;
public InventoryArchiveReadRequest(
CachedUserInfo userInfo, string invPath, string loadPath, CommunicationsManager commsManager, IAssetService assetService)
Scene scene, CachedUserInfo userInfo, string invPath, string loadPath)
: this(
scene,
userInfo,
invPath,
new GZipStream(new FileStream(loadPath, FileMode.Open), CompressionMode.Decompress),
commsManager, assetService)
new GZipStream(new FileStream(loadPath, FileMode.Open), CompressionMode.Decompress))
{
}
public InventoryArchiveReadRequest(
CachedUserInfo userInfo, string invPath, Stream loadStream, CommunicationsManager commsManager, IAssetService assetService)
Scene scene, CachedUserInfo userInfo, string invPath, Stream loadStream)
{
m_scene = scene;
m_userInfo = userInfo;
m_invPath = invPath;
m_loadStream = loadStream;
m_commsManager = commsManager;
m_assetService = assetService;
}
/// <summary>
@ -98,6 +100,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
int successfulItemRestores = 0;
List<InventoryNodeBase> nodesLoaded = new List<InventoryNodeBase>();
/*
if (!m_userInfo.HasReceivedInventory)
{
// If the region server has access to the user admin service (by which users are created),
@ -106,7 +109,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
//
// FIXME: FetchInventory should probably be assumed to by async anyway, since even standalones might
// use a remote inventory service, though this is vanishingly rare at the moment.
if (null == m_commsManager.UserAdminService)
if (null == m_scene.CommsManager.UserAdminService)
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}",
@ -125,8 +128,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
}
}
*/
InventoryFolderImpl rootDestinationFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath);
//InventoryFolderImpl rootDestinationFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath);
InventoryFolderBase rootDestinationFolder
= InventoryArchiveUtils.FindFolderByPath(
m_scene.InventoryService, m_userInfo.UserProfile.ID, m_invPath);
if (null == rootDestinationFolder)
{
@ -140,7 +147,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
// In order to load identically named folders, we need to keep track of the folders that we have already
// created
Dictionary <string, InventoryFolderImpl> foldersCreated = new Dictionary<string, InventoryFolderImpl>();
Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>();
byte[] data;
TarArchiveReader.TarEntryType entryType;
@ -155,7 +162,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH))
{
InventoryFolderImpl foundFolder
InventoryFolderBase foundFolder
= ReplicateArchivePathToUserInventory(
filePath, TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType,
rootDestinationFolder, foldersCreated, nodesLoaded);
@ -167,7 +174,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
// Don't use the item ID that's in the file
item.ID = UUID.Random();
UUID ospResolvedId = OspResolver.ResolveOspa(item.CreatorId, m_commsManager);
UUID ospResolvedId = OspResolver.ResolveOspa(item.CreatorId, m_scene.CommsManager);
if (UUID.Zero != ospResolvedId)
item.CreatorIdAsUuid = ospResolvedId;
@ -176,7 +183,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
// Reset folder ID to the one in which we want to load it
item.Folder = foundFolder.ID;
m_userInfo.AddItem(item);
//m_userInfo.AddItem(item);
m_scene.InventoryService.AddItem(item);
successfulItemRestores++;
// If we're loading an item directly into the given destination folder then we need to record
@ -209,11 +217,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// chain, only the root node needs to be recorded
/// </param>
/// <returns>The last user inventory folder created or found for the archive path</returns>
public InventoryFolderImpl ReplicateArchivePathToUserInventory(
public InventoryFolderBase ReplicateArchivePathToUserInventory(
string fsPath,
bool isDir,
InventoryFolderImpl rootDestinationFolder,
Dictionary <string, InventoryFolderImpl> foldersCreated,
InventoryFolderBase rootDestFolder,
Dictionary <string, InventoryFolderBase> foldersCreated,
List<InventoryNodeBase> nodesLoaded)
{
fsPath = fsPath.Substring(ArchiveConstants.INVENTORY_PATH.Length);
@ -226,17 +234,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
m_log.DebugFormat("[INVENTORY ARCHIVER]: Loading to folder {0}", fsPath);
InventoryFolderImpl foundFolder = null;
InventoryFolderBase destFolder = null;
// XXX: Nasty way of dealing with a path that has no directory component
if (fsPath.Length > 0)
{
while (null == foundFolder && fsPath.Length > 0)
while (null == destFolder && fsPath.Length > 0)
{
if (foldersCreated.ContainsKey(fsPath))
{
m_log.DebugFormat("[INVENTORY ARCHIVER]: Found previously created fs path {0}", fsPath);
foundFolder = foldersCreated[fsPath];
destFolder = foldersCreated[fsPath];
}
else
{
@ -253,14 +261,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
"[INVENTORY ARCHIVER]: Found no previously created fs path for {0}",
originalFsPath);
fsPath = string.Empty;
foundFolder = rootDestinationFolder;
destFolder = rootDestFolder;
}
}
}
}
else
{
foundFolder = rootDestinationFolder;
destFolder = rootDestFolder;
}
string fsPathSectionToCreate = originalFsPath.Substring(fsPath.Length);
@ -275,30 +283,39 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
int identicalNameIdentifierIndex
= rawDirsToCreate[i].LastIndexOf(
ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR);
string folderName = rawDirsToCreate[i].Remove(identicalNameIdentifierIndex);
string newFolderName = rawDirsToCreate[i].Remove(identicalNameIdentifierIndex);
UUID newFolderId = UUID.Random();
m_userInfo.CreateFolder(
folderName, newFolderId, (ushort)AssetType.Folder, foundFolder.ID);
m_log.DebugFormat("[INVENTORY ARCHIVER]: Retrieving newly created folder {0}", folderName);
foundFolder = foundFolder.GetChildFolder(newFolderId);
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Retrieved newly created folder {0} with ID {1}",
foundFolder.Name, foundFolder.ID);
destFolder
= new InventoryFolderBase(
newFolderId, newFolderName, m_userInfo.UserProfile.ID,
(short)AssetType.Folder, destFolder.ID, 0);
m_scene.InventoryService.AddFolder(destFolder);
// UUID newFolderId = UUID.Random();
// m_scene.InventoryService.AddFolder(
// m_userInfo.CreateFolder(
// folderName, newFolderId, (ushort)AssetType.Folder, foundFolder.ID);
// m_log.DebugFormat("[INVENTORY ARCHIVER]: Retrieving newly created folder {0}", folderName);
// foundFolder = foundFolder.GetChildFolder(newFolderId);
// m_log.DebugFormat(
// "[INVENTORY ARCHIVER]: Retrieved newly created folder {0} with ID {1}",
// foundFolder.Name, foundFolder.ID);
// Record that we have now created this folder
fsPath += rawDirsToCreate[i] + "/";
m_log.DebugFormat("[INVENTORY ARCHIVER]: Recording creation of fs path {0}", fsPath);
foldersCreated[fsPath] = foundFolder;
foldersCreated[fsPath] = destFolder;
if (0 == i)
nodesLoaded.Add(foundFolder);
nodesLoaded.Add(destFolder);
i++;
}
return foundFolder;
return destFolder;
/*
string[] rawFolders = filePath.Split(new char[] { '/' });
@ -371,7 +388,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
asset.Type = assetType;
asset.Data = data;
m_assetService.Store(asset);
m_scene.AssetService.Store(asset);
return true;
}

View File

@ -0,0 +1,212 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Services.Interfaces;
namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
/// <summary>
/// Utility methods for inventory archiving
/// </summary>
public static class InventoryArchiveUtils
{
public static readonly string PATH_DELIMITER = "/";
/// <summary>
/// Find a folder given a PATH_DELIMITER delimited path starting from a user's root folder
/// </summary>
///
/// This method does not handle paths that contain multiple delimitors
///
/// FIXME: We do not yet handle situations where folders have the same name. We could handle this by some
/// XPath like expression
///
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
///
/// <param name="inventoryService">
/// Inventory service to query
/// </param>
/// <param name="userId">
/// User id to search
/// </param>
/// <param name="path">
/// The path to the required folder.
/// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
/// </param>
/// <returns>null if the folder is not found</returns>
public static InventoryFolderBase FindFolderByPath(
IInventoryService inventoryService, UUID userId, string path)
{
InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
if (null == rootFolder)
return null;
return FindFolderByPath(inventoryService, rootFolder, path);
}
/// <summary>
/// Find a folder given a PATH_DELIMITER delimited path starting from this folder
/// </summary>
///
/// This method does not handle paths that contain multiple delimitors
///
/// FIXME: We do not yet handle situations where folders have the same name. We could handle this by some
/// XPath like expression
///
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
///
/// <param name="inventoryService">
/// Inventory service to query
/// </param>
/// <param name="startFolder">
/// The folder from which the path starts
/// </param>
/// <param name="path">
/// The path to the required folder.
/// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
/// </param>
/// <returns>null if the folder is not found</returns>
public static InventoryFolderBase FindFolderByPath(
IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
{
if (path == string.Empty)
return startFolder;
path = path.Trim();
if (path == PATH_DELIMITER)
return startFolder;
InventoryFolderBase foundFolder = null;
string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID);
foreach (InventoryFolderBase folder in contents.Folders)
{
if (folder.Name == components[0])
{
if (components.Length > 1)
return FindFolderByPath(inventoryService, foundFolder, components[1]);
else
return folder;
}
}
// We didn't find a folder with the right name
return null;
}
/// <summary>
/// Find an item given a PATH_DELIMITOR delimited path starting from the user's root folder.
///
/// This method does not handle paths that contain multiple delimitors
///
/// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some
/// XPath like expression
///
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
/// </summary>
///
/// <param name="inventoryService">
/// Inventory service to query
/// </param>
/// <param name="userId">
/// The user to search
/// </param>
/// <param name="path">
/// The path to the required item.
/// </param>
/// <returns>null if the item is not found</returns>
public static InventoryItemBase FindItemByPath(
IInventoryService inventoryService, UUID userId, string path)
{
InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
if (null == rootFolder)
return null;
return FindItemByPath(inventoryService, rootFolder, path);
}
/// <summary>
/// Find an item given a PATH_DELIMITOR delimited path starting from this folder.
///
/// This method does not handle paths that contain multiple delimitors
///
/// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some
/// XPath like expression
///
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
/// </summary>
///
/// <param name="inventoryService">
/// Inventory service to query
/// </param>
/// <param name="startFolder">
/// The folder from which the path starts
/// </param>
/// <param name="path">
/// <param name="path">
/// The path to the required item.
/// </param>
/// <returns>null if the item is not found</returns>
public static InventoryItemBase FindItemByPath(
IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
{
string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
if (components.Length == 1)
{
List<InventoryItemBase> items = inventoryService.GetFolderItems(startFolder.Owner, startFolder.ID);
foreach (InventoryItemBase item in items)
{
if (item.Name == components[0])
return item;
}
}
else
{
InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID);
foreach (InventoryFolderBase folder in contents.Folders)
{
if (folder.Name == components[0])
return FindItemByPath(inventoryService, folder, components[1]);
}
}
// We didn't find an item or intermediate folder with the given name
return null;
}
}
}

View File

@ -59,6 +59,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
protected TarArchiveWriter m_archiveWriter;
protected UuidGatherer m_assetGatherer;
/// <value>
/// We only use this to request modules
/// </value>
protected Scene m_scene;
/// <value>
/// ID of this request
/// </value>
@ -83,10 +88,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// Constructor
/// </summary>
public InventoryArchiveWriteRequest(
Guid id, InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, string savePath)
Guid id, InventoryArchiverModule module, Scene scene,
CachedUserInfo userInfo, string invPath, string savePath)
: this(
id,
module,
scene,
userInfo,
invPath,
new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress))
@ -97,14 +104,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// Constructor
/// </summary>
public InventoryArchiveWriteRequest(
Guid id, InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, Stream saveStream)
Guid id, InventoryArchiverModule module, Scene scene,
CachedUserInfo userInfo, string invPath, Stream saveStream)
{
m_id = id;
m_module = module;
m_scene = scene;
m_userInfo = userInfo;
m_invPath = invPath;
m_saveStream = saveStream;
m_assetGatherer = new UuidGatherer(m_module.AssetService);
m_assetGatherer = new UuidGatherer(m_scene.AssetService);
}
protected void ReceivedAllAssets(ICollection<UUID> assetsFoundUuids, ICollection<UUID> assetsNotFoundUuids)
@ -135,7 +144,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
m_userUuids[inventoryItem.CreatorIdAsUuid] = 1;
InventoryItemBase saveItem = (InventoryItemBase)inventoryItem.Clone();
saveItem.CreatorId = OspResolver.MakeOspa(saveItem.CreatorIdAsUuid, m_module.CommsManager);
saveItem.CreatorId = OspResolver.MakeOspa(saveItem.CreatorIdAsUuid, m_scene.CommsManager);
string serialization = UserInventoryItemSerializer.Serialize(saveItem);
m_archiveWriter.WriteFile(filename, serialization);
@ -149,7 +158,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// <param name="inventoryFolder">The inventory folder to save</param>
/// <param name="path">The path to which the folder should be saved</param>
/// <param name="saveThisFolderItself">If true, save this folder itself. If false, only saves contents</param>
protected void SaveInvFolder(InventoryFolderImpl inventoryFolder, string path, bool saveThisFolderItself)
protected void SaveInvFolder(InventoryFolderBase inventoryFolder, string path, bool saveThisFolderItself)
{
if (saveThisFolderItself)
{
@ -164,15 +173,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
m_archiveWriter.WriteDir(path);
}
List<InventoryFolderImpl> childFolders = inventoryFolder.RequestListOfFolderImpls();
List<InventoryItemBase> items = inventoryFolder.RequestListOfItems();
InventoryCollection contents
= m_scene.InventoryService.GetFolderContent(inventoryFolder.Owner, inventoryFolder.ID);
//List<InventoryFolderImpl> childFolders = inventoryFolder.RequestListOfFolderImpls();
//List<InventoryItemBase> items = inventoryFolder.RequestListOfItems();
/*
Dictionary identicalFolderNames = new Dictionary<string, int>();
foreach (InventoryFolderImpl folder in inventories)
{
if (!identicalFolderNames.ContainsKey(folder.Name))
identicalFolderNames[folder.Name] = 0;
else
@ -188,12 +198,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
*/
foreach (InventoryFolderImpl childFolder in childFolders)
foreach (InventoryFolderBase childFolder in contents.Folders)
{
SaveInvFolder(childFolder, path, true);
}
foreach (InventoryItemBase item in items)
foreach (InventoryItemBase item in contents.Items)
{
SaveInvItem(item, path);
}
@ -204,9 +214,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// </summary>
public void Execute()
{
InventoryFolderImpl inventoryFolder = null;
InventoryFolderBase inventoryFolder = null;
InventoryItemBase inventoryItem = null;
InventoryFolderBase rootFolder = m_scene.InventoryService.GetRootFolder(m_userInfo.UserProfile.ID);
// XXX: Very temporarily, drop and refetch inventory to make sure we have any newly created items in cache
// This will disappear very soon once we stop using the old cached inventory.
/*
m_userInfo.DropInventory();
m_userInfo.FetchInventory();
*/
/*
if (!m_userInfo.HasReceivedInventory)
{
// If the region server has access to the user admin service (by which users are created),
@ -215,7 +234,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
//
// FIXME: FetchInventory should probably be assumed to by async anyway, since even standalones might
// use a remote inventory service, though this is vanishingly rare at the moment.
if (null == m_module.CommsManager.UserAdminService)
if (null == m_scene.CommsManager.UserAdminService)
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}",
@ -228,11 +247,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
m_userInfo.FetchInventory();
}
}
*/
bool foundStar = false;
// Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl
// itself (possibly at a small loss in efficiency).
// Eliminate double slashes and any leading / on the path.
string[] components
= m_invPath.Split(
new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries);
@ -257,18 +276,21 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
// Therefore if we still start with a / after the split, then we need the root folder
if (m_invPath.Length == 0)
{
inventoryFolder = m_userInfo.RootFolder;
inventoryFolder = rootFolder;
}
else
{
m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER));
inventoryFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath);
inventoryFolder
= InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, rootFolder, m_invPath);
//inventoryFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath);
}
// The path may point to an item instead
if (inventoryFolder == null)
{
inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
inventoryItem = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, rootFolder, m_invPath);
//inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
}
m_archiveWriter = new TarArchiveWriter(m_saveStream);
@ -306,7 +328,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
SaveUsers();
new AssetsRequest(
new AssetsArchiver(m_archiveWriter), m_assetUuids.Keys,
m_module.AssetService, ReceivedAllAssets).Execute();
m_scene.AssetService, ReceivedAllAssets).Execute();
}
/// <summary>
@ -320,7 +342,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
// Record the creator of this item
CachedUserInfo creator
= m_module.CommsManager.UserProfileCacheService.GetUserDetails(creatorId);
= m_scene.CommsManager.UserProfileCacheService.GetUserDetails(creatorId);
if (creator != null)
{

View File

@ -52,12 +52,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
public bool IsSharedModule { get { return true; } }
/// <value>
/// Enable or disable checking whether the iar user is actually logged in
/// </value>
public bool DisablePresenceChecks { get; set; }
public event InventoryArchiveSaved OnInventoryArchiveSaved;
/// <summary>
/// The file to load and save inventory if no filename has been specified
/// </summary>
protected const string DEFAULT_INV_BACKUP_FILENAME = "user-inventory_iar.tar.gz";
protected const string DEFAULT_INV_BACKUP_FILENAME = "user-inventory.iar";
/// <value>
/// Pending save completions initiated from the console
@ -70,18 +75,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
private Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>();
private Scene m_aScene;
/// <value>
/// The comms manager we will use for all comms requests
/// </value>
protected internal CommunicationsManager CommsManager;
protected internal IAssetService AssetService;
public InventoryArchiverModule() {}
public InventoryArchiverModule(bool disablePresenceChecks)
{
DisablePresenceChecks = disablePresenceChecks;
}
public void Initialise(Scene scene, IConfigSource source)
{
if (m_scenes.Count == 0)
{
scene.RegisterModuleInterface<IInventoryArchiverModule>(this);
CommsManager = scene.CommsManager;
OnInventoryArchiveSaved += SaveInvConsoleCommandCompleted;
scene.AddCommand(
@ -100,10 +105,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
m_scenes[scene.RegionInfo.RegionID] = scene;
}
public void PostInitialise()
{
AssetService = m_aScene.AssetService;
}
public void PostInitialise() {}
public void Close() {}
@ -119,29 +121,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
handlerInventoryArchiveSaved(id, succeeded, userInfo, invPath, saveStream, reportedException);
}
public void ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream)
{
if (m_scenes.Count > 0)
{
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null)
new InventoryArchiveWriteRequest(id, this, userInfo, invPath, saveStream).Execute();
}
}
public void ArchiveInventory(Guid id, string firstName, string lastName, string invPath, string savePath)
{
if (m_scenes.Count > 0)
{
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null)
new InventoryArchiveWriteRequest(id, this, userInfo, invPath, savePath).Execute();
}
}
public void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream)
public bool ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream)
{
if (m_scenes.Count > 0)
{
@ -149,14 +129,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
if (userInfo != null)
{
InventoryArchiveReadRequest request =
new InventoryArchiveReadRequest(userInfo, invPath, loadStream, CommsManager, AssetService);
UpdateClientWithLoadedNodes(userInfo, request.Execute());
if (CheckPresence(userInfo.UserProfile.ID))
{
new InventoryArchiveWriteRequest(id, this, m_aScene, userInfo, invPath, saveStream).Execute();
return true;
}
else
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator",
userInfo.UserProfile.Name, userInfo.UserProfile.ID);
}
}
}
return false;
}
public void DearchiveInventory(string firstName, string lastName, string invPath, string loadPath)
public bool ArchiveInventory(Guid id, string firstName, string lastName, string invPath, string savePath)
{
if (m_scenes.Count > 0)
{
@ -164,11 +154,77 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
if (userInfo != null)
{
InventoryArchiveReadRequest request =
new InventoryArchiveReadRequest(userInfo, invPath, loadPath, CommsManager, AssetService);
UpdateClientWithLoadedNodes(userInfo, request.Execute());
if (CheckPresence(userInfo.UserProfile.ID))
{
new InventoryArchiveWriteRequest(id, this, m_aScene, userInfo, invPath, savePath).Execute();
return true;
}
else
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator",
userInfo.UserProfile.Name, userInfo.UserProfile.ID);
}
}
}
return false;
}
public bool DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream)
{
if (m_scenes.Count > 0)
{
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null)
{
if (CheckPresence(userInfo.UserProfile.ID))
{
InventoryArchiveReadRequest request =
new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadStream);
UpdateClientWithLoadedNodes(userInfo, request.Execute());
return true;
}
else
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator",
userInfo.UserProfile.Name, userInfo.UserProfile.ID);
}
}
}
return false;
}
public bool DearchiveInventory(string firstName, string lastName, string invPath, string loadPath)
{
if (m_scenes.Count > 0)
{
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null)
{
if (CheckPresence(userInfo.UserProfile.ID))
{
InventoryArchiveReadRequest request =
new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadPath);
UpdateClientWithLoadedNodes(userInfo, request.Execute());
return true;
}
else
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator",
userInfo.UserProfile.Name, userInfo.UserProfile.ID);
}
}
}
return false;
}
/// <summary>
@ -193,11 +249,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
"[INVENTORY ARCHIVER]: Loading archive {0} to inventory path {1} for {2} {3}",
loadPath, invPath, firstName, lastName);
DearchiveInventory(firstName, lastName, invPath, loadPath);
m_log.InfoFormat(
"[INVENTORY ARCHIVER]: Loaded archive {0} for {1} {2}",
loadPath, firstName, lastName);
if (DearchiveInventory(firstName, lastName, invPath, loadPath))
m_log.InfoFormat(
"[INVENTORY ARCHIVER]: Loaded archive {0} for {1} {2}",
loadPath, firstName, lastName);
}
/// <summary>
@ -261,7 +316,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// <returns></returns>
protected CachedUserInfo GetUserInfo(string firstName, string lastName)
{
CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(firstName, lastName);
CachedUserInfo userInfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(firstName, lastName);
if (null == userInfo)
{
m_log.ErrorFormat(
@ -301,5 +356,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
}
}
/// <summary>
/// Check if the given user is present in any of the scenes.
/// </summary>
/// <param name="userId">The user to check</param>
/// <returns>true if the user is in any of the scenes, false otherwise</returns>
protected bool CheckPresence(UUID userId)
{
if (DisablePresenceChecks)
return true;
foreach (Scene scene in m_scenes.Values)
{
if (scene.GetScenePresence(userId) != null)
return true;
}
return false;
}
}
}

View File

@ -77,13 +77,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
/// </summary>
// Commenting for now! The mock inventory service needs more beef, at least for
// GetFolderForType
//[Test]
[Test]
public void TestSaveIarV0_1()
{
TestHelper.InMethod();
log4net.Config.XmlConfigurator.Configure();
InventoryArchiverModule archiverModule = new InventoryArchiverModule();
InventoryArchiverModule archiverModule = new InventoryArchiverModule(true);
Scene scene = SceneSetupHelpers.SetupScene("Inventory");
SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
@ -93,7 +93,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
string userFirstName = "Jock";
string userLastName = "Stirrup";
UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
// CachedUserInfo userInfo;
lock (this)
{
@ -102,8 +101,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
Monitor.Wait(this, 60000);
}
Console.WriteLine("here");
// Create asset
SceneObjectGroup object1;
SceneObjectPart part1;
@ -136,16 +133,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
item1.Name = "My Little Dog";
item1.AssetID = asset1.FullID;
item1.ID = item1Id;
//userInfo.RootFolder.FindFolderByPath("Objects").ID;
//InventoryFolderBase objsFolder = scene.InventoryService.GetFolderForType(userId, AssetType.Object);
Console.WriteLine("here2");
IInventoryService inventoryService = scene.InventoryService;
InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
InventoryCollection rootContents = inventoryService.GetFolderContent(userId, rootFolder.ID);
InventoryFolderBase objsFolder = null;
foreach (InventoryFolderBase folder in rootContents.Folders)
if (folder.Name == "Objects")
objsFolder = folder;
InventoryFolderBase objsFolder
= InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects");
item1.Folder = objsFolder.ID;
scene.AddInventoryItem(userId, item1);
@ -155,7 +144,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
mre.Reset();
archiverModule.ArchiveInventory(
Guid.NewGuid(), userFirstName, userLastName, "Objects", archiveWriteStream);
mre.WaitOne();
mre.WaitOne(60000, false);
byte[] archive = archiveWriteStream.ToArray();
MemoryStream archiveReadStream = new MemoryStream(archive);
@ -257,7 +246,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
SerialiserModule serialiserModule = new SerialiserModule();
InventoryArchiverModule archiverModule = new InventoryArchiverModule();
InventoryArchiverModule archiverModule = new InventoryArchiverModule(true);
// Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene
Scene scene = SceneSetupHelpers.SetupScene("inventory");
@ -275,7 +264,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
CachedUserInfo userInfo
= scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName);
InventoryItemBase foundItem = userInfo.RootFolder.FindItemByPath(itemName);
InventoryItemBase foundItem
= InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, itemName);
Assert.That(foundItem, Is.Not.Null, "Didn't find loaded item");
Assert.That(
foundItem.CreatorId, Is.EqualTo(item1.CreatorId),
@ -325,7 +316,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
SerialiserModule serialiserModule = new SerialiserModule();
InventoryArchiverModule archiverModule = new InventoryArchiverModule();
InventoryArchiverModule archiverModule = new InventoryArchiverModule(true);
// Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene
Scene scene = SceneSetupHelpers.SetupScene();
@ -385,9 +376,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
Monitor.Wait(this, 60000);
}
Console.WriteLine("userInfo.RootFolder 1: {0}", userInfo.RootFolder);
//Console.WriteLine("userInfo.RootFolder 1: {0}", userInfo.RootFolder);
Dictionary <string, InventoryFolderImpl> foldersCreated = new Dictionary<string, InventoryFolderImpl>();
Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>();
List<InventoryNodeBase> nodesLoaded = new List<InventoryNodeBase>();
string folder1Name = "a";
@ -405,16 +396,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
"{0}{1}/{2}/{3}",
ArchiveConstants.INVENTORY_PATH, folder1ArchiveName, folder2ArchiveName, itemName);
Console.WriteLine("userInfo.RootFolder 2: {0}", userInfo.RootFolder);
//Console.WriteLine("userInfo.RootFolder 2: {0}", userInfo.RootFolder);
new InventoryArchiveReadRequest(userInfo, null, (Stream)null, null, null)
new InventoryArchiveReadRequest(scene, userInfo, null, (Stream)null)
.ReplicateArchivePathToUserInventory(
itemArchivePath, false, userInfo.RootFolder, foldersCreated, nodesLoaded);
itemArchivePath, false, scene.InventoryService.GetRootFolder(userInfo.UserProfile.ID),
foldersCreated, nodesLoaded);
Console.WriteLine("userInfo.RootFolder 3: {0}", userInfo.RootFolder);
InventoryFolderImpl folder1 = userInfo.RootFolder.FindFolderByPath("a");
//Console.WriteLine("userInfo.RootFolder 3: {0}", userInfo.RootFolder);
//InventoryFolderImpl folder1 = userInfo.RootFolder.FindFolderByPath("a");
InventoryFolderBase folder1
= InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userInfo.UserProfile.ID, "a");
Assert.That(folder1, Is.Not.Null, "Could not find folder a");
InventoryFolderImpl folder2 = folder1.FindFolderByPath("b");
InventoryFolderBase folder2 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, "b");
Assert.That(folder2, Is.Not.Null, "Could not find folder b");
}
}

View File

@ -58,14 +58,14 @@ namespace OpenSim.Region.CoreModules.World.Archiver
public void Initialise(IConfigSource source)
{
m_log.Info("[ARCHIVER] Initialising");
//m_log.Debug("[ARCHIVER] Initialising");
}
public void AddRegion(Scene scene)
{
m_scene = scene;
m_scene.RegisterModuleInterface<IRegionArchiverModule>(this);
m_log.InfoFormat("[ARCHIVER]: Enabled for region {0}", scene.RegionInfo.RegionName);
//m_log.DebugFormat("[ARCHIVER]: Enabled for region {0}", scene.RegionInfo.RegionName);
}
public void RegionLoaded(Scene scene)

View File

@ -57,7 +57,8 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="lastName"></param>
/// <param name="invPath">The inventory path in which to place the loaded folders and items</param>
/// <param name="loadStream">The stream from which the inventory archive will be loaded</param>
void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream);
/// <returns>true if the first stage of the operation succeeded, false otherwise</returns>
bool DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream);
/// <summary>
/// Archive a user's inventory folder to the given stream
@ -67,6 +68,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="lastName"></param>
/// <param name="invPath">The inventory path from which the inventory should be saved.</param>
/// <param name="saveStream">The stream to which the inventory archive will be saved</param>
void ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream);
/// <returns>true if the first stage of the operation succeeded, false otherwise</returns>
bool ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream);
}
}

View File

@ -476,9 +476,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// normalize an angle between -PI and PI (-180 to +180 degrees)
protected double NormalizeAngle(double angle)
{
angle = angle % (Math.PI * 2);
// if (angle < 0) angle = angle + Math.PI * 2;
return angle;
if (angle > -Math.PI && angle < Math.PI)
return angle;
int numPis = (int)(Math.PI / angle);
double remainder = angle - Math.PI * numPis;
if (numPis % 2 == 1)
return Math.PI - angle;
return remainder;
}
// Old implementation of llRot2Euler, now normalized
@ -497,9 +502,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
NormalizeAngle(Math.Atan2(n, Math.Sqrt(p))),
NormalizeAngle(Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s))));
else if (n > 0)
return new LSL_Vector(0.0, Math.PI / 2, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z)));
return new LSL_Vector(0.0, Math.PI * 0.5, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z)));
else
return new LSL_Vector(0.0, -Math.PI / 2, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z)));
return new LSL_Vector(0.0, -Math.PI * 0.5, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z)));
}
/* From wiki:
@ -553,12 +558,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
double x,y,z,s;
double c1 = Math.Cos(v.x/2.0);
double c2 = Math.Cos(v.y/2.0);
double c3 = Math.Cos(v.z/2.0);
double s1 = Math.Sin(v.x/2.0);
double s2 = Math.Sin(v.y/2.0);
double s3 = Math.Sin(v.z/2.0);
double c1 = Math.Cos(v.x * 0.5);
double c2 = Math.Cos(v.y * 0.5);
double c3 = Math.Cos(v.z * 0.5);
double s1 = Math.Sin(v.x * 0.5);
double s2 = Math.Sin(v.y * 0.5);
double s3 = Math.Sin(v.z * 0.5);
x = s1*c2*c3+c1*s2*s3;
y = c1*s2*c3-s1*c2*s3;

View File

@ -112,7 +112,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
if (!inits.ContainsKey(api))
return;
ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject);
//ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject);
RemotingServices.GetLifetimeService(data as MarshalByRefObject);
// lease.Register(m_sponser);
MethodInfo mi = inits[api];

View File

@ -260,7 +260,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
Path.GetFileNameWithoutExtension(assembly),
"SecondLife.Script");
ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass);
//ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass);
RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass);
// lease.Register(this);
}
catch (Exception)

View File

@ -84,7 +84,17 @@ namespace OpenSim.Tests.Common.Mock
public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
{
return new List<InventoryItemBase>();
m_log.DebugFormat("[MOCK INV DB]: Getting items in folder {0}", folderID);
List<InventoryItemBase> items = new List<InventoryItemBase>();
foreach (InventoryItemBase item in m_items.Values)
{
if (item.Folder == folderID)
items.Add(item);
}
return items;
}
public List<InventoryFolderBase> getUserRootFolders(UUID user) { return null; }
@ -154,7 +164,13 @@ namespace OpenSim.Tests.Common.Mock
m_folders.Remove(folderId);
}
public void addInventoryItem(InventoryItemBase item) { m_items[item.ID] = item; }
public void addInventoryItem(InventoryItemBase item)
{
m_log.DebugFormat(
"[MOCK INV DB]: Adding inventory item {0} {1} in {2}", item.Name, item.ID, item.Folder);
m_items[item.ID] = item;
}
public void updateInventoryItem(InventoryItemBase item) { addInventoryItem(item); }