aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs137
1 files changed, 80 insertions, 57 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
index cf4ba91..9b98de3 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
@@ -77,18 +77,35 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
77 /// </value> 77 /// </value>
78 private Stream m_loadStream; 78 private Stream m_loadStream;
79 79
80 /// <summary>
81 /// Record the creator id that should be associated with an asset. This is used to adjust asset creator ids
82 /// after OSP resolution (since OSP creators are only stored in the item
83 /// </summary>
84 protected Dictionary<UUID, UUID> m_creatorIdForAssetId = new Dictionary<UUID, UUID>();
85
86 protected bool m_controlFileLoaded; 80 protected bool m_controlFileLoaded;
87 protected bool m_assetsLoaded; 81 protected bool m_assetsLoaded;
88 protected bool m_inventoryNodesLoaded; 82 protected bool m_inventoryNodesLoaded;
89 83
90 protected int m_successfulAssetRestores; 84 protected int m_successfulAssetRestores;
91 protected int m_failedAssetRestores; 85 protected int m_failedAssetRestores;
86 protected int m_successfulItemRestores;
87
88 /// <summary>
89 /// Root destination folder for the IAR load.
90 /// </summary>
91 protected InventoryFolderBase m_rootDestinationFolder;
92
93 /// <summary>
94 /// Inventory nodes loaded from the iar.
95 /// </summary>
96 protected HashSet<InventoryNodeBase> m_loadedNodes = new HashSet<InventoryNodeBase>();
97
98 /// <summary>
99 /// In order to load identically named folders, we need to keep track of the folders that we have already
100 /// resolved.
101 /// </summary>
102 Dictionary <string, InventoryFolderBase> m_resolvedFolders = new Dictionary<string, InventoryFolderBase>();
103
104 /// <summary>
105 /// Record the creator id that should be associated with an asset. This is used to adjust asset creator ids
106 /// after OSP resolution (since OSP creators are only stored in the item
107 /// </summary>
108 protected Dictionary<UUID, UUID> m_creatorIdForAssetId = new Dictionary<UUID, UUID>();
92 109
93 public InventoryArchiveReadRequest( 110 public InventoryArchiveReadRequest(
94 Scene scene, UserAccount userInfo, string invPath, string loadPath, bool merge) 111 Scene scene, UserAccount userInfo, string invPath, string loadPath, bool merge)
@@ -114,6 +131,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
114 /// <summary> 131 /// <summary>
115 /// Execute the request 132 /// Execute the request
116 /// </summary> 133 /// </summary>
134 /// <remarks>
135 /// Only call this once. To load another IAR, construct another request object.
136 /// </remarks>
117 /// <returns> 137 /// <returns>
118 /// A list of the inventory nodes loaded. If folders were loaded then only the root folders are 138 /// A list of the inventory nodes loaded. If folders were loaded then only the root folders are
119 /// returned 139 /// returned
@@ -124,9 +144,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
124 try 144 try
125 { 145 {
126 string filePath = "ERROR"; 146 string filePath = "ERROR";
127 int successfulItemRestores = 0;
128
129 HashSet<InventoryNodeBase> loadedNodes = new HashSet<InventoryNodeBase>();
130 147
131 List<InventoryFolderBase> folderCandidates 148 List<InventoryFolderBase> folderCandidates
132 = InventoryArchiveUtils.FindFolderByPath( 149 = InventoryArchiveUtils.FindFolderByPath(
@@ -137,16 +154,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
137 // Possibly provide an option later on to automatically create this folder if it does not exist 154 // Possibly provide an option later on to automatically create this folder if it does not exist
138 m_log.ErrorFormat("[INVENTORY ARCHIVER]: Inventory path {0} does not exist", m_invPath); 155 m_log.ErrorFormat("[INVENTORY ARCHIVER]: Inventory path {0} does not exist", m_invPath);
139 156
140 return loadedNodes; 157 return m_loadedNodes;
141 } 158 }
142 159
143 InventoryFolderBase rootDestinationFolder = folderCandidates[0]; 160 m_rootDestinationFolder = folderCandidates[0];
144 archive = new TarArchiveReader(m_loadStream); 161 archive = new TarArchiveReader(m_loadStream);
145
146 // In order to load identically named folders, we need to keep track of the folders that we have already
147 // resolved
148 Dictionary <string, InventoryFolderBase> resolvedFolders = new Dictionary<string, InventoryFolderBase>();
149
150 byte[] data; 162 byte[] data;
151 TarArchiveReader.TarEntryType entryType; 163 TarArchiveReader.TarEntryType entryType;
152 164
@@ -162,44 +174,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
162 } 174 }
163 else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH)) 175 else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH))
164 { 176 {
165 if (!m_controlFileLoaded) 177 LoadInventoryFile(filePath, entryType, data);
166 throw new Exception(
167 string.Format(
168 "The IAR you are trying to load does not list {0} before {1}. Aborting load",
169 ArchiveConstants.CONTROL_FILE_PATH, ArchiveConstants.INVENTORY_PATH));
170
171 if (m_assetsLoaded)
172 throw new Exception(
173 string.Format(
174 "The IAR you are trying to load does not list all {0} before {1}. Aborting load",
175 ArchiveConstants.INVENTORY_PATH, ArchiveConstants.ASSETS_PATH));
176
177 filePath = filePath.Substring(ArchiveConstants.INVENTORY_PATH.Length);
178
179 // Trim off the file portion if we aren't already dealing with a directory path
180 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
181 filePath = filePath.Remove(filePath.LastIndexOf("/") + 1);
182
183 InventoryFolderBase foundFolder
184 = ReplicateArchivePathToUserInventory(
185 filePath, rootDestinationFolder, resolvedFolders, loadedNodes);
186
187 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
188 {
189 InventoryItemBase item = LoadItem(data, foundFolder);
190
191 if (item != null)
192 {
193 successfulItemRestores++;
194
195 // If we aren't loading the folder containing the item then well need to update the
196 // viewer separately for that item.
197 if (!loadedNodes.Contains(foundFolder))
198 loadedNodes.Add(item);
199 }
200 }
201
202 m_inventoryNodesLoaded = true;
203 } 178 }
204 } 179 }
205 180
@@ -208,9 +183,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
208 m_log.DebugFormat( 183 m_log.DebugFormat(
209 "[INVENTORY ARCHIVER]: Successfully loaded {0} assets with {1} failures", 184 "[INVENTORY ARCHIVER]: Successfully loaded {0} assets with {1} failures",
210 m_successfulAssetRestores, m_failedAssetRestores); 185 m_successfulAssetRestores, m_failedAssetRestores);
211 m_log.InfoFormat("[INVENTORY ARCHIVER]: Successfully loaded {0} items", successfulItemRestores); 186 m_log.InfoFormat("[INVENTORY ARCHIVER]: Successfully loaded {0} items", m_successfulItemRestores);
212 187
213 return loadedNodes; 188 return m_loadedNodes;
214 } 189 }
215 finally 190 finally
216 { 191 {
@@ -549,6 +524,54 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
549 } 524 }
550 525
551 /// <summary> 526 /// <summary>
527 /// Load inventory file
528 /// </summary>
529 /// <param name="path"></param>
530 /// <param name="entryType"></param>
531 /// <param name="data"></param>
532 protected void LoadInventoryFile(string path, TarArchiveReader.TarEntryType entryType, byte[] data)
533 {
534 if (!m_controlFileLoaded)
535 throw new Exception(
536 string.Format(
537 "The IAR you are trying to load does not list {0} before {1}. Aborting load",
538 ArchiveConstants.CONTROL_FILE_PATH, ArchiveConstants.INVENTORY_PATH));
539
540 if (m_assetsLoaded)
541 throw new Exception(
542 string.Format(
543 "The IAR you are trying to load does not list all {0} before {1}. Aborting load",
544 ArchiveConstants.INVENTORY_PATH, ArchiveConstants.ASSETS_PATH));
545
546 path = path.Substring(ArchiveConstants.INVENTORY_PATH.Length);
547
548 // Trim off the file portion if we aren't already dealing with a directory path
549 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
550 path = path.Remove(path.LastIndexOf("/") + 1);
551
552 InventoryFolderBase foundFolder
553 = ReplicateArchivePathToUserInventory(
554 path, m_rootDestinationFolder, m_resolvedFolders, m_loadedNodes);
555
556 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
557 {
558 InventoryItemBase item = LoadItem(data, foundFolder);
559
560 if (item != null)
561 {
562 m_successfulItemRestores++;
563
564 // If we aren't loading the folder containing the item then well need to update the
565 // viewer separately for that item.
566 if (!m_loadedNodes.Contains(foundFolder))
567 m_loadedNodes.Add(item);
568 }
569 }
570
571 m_inventoryNodesLoaded = true;
572 }
573
574 /// <summary>
552 /// Load asset file 575 /// Load asset file
553 /// </summary> 576 /// </summary>
554 /// <param name="path"></param> 577 /// <param name="path"></param>
@@ -578,6 +601,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
578 m_successfulAssetRestores); 601 m_successfulAssetRestores);
579 602
580 m_assetsLoaded = true; 603 m_assetsLoaded = true;
581 } 604 }
582 } 605 }
583} \ No newline at end of file 606} \ No newline at end of file