aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-04-24 19:10:13 +0000
committerJustin Clarke Casey2009-04-24 19:10:13 +0000
commiteeb1908bcee483458f6701b30b839a758565a3c6 (patch)
tree48d446c6c7f885cc2a8aa1d3898b68a877d57dc2 /OpenSim
parent* correct spelling mistake in item seiralization (diff)
downloadopensim-SC-eeb1908bcee483458f6701b30b839a758565a3c6.zip
opensim-SC-eeb1908bcee483458f6701b30b839a758565a3c6.tar.gz
opensim-SC-eeb1908bcee483458f6701b30b839a758565a3c6.tar.bz2
opensim-SC-eeb1908bcee483458f6701b30b839a758565a3c6.tar.xz
* Refactor: break out loading of archive paths into inventory into a separate method
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs249
1 files changed, 139 insertions, 110 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
index 69a4bd7..2ecb7d4 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
@@ -144,116 +144,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
144 } 144 }
145 else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH)) 145 else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH))
146 { 146 {
147 string fsPath = filePath.Substring(ArchiveConstants.INVENTORY_PATH.Length); 147 InventoryFolderImpl foundFolder
148 148 = ReplicateArchivePathToUserInventory(
149 // Remove the file portion if we aren't already dealing with a directory path 149 filePath, TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType,
150 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) 150 rootDestinationFolder, foldersCreated, nodesLoaded);
151 fsPath = fsPath.Remove(fsPath.LastIndexOf("/") + 1);
152
153 string originalFsPath = fsPath;
154
155 m_log.DebugFormat("[INVENTORY ARCHIVER]: Loading to folder {0}", fsPath);
156
157 InventoryFolderImpl foundFolder = null;
158
159 // XXX: Nasty way of dealing with a path that has no directory component
160 if (fsPath.Length > 0)
161 {
162 while (null == foundFolder && fsPath.Length > 0)
163 {
164 if (foldersCreated.ContainsKey(fsPath))
165 {
166 m_log.DebugFormat("[INVENTORY ARCHIVER]: Found previously created fs path {0}", fsPath);
167 foundFolder = foldersCreated[fsPath];
168 }
169 else
170 {
171 // Don't include the last slash
172 int penultimateSlashIndex = fsPath.LastIndexOf("/", fsPath.Length - 2);
173
174 if (penultimateSlashIndex >= 0)
175 {
176 fsPath = fsPath.Remove(penultimateSlashIndex + 1);
177 }
178 else
179 {
180 m_log.DebugFormat(
181 "[INVENTORY ARCHIVER]: Found no previously created fs path for {0}",
182 originalFsPath);
183 fsPath = string.Empty;
184 foundFolder = rootDestinationFolder;
185 }
186 }
187 }
188 }
189 else
190 {
191 foundFolder = rootDestinationFolder;
192 }
193
194 string fsPathSectionToCreate = originalFsPath.Substring(fsPath.Length);
195 string[] rawDirsToCreate
196 = fsPathSectionToCreate.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
197 int i = 0;
198
199 while (i < rawDirsToCreate.Length)
200 {
201 m_log.DebugFormat("[INVENTORY ARCHIVER]: Creating folder {0}", rawDirsToCreate[i]);
202
203 int identicalNameIdentifierIndex
204 = rawDirsToCreate[i].LastIndexOf(
205 ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR);
206 string folderName = rawDirsToCreate[i].Remove(identicalNameIdentifierIndex);
207
208 UUID newFolderId = UUID.Random();
209 m_userInfo.CreateFolder(
210 folderName, newFolderId, (ushort)AssetType.Folder, foundFolder.ID);
211 foundFolder = foundFolder.GetChildFolder(newFolderId);
212
213 // Record that we have now created this folder
214 fsPath += rawDirsToCreate[i] + "/";
215 m_log.DebugFormat("[INVENTORY ARCHIVER]: Recording creation of fs path {0}", fsPath);
216 foldersCreated[fsPath] = foundFolder;
217
218 if (0 == i)
219 nodesLoaded.Add(foundFolder);
220
221 i++;
222 }
223
224 /*
225 string[] rawFolders = filePath.Split(new char[] { '/' });
226
227 // Find the folders that do exist along the path given
228 int i = 0;
229 bool noFolder = false;
230 InventoryFolderImpl foundFolder = rootDestinationFolder;
231 while (!noFolder && i < rawFolders.Length)
232 {
233 InventoryFolderImpl folder = foundFolder.FindFolderByPath(rawFolders[i]);
234 if (null != folder)
235 {
236 m_log.DebugFormat("[INVENTORY ARCHIVER]: Found folder {0}", folder.Name);
237 foundFolder = folder;
238 i++;
239 }
240 else
241 {
242 noFolder = true;
243 }
244 }
245
246 // Create any folders that did not previously exist
247 while (i < rawFolders.Length)
248 {
249 m_log.DebugFormat("[INVENTORY ARCHIVER]: Creating folder {0}", rawFolders[i]);
250
251 UUID newFolderId = UUID.Random();
252 m_userInfo.CreateFolder(
253 rawFolders[i++], newFolderId, (ushort)AssetType.Folder, foundFolder.ID);
254 foundFolder = foundFolder.GetChildFolder(newFolderId);
255 }
256 */
257 151
258 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) 152 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
259 { 153 {
@@ -286,6 +180,141 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
286 180
287 return nodesLoaded; 181 return nodesLoaded;
288 } 182 }
183
184 /// <summary>
185 /// Replicate the inventory paths in the archive to the user's inventory as necessary.
186 /// </summary>
187 /// <param name="fsPath"></param>
188 /// <param name="isDir">Is the path we're dealing with a directory?</param>
189 /// <param name="rootDestinationFolder">The root folder for the inventory load</param>
190 /// <param name="foldersCreated">
191 /// The folders created so far. This method will add more folders if necessary
192 /// </param>
193 /// <param name="nodesLoaded">
194 /// Track the inventory nodes created. This is distinct from the folders created since for a particular folder
195 /// chain, only the root node needs to be recorded
196 /// </param>
197 /// <returns>The last user inventory folder created or found for the archive path</returns>
198 public InventoryFolderImpl ReplicateArchivePathToUserInventory(
199 string fsPath,
200 bool isDir,
201 InventoryFolderImpl rootDestinationFolder,
202 Dictionary <string, InventoryFolderImpl> foldersCreated,
203 List<InventoryNodeBase> nodesLoaded)
204 {
205 fsPath = fsPath.Substring(ArchiveConstants.INVENTORY_PATH.Length);
206
207 // Remove the file portion if we aren't already dealing with a directory path
208 if (!isDir)
209 fsPath = fsPath.Remove(fsPath.LastIndexOf("/") + 1);
210
211 string originalFsPath = fsPath;
212
213 m_log.DebugFormat("[INVENTORY ARCHIVER]: Loading to folder {0}", fsPath);
214
215 InventoryFolderImpl foundFolder = null;
216
217 // XXX: Nasty way of dealing with a path that has no directory component
218 if (fsPath.Length > 0)
219 {
220 while (null == foundFolder && fsPath.Length > 0)
221 {
222 if (foldersCreated.ContainsKey(fsPath))
223 {
224 m_log.DebugFormat("[INVENTORY ARCHIVER]: Found previously created fs path {0}", fsPath);
225 foundFolder = foldersCreated[fsPath];
226 }
227 else
228 {
229 // Don't include the last slash
230 int penultimateSlashIndex = fsPath.LastIndexOf("/", fsPath.Length - 2);
231
232 if (penultimateSlashIndex >= 0)
233 {
234 fsPath = fsPath.Remove(penultimateSlashIndex + 1);
235 }
236 else
237 {
238 m_log.DebugFormat(
239 "[INVENTORY ARCHIVER]: Found no previously created fs path for {0}",
240 originalFsPath);
241 fsPath = string.Empty;
242 foundFolder = rootDestinationFolder;
243 }
244 }
245 }
246 }
247 else
248 {
249 foundFolder = rootDestinationFolder;
250 }
251
252 string fsPathSectionToCreate = originalFsPath.Substring(fsPath.Length);
253 string[] rawDirsToCreate
254 = fsPathSectionToCreate.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
255 int i = 0;
256
257 while (i < rawDirsToCreate.Length)
258 {
259 m_log.DebugFormat("[INVENTORY ARCHIVER]: Creating folder {0}", rawDirsToCreate[i]);
260
261 int identicalNameIdentifierIndex
262 = rawDirsToCreate[i].LastIndexOf(
263 ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR);
264 string folderName = rawDirsToCreate[i].Remove(identicalNameIdentifierIndex);
265
266 UUID newFolderId = UUID.Random();
267 m_userInfo.CreateFolder(
268 folderName, newFolderId, (ushort)AssetType.Folder, foundFolder.ID);
269 foundFolder = foundFolder.GetChildFolder(newFolderId);
270
271 // Record that we have now created this folder
272 fsPath += rawDirsToCreate[i] + "/";
273 m_log.DebugFormat("[INVENTORY ARCHIVER]: Recording creation of fs path {0}", fsPath);
274 foldersCreated[fsPath] = foundFolder;
275
276 if (0 == i)
277 nodesLoaded.Add(foundFolder);
278
279 i++;
280 }
281
282 return foundFolder;
283
284 /*
285 string[] rawFolders = filePath.Split(new char[] { '/' });
286
287 // Find the folders that do exist along the path given
288 int i = 0;
289 bool noFolder = false;
290 InventoryFolderImpl foundFolder = rootDestinationFolder;
291 while (!noFolder && i < rawFolders.Length)
292 {
293 InventoryFolderImpl folder = foundFolder.FindFolderByPath(rawFolders[i]);
294 if (null != folder)
295 {
296 m_log.DebugFormat("[INVENTORY ARCHIVER]: Found folder {0}", folder.Name);
297 foundFolder = folder;
298 i++;
299 }
300 else
301 {
302 noFolder = true;
303 }
304 }
305
306 // Create any folders that did not previously exist
307 while (i < rawFolders.Length)
308 {
309 m_log.DebugFormat("[INVENTORY ARCHIVER]: Creating folder {0}", rawFolders[i]);
310
311 UUID newFolderId = UUID.Random();
312 m_userInfo.CreateFolder(
313 rawFolders[i++], newFolderId, (ushort)AssetType.Folder, foundFolder.ID);
314 foundFolder = foundFolder.GetChildFolder(newFolderId);
315 }
316 */
317 }
289 318
290 /// <summary> 319 /// <summary>
291 /// Load an asset 320 /// Load an asset