* move userinfo for inventory archiving up to module class so that it only has to be done once

0.6.3-post-fixes
Justin Clarke Casey 2009-02-12 17:41:09 +00:00
parent e7427f21bd
commit f74326c1b0
3 changed files with 86 additions and 91 deletions

View File

@ -48,8 +48,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
protected TarArchiveReader archive; protected TarArchiveReader archive;
private static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); private static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding();
private string m_firstName; private CachedUserInfo m_userInfo;
private string m_lastName;
private string m_invPath; private string m_invPath;
/// <value> /// <value>
@ -60,10 +59,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
CommunicationsManager commsManager; CommunicationsManager commsManager;
public InventoryArchiveReadRequest( public InventoryArchiveReadRequest(
string firstName, string lastName, string invPath, string loadPath, CommunicationsManager commsManager) CachedUserInfo userInfo, string invPath, string loadPath, CommunicationsManager commsManager)
: this( : this(
firstName, userInfo,
lastName,
invPath, invPath,
new GZipStream(new FileStream(loadPath, FileMode.Open), CompressionMode.Decompress), new GZipStream(new FileStream(loadPath, FileMode.Open), CompressionMode.Decompress),
commsManager) commsManager)
@ -71,10 +69,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
} }
public InventoryArchiveReadRequest( public InventoryArchiveReadRequest(
string firstName, string lastName, string invPath, Stream loadStream, CommunicationsManager commsManager) CachedUserInfo userInfo, string invPath, Stream loadStream, CommunicationsManager commsManager)
{ {
m_firstName = firstName; m_userInfo = userInfo;
m_lastName = lastName;
m_invPath = invPath; m_invPath = invPath;
m_loadStream = loadStream; m_loadStream = loadStream;
this.commsManager = commsManager; this.commsManager = commsManager;
@ -174,33 +171,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
int successfulItemRestores = 0; int successfulItemRestores = 0;
List<InventoryNodeBase> nodesLoaded = new List<InventoryNodeBase>(); List<InventoryNodeBase> nodesLoaded = new List<InventoryNodeBase>();
UserProfileData userProfile = commsManager.UserService.GetUserProfile(m_firstName, m_lastName); if (!m_userInfo.HasReceivedInventory)
if (null == userProfile)
{
m_log.ErrorFormat("[INVENTORY ARCHIVER]: Failed to find user {0} {1}", m_firstName, m_lastName);
return nodesLoaded;
}
CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
if (null == userInfo)
{ {
m_log.ErrorFormat( m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: Failed to find user info for {0} {1} {2}", "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}",
m_firstName, m_lastName, userProfile.ID); m_userInfo.UserProfile.Name, m_userInfo.UserProfile.ID);
return nodesLoaded; return nodesLoaded;
} }
if (!userInfo.HasReceivedInventory) InventoryFolderImpl inventoryFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath);
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1} {2}",
m_firstName, m_lastName, userProfile.ID);
return nodesLoaded;
}
InventoryFolderImpl inventoryFolder = userInfo.RootFolder.FindFolderByPath(m_invPath);
if (null == inventoryFolder) if (null == inventoryFolder)
{ {
@ -232,15 +212,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
if (item != null) if (item != null)
{ {
item.Creator = userProfile.ID; item.Creator = m_userInfo.UserProfile.ID;
item.Owner = userProfile.ID; item.Owner = m_userInfo.UserProfile.ID;
// Reset folder ID to the one in which we want to load it // Reset folder ID to the one in which we want to load it
// TODO: Properly restore entire folder structure. At the moment all items are dumped in this // TODO: Properly restore entire folder structure. At the moment all items are dumped in this
// single folder no matter where in the saved folder structure they are. // single folder no matter where in the saved folder structure they are.
item.Folder = inventoryFolder.ID; item.Folder = inventoryFolder.ID;
userInfo.AddItem(item); m_userInfo.AddItem(item);
successfulItemRestores++; successfulItemRestores++;
nodesLoaded.Add(item); nodesLoaded.Add(item);
} }

View File

@ -48,8 +48,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
protected CommunicationsManager commsManager; protected CommunicationsManager commsManager;
protected Dictionary<UUID, int> assetUuids = new Dictionary<UUID, int>(); protected Dictionary<UUID, int> assetUuids = new Dictionary<UUID, int>();
private string m_firstName; private CachedUserInfo m_userInfo;
private string m_lastName;
private string m_invPath; private string m_invPath;
/// <value> /// <value>
@ -61,13 +60,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// Constructor /// Constructor
/// </summary> /// </summary>
public InventoryArchiveWriteRequest( public InventoryArchiveWriteRequest(
string firstName, string lastName, string invPath, string savePath, CommunicationsManager commsManager) CachedUserInfo userInfo, string invPath, string savePath, CommunicationsManager commsManager)
: this( : this(
firstName, userInfo,
lastName, invPath,
invPath, new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress),
new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress), commsManager)
commsManager)
{ {
} }
@ -75,10 +73,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// Constructor /// Constructor
/// </summary> /// </summary>
public InventoryArchiveWriteRequest( public InventoryArchiveWriteRequest(
string firstName, string lastName, string invPath, Stream saveStream, CommunicationsManager commsManager) CachedUserInfo userInfo, string invPath, Stream saveStream, CommunicationsManager commsManager)
{ {
m_firstName = firstName; m_userInfo = userInfo;
m_lastName = lastName;
m_invPath = invPath; m_invPath = invPath;
m_saveStream = saveStream; m_saveStream = saveStream;
this.commsManager = commsManager; this.commsManager = commsManager;
@ -183,26 +180,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
public void Execute() public void Execute()
{ {
UserProfileData userProfile = commsManager.UserService.GetUserProfile(m_firstName, m_lastName);
if (null == userProfile)
{
m_log.ErrorFormat("[INVENTORY ARCHIVER]: Failed to find user {0} {1}", m_firstName, m_lastName);
return;
}
CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
if (null == userInfo)
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: Failed to find user info for {0} {1} {2}",
m_firstName, m_lastName, userProfile.ID);
return;
}
InventoryFolderImpl inventoryFolder = null; InventoryFolderImpl inventoryFolder = null;
InventoryItemBase inventoryItem = null; InventoryItemBase inventoryItem = null;
if (userInfo.HasReceivedInventory) if (m_userInfo.HasReceivedInventory)
{ {
// Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl // Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl
// itself (possibly at a small loss in efficiency). // itself (possibly at a small loss in efficiency).
@ -218,25 +199,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
// Therefore if we still start with a / after the split, then we need the root folder // Therefore if we still start with a / after the split, then we need the root folder
if (m_invPath.Length == 0) if (m_invPath.Length == 0)
{ {
inventoryFolder = userInfo.RootFolder; inventoryFolder = m_userInfo.RootFolder;
} }
else else
{ {
m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER)); m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER));
inventoryFolder = userInfo.RootFolder.FindFolderByPath(m_invPath); inventoryFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath);
} }
// The path may point to an item instead // The path may point to an item instead
if (inventoryFolder == null) if (inventoryFolder == null)
{ {
inventoryItem = userInfo.RootFolder.FindItemByPath(m_invPath); inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
} }
} }
else else
{ {
m_log.ErrorFormat( m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1} {2}", "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}",
m_firstName, m_lastName, userProfile.ID); m_userInfo.UserProfile.Name, m_userInfo.UserProfile.ID);
return; return;
} }

