diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs | 155 |
1 files changed, 82 insertions, 73 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index ecbd07f..4a06fd1 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs | |||
@@ -61,16 +61,22 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
61 | 61 | ||
62 | private UserAccount m_userInfo; | 62 | private UserAccount m_userInfo; |
63 | private string m_invPath; | 63 | private string m_invPath; |
64 | |||
65 | /// <value> | ||
66 | /// ID of this request | ||
67 | /// </value> | ||
68 | protected UUID m_id; | ||
64 | 69 | ||
65 | /// <summary> | 70 | /// <summary> |
66 | /// Do we want to merge this load with existing inventory? | 71 | /// Do we want to merge this load with existing inventory? |
67 | /// </summary> | 72 | /// </summary> |
68 | protected bool m_merge; | 73 | protected bool m_merge; |
69 | 74 | ||
70 | /// <value> | 75 | protected IInventoryService m_InventoryService; |
71 | /// We only use this to request modules | 76 | protected IAssetService m_AssetService; |
72 | /// </value> | 77 | protected IUserAccountService m_UserAccountService; |
73 | protected Scene m_scene; | 78 | |
79 | private InventoryArchiverModule m_module; | ||
74 | 80 | ||
75 | /// <value> | 81 | /// <value> |
76 | /// The stream from which the inventory archive will be loaded. | 82 | /// The stream from which the inventory archive will be loaded. |
@@ -115,12 +121,29 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
115 | /// Record the creator id that should be associated with an asset. This is used to adjust asset creator ids | 121 | /// Record the creator id that should be associated with an asset. This is used to adjust asset creator ids |
116 | /// after OSP resolution (since OSP creators are only stored in the item | 122 | /// after OSP resolution (since OSP creators are only stored in the item |
117 | /// </summary> | 123 | /// </summary> |
118 | protected Dictionary<UUID, UUID> m_creatorIdForAssetId = new Dictionary<UUID, UUID>(); | 124 | protected Dictionary<UUID, UUID> m_creatorIdForAssetId = new Dictionary<UUID, UUID>(); |
125 | |||
126 | public InventoryArchiveReadRequest( | ||
127 | IInventoryService inv, IAssetService assets, IUserAccountService uacc, UserAccount userInfo, string invPath, string loadPath, bool merge) | ||
128 | : this(UUID.Zero, null, | ||
129 | inv, | ||
130 | assets, | ||
131 | uacc, | ||
132 | userInfo, | ||
133 | invPath, | ||
134 | loadPath, | ||
135 | merge) | ||
136 | { | ||
137 | } | ||
119 | 138 | ||
120 | public InventoryArchiveReadRequest( | 139 | public InventoryArchiveReadRequest( |
121 | Scene scene, UserAccount userInfo, string invPath, string loadPath, bool merge) | 140 | UUID id, InventoryArchiverModule module, IInventoryService inv, IAssetService assets, IUserAccountService uacc, UserAccount userInfo, string invPath, string loadPath, bool merge) |
122 | : this( | 141 | : this( |
123 | scene, | 142 | id, |
143 | module, | ||
144 | inv, | ||
145 | assets, | ||
146 | uacc, | ||
124 | userInfo, | 147 | userInfo, |
125 | invPath, | 148 | invPath, |
126 | new GZipStream(ArchiveHelpers.GetStream(loadPath), CompressionMode.Decompress), | 149 | new GZipStream(ArchiveHelpers.GetStream(loadPath), CompressionMode.Decompress), |
@@ -129,13 +152,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
129 | } | 152 | } |
130 | 153 | ||
131 | public InventoryArchiveReadRequest( | 154 | public InventoryArchiveReadRequest( |
132 | Scene scene, UserAccount userInfo, string invPath, Stream loadStream, bool merge) | 155 | UUID id, InventoryArchiverModule module, IInventoryService inv, IAssetService assets, IUserAccountService uacc, UserAccount userInfo, string invPath, Stream loadStream, bool merge) |
133 | { | 156 | { |
134 | m_scene = scene; | 157 | m_id = id; |
158 | m_InventoryService = inv; | ||
159 | m_AssetService = assets; | ||
160 | m_UserAccountService = uacc; | ||
135 | m_merge = merge; | 161 | m_merge = merge; |
136 | m_userInfo = userInfo; | 162 | m_userInfo = userInfo; |
137 | m_invPath = invPath; | 163 | m_invPath = invPath; |
138 | m_loadStream = loadStream; | 164 | m_loadStream = loadStream; |
165 | m_module = module; | ||
139 | 166 | ||
140 | // FIXME: Do not perform this check since older versions of OpenSim do save the control file after other things | 167 | // FIXME: Do not perform this check since older versions of OpenSim do save the control file after other things |
141 | // (I thought they weren't). We will need to bump the version number and perform this check on all | 168 | // (I thought they weren't). We will need to bump the version number and perform this check on all |
@@ -158,11 +185,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
158 | { | 185 | { |
159 | try | 186 | try |
160 | { | 187 | { |
188 | Exception reportedException = null; | ||
189 | |||
161 | string filePath = "ERROR"; | 190 | string filePath = "ERROR"; |
162 | 191 | ||
163 | List<InventoryFolderBase> folderCandidates | 192 | List<InventoryFolderBase> folderCandidates |
164 | = InventoryArchiveUtils.FindFolderByPath( | 193 | = InventoryArchiveUtils.FindFoldersByPath( |
165 | m_scene.InventoryService, m_userInfo.PrincipalID, m_invPath); | 194 | m_InventoryService, m_userInfo.PrincipalID, m_invPath); |
166 | 195 | ||
167 | if (folderCandidates.Count == 0) | 196 | if (folderCandidates.Count == 0) |
168 | { | 197 | { |
@@ -194,14 +223,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
194 | } | 223 | } |
195 | 224 | ||
196 | archive.Close(); | 225 | archive.Close(); |
197 | 226 | ||
198 | m_log.DebugFormat( | 227 | m_log.DebugFormat( |
199 | "[INVENTORY ARCHIVER]: Successfully loaded {0} assets with {1} failures", | 228 | "[INVENTORY ARCHIVER]: Successfully loaded {0} assets with {1} failures", |
200 | m_successfulAssetRestores, m_failedAssetRestores); | 229 | m_successfulAssetRestores, m_failedAssetRestores); |
201 | m_log.InfoFormat("[INVENTORY ARCHIVER]: Successfully loaded {0} items", m_successfulItemRestores); | 230 | |
231 | //Alicia: When this is called by LibraryModule or Tests, m_module will be null as event is not required | ||
232 | if(m_module != null) | ||
233 | m_module.TriggerInventoryArchiveLoaded(m_id, true, m_userInfo, m_invPath, m_loadStream, reportedException, m_successfulItemRestores); | ||
202 | 234 | ||
203 | return m_loadedNodes; | 235 | return m_loadedNodes; |
204 | } | 236 | } |
237 | catch(Exception Ex) | ||
238 | { | ||
239 | // Trigger saved event with failed result and exception data | ||
240 | if (m_module != null) | ||
241 | m_module.TriggerInventoryArchiveLoaded(m_id, false, m_userInfo, m_invPath, m_loadStream, Ex, 0); | ||
242 | |||
243 | return m_loadedNodes; | ||
244 | } | ||
205 | finally | 245 | finally |
206 | { | 246 | { |
207 | m_loadStream.Close(); | 247 | m_loadStream.Close(); |
@@ -296,8 +336,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
296 | // iar name and try to find that instead. | 336 | // iar name and try to find that instead. |
297 | string plainPath = ArchiveConstants.ExtractPlainPathFromIarPath(archivePath); | 337 | string plainPath = ArchiveConstants.ExtractPlainPathFromIarPath(archivePath); |
298 | List<InventoryFolderBase> folderCandidates | 338 | List<InventoryFolderBase> folderCandidates |
299 | = InventoryArchiveUtils.FindFolderByPath( | 339 | = InventoryArchiveUtils.FindFoldersByPath( |
300 | m_scene.InventoryService, m_userInfo.PrincipalID, plainPath); | 340 | m_InventoryService, m_userInfo.PrincipalID, plainPath); |
301 | 341 | ||
302 | if (folderCandidates.Count != 0) | 342 | if (folderCandidates.Count != 0) |
303 | { | 343 | { |
@@ -372,15 +412,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
372 | newFolderName = InventoryArchiveUtils.UnescapeArchivePath(newFolderName); | 412 | newFolderName = InventoryArchiveUtils.UnescapeArchivePath(newFolderName); |
373 | UUID newFolderId = UUID.Random(); | 413 | UUID newFolderId = UUID.Random(); |
374 | 414 | ||
375 | // Asset type has to be Unknown here rather than Folder, otherwise the created folder can't be | ||
376 | // deleted once the client has relogged. | ||
377 | // The root folder appears to be labelled AssetType.Folder (shows up as "Category" in the client) | ||
378 | // even though there is a AssetType.RootCategory | ||
379 | destFolder | 415 | destFolder |
380 | = new InventoryFolderBase( | 416 | = new InventoryFolderBase( |
381 | newFolderId, newFolderName, m_userInfo.PrincipalID, | 417 | newFolderId, newFolderName, m_userInfo.PrincipalID, |
382 | (short)AssetType.Unknown, destFolder.ID, 1); | 418 | (short)FolderType.None, destFolder.ID, 1); |
383 | m_scene.InventoryService.AddFolder(destFolder); | 419 | m_InventoryService.AddFolder(destFolder); |
384 | 420 | ||
385 | // Record that we have now created this folder | 421 | // Record that we have now created this folder |
386 | iarPathExisting += rawDirsToCreate[i] + "/"; | 422 | iarPathExisting += rawDirsToCreate[i] + "/"; |
@@ -406,7 +442,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
406 | // Don't use the item ID that's in the file | 442 | // Don't use the item ID that's in the file |
407 | item.ID = UUID.Random(); | 443 | item.ID = UUID.Random(); |
408 | 444 | ||
409 | UUID ospResolvedId = OspResolver.ResolveOspa(item.CreatorId, m_scene.UserAccountService); | 445 | UUID ospResolvedId = OspResolver.ResolveOspa(item.CreatorId, m_UserAccountService); |
410 | if (UUID.Zero != ospResolvedId) // The user exists in this grid | 446 | if (UUID.Zero != ospResolvedId) // The user exists in this grid |
411 | { | 447 | { |
412 | // m_log.DebugFormat("[INVENTORY ARCHIVER]: Found creator {0} via OSPA resolution", ospResolvedId); | 448 | // m_log.DebugFormat("[INVENTORY ARCHIVER]: Found creator {0} via OSPA resolution", ospResolvedId); |
@@ -418,7 +454,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
418 | item.CreatorId = ospResolvedId.ToString(); | 454 | item.CreatorId = ospResolvedId.ToString(); |
419 | item.CreatorData = string.Empty; | 455 | item.CreatorData = string.Empty; |
420 | } | 456 | } |
421 | else if (item.CreatorData == null || item.CreatorData == String.Empty) | 457 | else if (string.IsNullOrEmpty(item.CreatorData)) |
422 | { | 458 | { |
423 | item.CreatorId = m_userInfo.PrincipalID.ToString(); | 459 | item.CreatorId = m_userInfo.PrincipalID.ToString(); |
424 | // item.CreatorIdAsUuid = new UUID(item.CreatorId); | 460 | // item.CreatorIdAsUuid = new UUID(item.CreatorId); |
@@ -436,7 +472,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
436 | // relying on native tar tools. | 472 | // relying on native tar tools. |
437 | m_creatorIdForAssetId[item.AssetID] = item.CreatorIdAsUuid; | 473 | m_creatorIdForAssetId[item.AssetID] = item.CreatorIdAsUuid; |
438 | 474 | ||
439 | m_scene.AddInventoryItem(item); | 475 | if (!m_InventoryService.AddItem(item)) |
476 | m_log.WarnFormat("[INVENTORY ARCHIVER]: Unable to save item {0} in folder {1}", item.Name, item.Folder); | ||
440 | 477 | ||
441 | return item; | 478 | return item; |
442 | } | 479 | } |
@@ -479,52 +516,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
479 | { | 516 | { |
480 | if (m_creatorIdForAssetId.ContainsKey(assetId)) | 517 | if (m_creatorIdForAssetId.ContainsKey(assetId)) |
481 | { | 518 | { |
482 | string xmlData = Utils.BytesToString(data); | 519 | data = SceneObjectSerializer.ModifySerializedObject(assetId, data, |
483 | List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>(); | 520 | sog => { |
521 | bool modified = false; | ||
522 | |||
523 | foreach (SceneObjectPart sop in sog.Parts) | ||
524 | { | ||
525 | if (string.IsNullOrEmpty(sop.CreatorData)) | ||
526 | { | ||
527 | sop.CreatorID = m_creatorIdForAssetId[assetId]; | ||
528 | modified = true; | ||
529 | } | ||
530 | } | ||
531 | |||
532 | return modified; | ||
533 | }); | ||
484 | 534 | ||
485 | CoalescedSceneObjects coa = null; | 535 | if (data == null) |
486 | if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa)) | 536 | return false; |
487 | { | ||
488 | // m_log.DebugFormat( | ||
489 | // "[INVENTORY ARCHIVER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count); | ||
490 | |||
491 | if (coa.Objects.Count == 0) | ||
492 | { | ||
493 | m_log.WarnFormat( | ||
494 | "[INVENTORY ARCHIVE READ REQUEST]: Aborting load of coalesced object from asset {0} as it has zero loaded components", | ||
495 | assetId); | ||
496 | return false; | ||
497 | } | ||
498 | |||
499 | sceneObjects.AddRange(coa.Objects); | ||
500 | } | ||
501 | else | ||
502 | { | ||
503 | SceneObjectGroup deserializedObject = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); | ||
504 | |||
505 | if (deserializedObject != null) | ||
506 | { | ||
507 | sceneObjects.Add(deserializedObject); | ||
508 | } | ||
509 | else | ||
510 | { | ||
511 | m_log.WarnFormat( | ||
512 | "[INVENTORY ARCHIVE READ REQUEST]: Aborting load of object from asset {0} as deserialization failed", | ||
513 | assetId); | ||
514 | |||
515 | return false; | ||
516 | } | ||
517 | } | ||
518 | |||
519 | foreach (SceneObjectGroup sog in sceneObjects) | ||
520 | foreach (SceneObjectPart sop in sog.Parts) | ||
521 | if (sop.CreatorData == null || sop.CreatorData == "") | ||
522 | sop.CreatorID = m_creatorIdForAssetId[assetId]; | ||
523 | |||
524 | if (coa != null) | ||
525 | data = Utils.StringToBytes(CoalescedSceneObjectsSerializer.ToXml(coa)); | ||
526 | else | ||
527 | data = Utils.StringToBytes(SceneObjectSerializer.ToOriginalXmlFormat(sceneObjects[0])); | ||
528 | } | 537 | } |
529 | } | 538 | } |
530 | 539 | ||
@@ -533,7 +542,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
533 | AssetBase asset = new AssetBase(assetId, "From IAR", assetType, UUID.Zero.ToString()); | 542 | AssetBase asset = new AssetBase(assetId, "From IAR", assetType, UUID.Zero.ToString()); |
534 | asset.Data = data; | 543 | asset.Data = data; |
535 | 544 | ||
536 | m_scene.AssetService.Store(asset); | 545 | m_AssetService.Store(asset); |
537 | 546 | ||
538 | return true; | 547 | return true; |
539 | } | 548 | } |
@@ -546,7 +555,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
546 | return false; | 555 | return false; |
547 | } | 556 | } |
548 | } | 557 | } |
549 | 558 | ||
550 | /// <summary> | 559 | /// <summary> |
551 | /// Load control file | 560 | /// Load control file |
552 | /// </summary> | 561 | /// </summary> |
@@ -652,4 +661,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
652 | m_assetsLoaded = true; | 661 | m_assetsLoaded = true; |
653 | } | 662 | } |
654 | } | 663 | } |
655 | } \ No newline at end of file | 664 | } |