aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-02-25 18:07:32 +0000
committerJustin Clarke Casey2009-02-25 18:07:32 +0000
commit17a336f21fe44a88fb18850f660926a9f2fe3e9a (patch)
tree995df58218c751f278406d3015559f78b66ddb11
parent* Store inventory data in an 'inventory' directory rather than in the root of... (diff)
downloadopensim-SC-17a336f21fe44a88fb18850f660926a9f2fe3e9a.zip
opensim-SC-17a336f21fe44a88fb18850f660926a9f2fe3e9a.tar.gz
opensim-SC-17a336f21fe44a88fb18850f660926a9f2fe3e9a.tar.bz2
opensim-SC-17a336f21fe44a88fb18850f660926a9f2fe3e9a.tar.xz
* Add InventoryArchiveConstants that I missed from last commit
* This commit also does a first pass at creating folders for an inventory archive (previously everything was dumped in the same destiantion folder). * This code might not work yet and nobody else should be using it yet anyway :)
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveConstants.cs108
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs35
2 files changed, 137 insertions, 6 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveConstants.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveConstants.cs
new file mode 100644
index 0000000..b274af2
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveConstants.cs
@@ -0,0 +1,108 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Collections.Generic;
29using OpenMetaverse;
30
31namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
32{
33 /// <summary>
34 /// Constants for the inventory archiving module
35 /// </summary>
36 public class InventoryArchiveConstants
37 {
38 /// <summary>
39 /// Path for the inventory data
40 /// </summary>
41 public static readonly string INVENTORY_PATH = "inventory/";
42
43 /// <summary>
44 /// Path for the assets held in an archive
45 /// </summary>
46 public static readonly string ASSETS_PATH = "assets/";
47
48 /// <summary>
49 /// The character the separates the uuid from extension information in an archived asset filename
50 /// </summary>
51 public static readonly string ASSET_EXTENSION_SEPARATOR = "_";
52
53 /// <summary>
54 /// Extensions used for asset types in the archive
55 /// </summary>
56 public static readonly IDictionary<sbyte, string> ASSET_TYPE_TO_EXTENSION = new Dictionary<sbyte, string>();
57 public static readonly IDictionary<string, sbyte> EXTENSION_TO_ASSET_TYPE = new Dictionary<string, sbyte>();
58
59 static InventoryArchiveConstants()
60 {
61 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Animation] = ASSET_EXTENSION_SEPARATOR + "animation.bvh";
62 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Bodypart] = ASSET_EXTENSION_SEPARATOR + "bodypart.txt";
63 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.CallingCard] = ASSET_EXTENSION_SEPARATOR + "callingcard.txt";
64 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Clothing] = ASSET_EXTENSION_SEPARATOR + "clothing.txt";
65 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Folder] = ASSET_EXTENSION_SEPARATOR + "folder.txt"; // Not sure if we'll ever see this
66 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Gesture] = ASSET_EXTENSION_SEPARATOR + "gesture.txt";
67 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.ImageJPEG] = ASSET_EXTENSION_SEPARATOR + "image.jpg";
68 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.ImageTGA] = ASSET_EXTENSION_SEPARATOR + "image.tga";
69 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Landmark] = ASSET_EXTENSION_SEPARATOR + "landmark.txt";
70 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LostAndFoundFolder] = ASSET_EXTENSION_SEPARATOR + "lostandfoundfolder.txt"; // Not sure if we'll ever see this
71 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLBytecode] = ASSET_EXTENSION_SEPARATOR + "bytecode.lso";
72 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLText] = ASSET_EXTENSION_SEPARATOR + "script.lsl";
73 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Notecard] = ASSET_EXTENSION_SEPARATOR + "notecard.txt";
74 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Object] = ASSET_EXTENSION_SEPARATOR + "object.xml";
75 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.RootFolder] = ASSET_EXTENSION_SEPARATOR + "rootfolder.txt"; // Not sure if we'll ever see this
76 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Simstate] = ASSET_EXTENSION_SEPARATOR + "simstate.bin"; // Not sure if we'll ever see this
77 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SnapshotFolder] = ASSET_EXTENSION_SEPARATOR + "snapshotfolder.txt"; // Not sure if we'll ever see this
78 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Sound] = ASSET_EXTENSION_SEPARATOR + "sound.ogg";
79 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV] = ASSET_EXTENSION_SEPARATOR + "sound.wav";
80 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Texture] = ASSET_EXTENSION_SEPARATOR + "texture.jp2";
81 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TextureTGA] = ASSET_EXTENSION_SEPARATOR + "texture.tga";
82 ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TrashFolder] = ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"; // Not sure if we'll ever see this
83
84 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "animation.bvh"] = (sbyte)AssetType.Animation;
85 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bodypart.txt"] = (sbyte)AssetType.Bodypart;
86 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "callingcard.txt"] = (sbyte)AssetType.CallingCard;
87 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "clothing.txt"] = (sbyte)AssetType.Clothing;
88 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "folder.txt"] = (sbyte)AssetType.Folder;
89 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "gesture.txt"] = (sbyte)AssetType.Gesture;
90 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "image.jpg"] = (sbyte)AssetType.ImageJPEG;
91 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "image.tga"] = (sbyte)AssetType.ImageTGA;
92 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "landmark.txt"] = (sbyte)AssetType.Landmark;
93 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "lostandfoundfolder.txt"] = (sbyte)AssetType.LostAndFoundFolder;
94 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bytecode.lso"] = (sbyte)AssetType.LSLBytecode;
95 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "script.lsl"] = (sbyte)AssetType.LSLText;
96 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "notecard.txt"] = (sbyte)AssetType.Notecard;
97 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "object.xml"] = (sbyte)AssetType.Object;
98 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "rootfolder.txt"] = (sbyte)AssetType.RootFolder;
99 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "simstate.bin"] = (sbyte)AssetType.Simstate;
100 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "snapshotfolder.txt"] = (sbyte)AssetType.SnapshotFolder;
101 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "sound.ogg"] = (sbyte)AssetType.Sound;
102 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "sound.wav"] = (sbyte)AssetType.SoundWAV;
103 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.jp2"] = (sbyte)AssetType.Texture;
104 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA;
105 EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"] = (sbyte)AssetType.TrashFolder;
106 }
107 }
108}
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
index d2b59ae..2090558 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
@@ -77,7 +77,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
77 this.commsManager = commsManager; 77 this.commsManager = commsManager;
78 } 78 }
79 79
80 protected InventoryItemBase LoadInvItem(string path, string contents) 80 protected InventoryItemBase LoadInvItem(string contents)
81 { 81 {
82 InventoryItemBase item = new InventoryItemBase(); 82 InventoryItemBase item = new InventoryItemBase();
83 StringReader sr = new StringReader(contents); 83 StringReader sr = new StringReader(contents);
@@ -183,9 +183,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
183 } 183 }
184 } 184 }
185 185
186 InventoryFolderImpl inventoryFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath); 186 InventoryFolderImpl rootDestinationFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath);
187 187
188 if (null == inventoryFolder) 188 if (null == rootDestinationFolder)
189 { 189 {
190 // TODO: Later on, automatically create this folder if it does not exist 190 // TODO: Later on, automatically create this folder if it does not exist
191 m_log.ErrorFormat("[INVENTORY ARCHIVER]: Inventory path {0} does not exist", m_invPath); 191 m_log.ErrorFormat("[INVENTORY ARCHIVER]: Inventory path {0} does not exist", m_invPath);
@@ -199,7 +199,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
199 TarArchiveReader.TarEntryType entryType; 199 TarArchiveReader.TarEntryType entryType;
200 while ((data = archive.ReadEntry(out filePath, out entryType)) != null) 200 while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
201 { 201 {
202 if (entryType == TarArchiveReader.TarEntryType.TYPE_DIRECTORY) { 202 if (entryType == TarArchiveReader.TarEntryType.TYPE_DIRECTORY)
203 {
203 m_log.WarnFormat("[INVENTORY ARCHIVER]: Ignoring directory entry {0}", filePath); 204 m_log.WarnFormat("[INVENTORY ARCHIVER]: Ignoring directory entry {0}", filePath);
204 } 205 }
205 else if (filePath.StartsWith(InventoryArchiveConstants.ASSETS_PATH)) 206 else if (filePath.StartsWith(InventoryArchiveConstants.ASSETS_PATH))
@@ -211,7 +212,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
211 } 212 }
212 else if (filePath.StartsWith(InventoryArchiveConstants.INVENTORY_PATH)) 213 else if (filePath.StartsWith(InventoryArchiveConstants.INVENTORY_PATH))
213 { 214 {
214 InventoryItemBase item = LoadInvItem(filePath, m_asciiEncoding.GetString(data)); 215 InventoryItemBase item = LoadInvItem(m_asciiEncoding.GetString(data));
215 216
216 if (item != null) 217 if (item != null)
217 { 218 {
@@ -220,11 +221,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
220 221
221 item.Creator = m_userInfo.UserProfile.ID; 222 item.Creator = m_userInfo.UserProfile.ID;
222 item.Owner = m_userInfo.UserProfile.ID; 223 item.Owner = m_userInfo.UserProfile.ID;
224
225 filePath = filePath.Substring(InventoryArchiveConstants.INVENTORY_PATH.Length);
226 string[] rawFolders = filePath.Split(new char[] { '/' });
227
228 // Find the folders that do exist along the path given
229 int i = 0;
230 bool noFolder = false;
231 InventoryFolderImpl foundFolder = rootDestinationFolder;
232 while (!noFolder && i < rawFolders.Length)
233 {
234 foundFolder = foundFolder.FindFolderByPath(rawFolders[i]);
235 if (null == foundFolder)
236 noFolder = true;
237 else
238 i++;
239 }
240
241 // Create any folders that did not previously exist
242 while (i < rawFolders.Length)
243 {
244 foundFolder.CreateChildFolder(UUID.Random(), rawFolders[i++], (ushort)AssetType.Folder);
245 }
223 246
224 // Reset folder ID to the one in which we want to load it 247 // Reset folder ID to the one in which we want to load it
225 // TODO: Properly restore entire folder structure. At the moment all items are dumped in this 248 // TODO: Properly restore entire folder structure. At the moment all items are dumped in this
226 // single folder no matter where in the saved folder structure they are. 249 // single folder no matter where in the saved folder structure they are.
227 item.Folder = inventoryFolder.ID; 250 item.Folder = foundFolder.ID;
228 251
229 m_userInfo.AddItem(item); 252 m_userInfo.AddItem(item);
230 successfulItemRestores++; 253 successfulItemRestores++;