aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-07-31 18:23:17 +0000
committerJustin Clarke Casey2008-07-31 18:23:17 +0000
commit900a6564203b69851cf43fc87eb7190c82acec38 (patch)
tree2d2fcc2735003b55b7f2b0846ab28339d5726411
parent* refactor: eliminate unused SubFoldersCount (diff)
downloadopensim-SC-900a6564203b69851cf43fc87eb7190c82acec38.zip
opensim-SC-900a6564203b69851cf43fc87eb7190c82acec38.tar.gz
opensim-SC-900a6564203b69851cf43fc87eb7190c82acec38.tar.bz2
opensim-SC-900a6564203b69851cf43fc87eb7190c82acec38.tar.xz
* refactor: rearrange path inventory manipulation so that input tidying can be used for item paths as well
-rw-r--r--OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs55
-rw-r--r--OpenSim/Region/Application/OpenSimBase.cs36
2 files changed, 73 insertions, 18 deletions
diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs
index ee3fc55..96853f0 100644
--- a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs
+++ b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs
@@ -108,7 +108,7 @@ namespace OpenSim.Framework.Communications.Cache
108 } 108 }
109 109
110 /// <summary> 110 /// <summary>
111 /// Returns the item if it exists in this folder or any of this folder's subfolders? 111 /// Returns the item if it exists in this folder or in any of this folder's descendant folders
112 /// </summary> 112 /// </summary>
113 /// <param name="itemID"></param> 113 /// <param name="itemID"></param>
114 /// <returns>null if the item is not found</returns> 114 /// <returns>null if the item is not found</returns>
@@ -197,7 +197,7 @@ namespace OpenSim.Framework.Communications.Cache
197 } 197 }
198 198
199 /// <summary> 199 /// <summary>
200 /// Find a folder given a PATH_DELIMITOR delimited path. 200 /// Find a folder given a PATH_DELIMITOR delimited path starting from this folder
201 /// 201 ///
202 /// This method does not handle paths that contain multiple delimitors 202 /// This method does not handle paths that contain multiple delimitors
203 /// 203 ///
@@ -208,9 +208,8 @@ namespace OpenSim.Framework.Communications.Cache
208 /// </summary> 208 /// </summary>
209 /// <param name="path"> 209 /// <param name="path">
210 /// The path to the required folder. It this is empty then this folder itself is returned. 210 /// The path to the required folder. It this is empty then this folder itself is returned.
211 /// If a folder for the given path is not found, then null is returned.
212 /// </param> 211 /// </param>
213 /// <returns></returns> 212 /// <returns>null if the folder is not found</returns>
214 public InventoryFolderImpl FindFolderByPath(string path) 213 public InventoryFolderImpl FindFolderByPath(string path)
215 { 214 {
216 if (path == string.Empty) 215 if (path == string.Empty)
@@ -234,6 +233,52 @@ namespace OpenSim.Framework.Communications.Cache
234 // We didn't find a folder with the given name 233 // We didn't find a folder with the given name
235 return null; 234 return null;
236 } 235 }
236
237 /// <summary>
238 /// Find an item given a PATH_DELIMITOR delimited path starting from this folder.
239 ///
240 /// This method does not handle paths that contain multiple delimitors
241 ///
242 /// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some
243 /// XPath like expression
244 ///
245 /// FIXME: Delimitors which occur in names themselves are not currently escapable.
246 /// </summary>
247 /// <param name="path">
248 /// The path to the required item.
249 /// </param>
250 /// <returns>null if the item is not found</returns>
251 public InventoryItemBase FindItemByPath(string path)
252 {
253 int delimitorIndex = path.IndexOf(PATH_DELIMITER);
254 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
255
256 if (components.Length == 1)
257 {
258 lock (Items)
259 {
260 foreach (InventoryItemBase item in Items.Values)
261 {
262 if (item.Name == components[0])
263 return item;
264 }
265 }
266 }
267 else
268 {
269 lock (SubFolders)
270 {
271 foreach (InventoryFolderImpl folder in SubFolders.Values)
272 {
273 if (folder.Name == components[0])
274 return folder.FindItemByPath(components[1]);
275 }
276 }
277 }
278
279 // We didn't find an item or intermediate folder with the given name
280 return null;
281 }
237 282
238 /// <summary> 283 /// <summary>
239 /// Return a copy of the list of child items in this folder 284 /// Return a copy of the list of child items in this folder
@@ -256,7 +301,7 @@ namespace OpenSim.Framework.Communications.Cache
256 } 301 }
257 302
258 /// <summary> 303 /// <summary>
259 /// Return a copy of the list of immediate child folders in this folder. 304 /// Return a copy of the list of child folders in this folder.
260 /// </summary> 305 /// </summary>
261 public List<InventoryFolderBase> RequestListOfFolders() 306 public List<InventoryFolderBase> RequestListOfFolders()
262 { 307 {
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs
index 0d471d8..828abcb 100644
--- a/OpenSim/Region/Application/OpenSimBase.cs
+++ b/OpenSim/Region/Application/OpenSimBase.cs
@@ -698,27 +698,37 @@ namespace OpenSim
698 } 698 }
699 699
700 InventoryFolderImpl inventoryFolder = null; 700 InventoryFolderImpl inventoryFolder = null;
701 //InventoryItemBase inventoryItem = null;
701 702
702 if (userInfo.HasReceivedInventory) 703 if (userInfo.HasReceivedInventory)
703 { 704 {
704 if (invPath == InventoryFolderImpl.PATH_DELIMITER) 705 // Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl
706 // itself (possibly at a small loss in efficiency).
707 string[] components
708 = invPath.Split(new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries);
709 invPath = String.Empty;
710 foreach (string c in components)
711 {
712 invPath += c + InventoryFolderImpl.PATH_DELIMITER;
713 }
714
715 invPath = invPath.Remove(invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER));
716
717 // Annoyingly Split actually returns the original string if the input string consists only of delimiters
718 // Therefore if we still start with a / after the split, then we need the root folder
719 if (invPath.StartsWith(InventoryFolderImpl.PATH_DELIMITER))
705 { 720 {
706 inventoryFolder = userInfo.RootFolder; 721 inventoryFolder = userInfo.RootFolder;
707 } 722 }
708 else 723 else
709 { 724 {
710 // Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl 725 inventoryFolder = userInfo.RootFolder.FindFolderByPath(invPath);
711 // itself (possibly at a small loss in efficiency). 726 }
712 string[] components
713 = invPath.Split(new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries);
714 invPath = String.Empty;
715 foreach (string c in components)
716 {
717 invPath += c + InventoryFolderImpl.PATH_DELIMITER;
718 }
719 727
720 inventoryFolder = userInfo.RootFolder.FindFolderByPath(invPath); 728// if (inventoryFolder == null)
721 } 729// {
730//
731// }
722 } 732 }
723 else 733 else
724 { 734 {