View File

@ -32,7 +32,8 @@ using log4net;
using Nini.Config; using Nini.Config;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Communications; using OpenSim.Framework.Communications;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
@ -85,22 +86,22 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
m_scenes[scene.RegionInfo.RegionID] = scene; m_scenes[scene.RegionInfo.RegionID] = scene;
} }
public void PostInitialise() public void PostInitialise() {}
{
}
public void Close() public void Close() {}
{
}
public void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream) public void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream)
{ {
if (m_scenes.Count > 0) if (m_scenes.Count > 0)
{ {
InventoryArchiveReadRequest request = CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
new InventoryArchiveReadRequest(firstName, lastName, invPath, loadStream, m_commsManager);
if (userInfo != null)
UpdateClientWithLoadedNodes(firstName, lastName, request.Execute()); {
InventoryArchiveReadRequest request =
new InventoryArchiveReadRequest(userInfo, invPath, loadStream, m_commsManager);
UpdateClientWithLoadedNodes(userInfo, request.Execute());
}
} }
} }
@ -108,18 +109,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{ {
if (m_scenes.Count > 0) if (m_scenes.Count > 0)
{ {
new InventoryArchiveWriteRequest(firstName, lastName, invPath, saveStream, m_commsManager).Execute(); CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null)
new InventoryArchiveWriteRequest(userInfo, invPath, saveStream, m_commsManager).Execute();
} }
} }
public void DearchiveInventory(string firstName, string lastName, string invPath, string loadPath) public void DearchiveInventory(string firstName, string lastName, string invPath, string loadPath)
{ {
if (m_scenes.Count > 0) if (m_scenes.Count > 0)
{ {
InventoryArchiveReadRequest request = CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
new InventoryArchiveReadRequest(firstName, lastName, invPath, loadPath, m_commsManager);
UpdateClientWithLoadedNodes(firstName, lastName, request.Execute()); if (userInfo != null)
{
InventoryArchiveReadRequest request =
new InventoryArchiveReadRequest(userInfo, invPath, loadPath, m_commsManager);
UpdateClientWithLoadedNodes(userInfo, request.Execute());
}
} }
} }
@ -127,9 +135,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{ {
if (m_scenes.Count > 0) if (m_scenes.Count > 0)
{ {
new InventoryArchiveWriteRequest(firstName, lastName, invPath, savePath, m_commsManager).Execute(); CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null)
new InventoryArchiveWriteRequest(userInfo, invPath, savePath, m_commsManager).Execute();
} }
} }
/// <summary> /// <summary>
/// Load inventory from an inventory file archive /// Load inventory from an inventory file archive
@ -174,22 +185,45 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
} }
/// <summary> /// <summary>
/// Notify the client of loaded nodes if they are logged in /// Get user information for the given name.
/// </summary> /// </summary>
/// <param name="loadedNodes">Can be empty. In which case, nothing happens</param> /// <param name="firstName"></param>
private void UpdateClientWithLoadedNodes(string firstName, string lastName, List<InventoryNodeBase> loadedNodes) /// <param name="lastName"></param>
{ /// <returns></returns>
if (loadedNodes.Count == 0) protected CachedUserInfo GetUserInfo(string firstName, string lastName)
return; {
UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(firstName, lastName); UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(firstName, lastName);
if (null == userProfile) if (null == userProfile)
{
m_log.ErrorFormat("[INVENTORY ARCHIVER]: Failed to find user {0} {1}", firstName, lastName);
return null;
}
CachedUserInfo userInfo = m_commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
if (null == userInfo)
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: Failed to find user info for {0} {1} {2}",
firstName, lastName, userProfile.ID);
return null;
}
return userInfo;
}
/// <summary>
/// Notify the client of loaded nodes if they are logged in
/// </summary>
/// <param name="loadedNodes">Can be empty. In which case, nothing happens</param>
private void UpdateClientWithLoadedNodes(CachedUserInfo userInfo, List<InventoryNodeBase> loadedNodes)
{
if (loadedNodes.Count == 0)
return; return;
foreach (Scene scene in m_scenes.Values) foreach (Scene scene in m_scenes.Values)
{ {
ScenePresence user = scene.GetScenePresence(userProfile.ID); ScenePresence user = scene.GetScenePresence(userInfo.UserProfile.ID);
if (user != null && !user.IsChildAgent) if (user != null && !user.IsChildAgent)
{ {