diff options
author | Justin Clark-Casey (justincc) | 2010-07-14 20:43:35 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-07-14 20:43:35 +0100 |
commit | 8c10cb5ffe783d457184923d32e8baea5321ed1d (patch) | |
tree | dcebba549aeb5744e872c587814b48f309f6ccd4 /OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC_OLD-8c10cb5ffe783d457184923d32e8baea5321ed1d.zip opensim-SC_OLD-8c10cb5ffe783d457184923d32e8baea5321ed1d.tar.gz opensim-SC_OLD-8c10cb5ffe783d457184923d32e8baea5321ed1d.tar.bz2 opensim-SC_OLD-8c10cb5ffe783d457184923d32e8baea5321ed1d.tar.xz |
improve closing of load/save iar streams in the event of a problem
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs | 139 |
1 files changed, 69 insertions, 70 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index 2c2724e..25a78ff 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs | |||
@@ -119,22 +119,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
119 | protected void ReceivedAllAssets(ICollection<UUID> assetsFoundUuids, ICollection<UUID> assetsNotFoundUuids) | 119 | protected void ReceivedAllAssets(ICollection<UUID> assetsFoundUuids, ICollection<UUID> assetsNotFoundUuids) |
120 | { | 120 | { |
121 | Exception reportedException = null; | 121 | Exception reportedException = null; |
122 | bool succeeded = true; | 122 | bool succeeded = true; |
123 | 123 | ||
124 | try | 124 | try |
125 | { | 125 | { |
126 | // We're almost done. Just need to write out the control file now | 126 | // We're almost done. Just need to write out the control file now |
127 | m_archiveWriter.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p1ControlFile()); | 127 | m_archiveWriter.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p1ControlFile()); |
128 | m_log.InfoFormat("[ARCHIVER]: Added control file to archive."); | 128 | m_log.InfoFormat("[ARCHIVER]: Added control file to archive."); |
129 | |||
130 | m_archiveWriter.Close(); | 129 | m_archiveWriter.Close(); |
131 | } | 130 | } |
132 | catch (Exception e) | 131 | catch (Exception e) |
133 | { | 132 | { |
134 | m_saveStream.Close(); | ||
135 | reportedException = e; | 133 | reportedException = e; |
136 | succeeded = false; | 134 | succeeded = false; |
137 | } | 135 | } |
136 | finally | ||
137 | { | ||
138 | m_saveStream.Close(); | ||
139 | } | ||
138 | 140 | ||
139 | m_module.TriggerInventoryArchiveSaved( | 141 | m_module.TriggerInventoryArchiveSaved( |
140 | m_id, succeeded, m_userInfo, m_invPath, m_saveStream, reportedException); | 142 | m_id, succeeded, m_userInfo, m_invPath, m_saveStream, reportedException); |
@@ -213,70 +215,68 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
213 | /// </summary> | 215 | /// </summary> |
214 | public void Execute() | 216 | public void Execute() |
215 | { | 217 | { |
216 | InventoryFolderBase inventoryFolder = null; | 218 | try |
217 | InventoryItemBase inventoryItem = null; | ||
218 | InventoryFolderBase rootFolder = m_scene.InventoryService.GetRootFolder(m_userInfo.PrincipalID); | ||
219 | |||
220 | bool foundStar = false; | ||
221 | |||
222 | // Eliminate double slashes and any leading / on the path. | ||
223 | string[] components | ||
224 | = m_invPath.Split( | ||
225 | new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries); | ||
226 | |||
227 | int maxComponentIndex = components.Length - 1; | ||
228 | |||
229 | // If the path terminates with a STAR then later on we want to archive all nodes in the folder but not the | ||
230 | // folder itself. This may get more sophisicated later on | ||
231 | if (maxComponentIndex >= 0 && components[maxComponentIndex] == STAR_WILDCARD) | ||
232 | { | ||
233 | foundStar = true; | ||
234 | maxComponentIndex--; | ||
235 | } | ||
236 | |||
237 | m_invPath = String.Empty; | ||
238 | for (int i = 0; i <= maxComponentIndex; i++) | ||
239 | { | ||
240 | m_invPath += components[i] + InventoryFolderImpl.PATH_DELIMITER; | ||
241 | } | ||
242 | |||
243 | // Annoyingly Split actually returns the original string if the input string consists only of delimiters | ||
244 | // Therefore if we still start with a / after the split, then we need the root folder | ||
245 | if (m_invPath.Length == 0) | ||
246 | { | ||
247 | inventoryFolder = rootFolder; | ||
248 | } | ||
249 | else | ||
250 | { | ||
251 | m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER)); | ||
252 | List<InventoryFolderBase> candidateFolders | ||
253 | = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, rootFolder, m_invPath); | ||
254 | if (candidateFolders.Count > 0) | ||
255 | inventoryFolder = candidateFolders[0]; | ||
256 | } | ||
257 | |||
258 | // The path may point to an item instead | ||
259 | if (inventoryFolder == null) | ||
260 | { | ||
261 | inventoryItem = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, rootFolder, m_invPath); | ||
262 | //inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath); | ||
263 | } | ||
264 | |||
265 | if (null == inventoryFolder && null == inventoryItem) | ||
266 | { | 219 | { |
267 | // We couldn't find the path indicated | 220 | InventoryFolderBase inventoryFolder = null; |
268 | string errorMessage = string.Format("Aborted save. Could not find inventory path {0}", m_invPath); | 221 | InventoryItemBase inventoryItem = null; |
269 | m_log.ErrorFormat("[INVENTORY ARCHIVER]: {0}", errorMessage); | 222 | InventoryFolderBase rootFolder = m_scene.InventoryService.GetRootFolder(m_userInfo.PrincipalID); |
270 | m_module.TriggerInventoryArchiveSaved( | 223 | |
271 | m_id, false, m_userInfo, m_invPath, m_saveStream, | 224 | bool foundStar = false; |
272 | new Exception(errorMessage)); | 225 | |
273 | return; | 226 | // Eliminate double slashes and any leading / on the path. |
274 | } | 227 | string[] components |
228 | = m_invPath.Split( | ||
229 | new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries); | ||
230 | |||
231 | int maxComponentIndex = components.Length - 1; | ||
232 | |||
233 | // If the path terminates with a STAR then later on we want to archive all nodes in the folder but not the | ||
234 | // folder itself. This may get more sophisicated later on | ||
235 | if (maxComponentIndex >= 0 && components[maxComponentIndex] == STAR_WILDCARD) | ||
236 | { | ||
237 | foundStar = true; | ||
238 | maxComponentIndex--; | ||
239 | } | ||
240 | |||
241 | m_invPath = String.Empty; | ||
242 | for (int i = 0; i <= maxComponentIndex; i++) | ||
243 | { | ||
244 | m_invPath += components[i] + InventoryFolderImpl.PATH_DELIMITER; | ||
245 | } | ||
246 | |||
247 | // Annoyingly Split actually returns the original string if the input string consists only of delimiters | ||
248 | // Therefore if we still start with a / after the split, then we need the root folder | ||
249 | if (m_invPath.Length == 0) | ||
250 | { | ||
251 | inventoryFolder = rootFolder; | ||
252 | } | ||
253 | else | ||
254 | { | ||
255 | m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER)); | ||
256 | List<InventoryFolderBase> candidateFolders | ||
257 | = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, rootFolder, m_invPath); | ||
258 | if (candidateFolders.Count > 0) | ||
259 | inventoryFolder = candidateFolders[0]; | ||
260 | } | ||
261 | |||
262 | // The path may point to an item instead | ||
263 | if (inventoryFolder == null) | ||
264 | { | ||
265 | inventoryItem = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, rootFolder, m_invPath); | ||
266 | //inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath); | ||
267 | } | ||
268 | |||
269 | if (null == inventoryFolder && null == inventoryItem) | ||
270 | { | ||
271 | // We couldn't find the path indicated | ||
272 | string errorMessage = string.Format("Aborted save. Could not find inventory path {0}", m_invPath); | ||
273 | Exception e = new InventoryArchiverException(errorMessage); | ||
274 | m_module.TriggerInventoryArchiveSaved(m_id, false, m_userInfo, m_invPath, m_saveStream, e); | ||
275 | throw e; | ||
276 | } | ||
275 | 277 | ||
276 | m_archiveWriter = new TarArchiveWriter(m_saveStream); | 278 | m_archiveWriter = new TarArchiveWriter(m_saveStream); |
277 | 279 | ||
278 | try | ||
279 | { | ||
280 | if (inventoryFolder != null) | 280 | if (inventoryFolder != null) |
281 | { | 281 | { |
282 | m_log.DebugFormat( | 282 | m_log.DebugFormat( |
@@ -297,16 +297,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
297 | 297 | ||
298 | // Don't put all this profile information into the archive right now. | 298 | // Don't put all this profile information into the archive right now. |
299 | //SaveUsers(); | 299 | //SaveUsers(); |
300 | |||
301 | new AssetsRequest( | ||
302 | new AssetsArchiver(m_archiveWriter), m_assetUuids, m_scene.AssetService, ReceivedAllAssets).Execute(); | ||
300 | } | 303 | } |
301 | catch (Exception) | 304 | catch (Exception) |
302 | { | 305 | { |
303 | m_archiveWriter.Close(); | 306 | m_saveStream.Close(); |
304 | throw; | 307 | throw; |
305 | } | 308 | } |
306 | |||
307 | new AssetsRequest( | ||
308 | new AssetsArchiver(m_archiveWriter), m_assetUuids, | ||
309 | m_scene.AssetService, ReceivedAllAssets).Execute(); | ||
310 | } | 309 | } |
311 | 310 | ||
312 | /// <summary> | 311 | /// <summary> |