From f76dceb90b5a76a7b6a5243c9032996c007c0cf5 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Wed, 24 Oct 2012 03:08:58 +0100
Subject: Get "save oar" and "save iar" to tell you in a more friendly manner
if the filename to save already exists, rather than exception throwing.
Also changes ConsoleUtil.CheckFileExists to CheckFileDoesNotExist() since this is more meaningful in the context, even though it does result in double negatives.
---
OpenSim/Framework/Console/ConsoleUtil.cs | 19 +++++++++++++++++++
.../Inventory/Archiver/InventoryArchiverModule.cs | 4 ++++
.../CoreModules/World/Archiver/ArchiverModule.cs | 18 +++++++++++-------
.../World/Objects/Commands/ObjectCommandsModule.cs | 5 +----
.../Region/OptionalModules/Asset/AssetInfoModule.cs | 3 +++
OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 3 +++
6 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs
index 5c25ccb..3ebfdf8 100644
--- a/OpenSim/Framework/Console/ConsoleUtil.cs
+++ b/OpenSim/Framework/Console/ConsoleUtil.cs
@@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Reflection;
using log4net;
@@ -60,6 +61,24 @@ namespace OpenSim.Framework.Console
public const string VectorSeparator = ",";
public static char[] VectorSeparatorChars = VectorSeparator.ToCharArray();
+
+ ///
+ /// Check if the given file path exists.
+ ///
+ /// If not, warning is printed to the given console.
+ /// true if the file does not exist, false otherwise.
+ ///
+ ///
+ public static bool CheckFileDoesNotExist(ICommandConsole console, string path)
+ {
+ if (File.Exists(path))
+ {
+ console.OutputFormat("File {0} already exists. Please move or remove it.", path);
+ return false;
+ }
+
+ return true;
+ }
///
/// Try to parse a console UUID from the console.
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
index cf87010..afe1200 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
@@ -35,6 +35,7 @@ using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
+using OpenSim.Framework.Console;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
@@ -209,6 +210,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
Guid id, string firstName, string lastName, string invPath, string pass, string savePath,
Dictionary options)
{
+ if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, savePath))
+ return false;
+
if (m_scenes.Count > 0)
{
UserAccount userInfo = GetUserInfo(firstName, lastName, pass);
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
index 2a87dc2..970487a 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs
@@ -32,6 +32,8 @@ using System.Reflection;
using log4net;
using NDesk.Options;
using Nini.Config;
+using OpenSim.Framework;
+using OpenSim.Framework.Console;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
@@ -117,7 +119,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
//
// foreach (string param in mainParams)
// m_log.DebugFormat("GOT PARAM [{0}]", param);
-
+
if (mainParams.Count > 2)
{
DearchiveRegion(mainParams[2], mergeOar, skipAssets, Guid.Empty);
@@ -150,14 +152,16 @@ namespace OpenSim.Region.CoreModules.World.Archiver
List mainParams = ops.Parse(cmdparams);
+ string path;
if (mainParams.Count > 2)
- {
- ArchiveRegion(mainParams[2], options);
- }
+ path = mainParams[2];
else
- {
- ArchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, options);
- }
+ path = DEFAULT_OAR_BACKUP_FILENAME;
+
+ if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, path))
+ return;
+
+ ArchiveRegion(path, options);
}
public void ArchiveRegion(string savePath, Dictionary options)
diff --git a/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs
index 41a1afd..f0a35ad 100644
--- a/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs
+++ b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs
@@ -485,11 +485,8 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
string fileName = string.Format("{0}.xml", objectUuid);
- if (File.Exists(fileName))
- {
- m_console.OutputFormat("File {0} already exists. Please move or remove it.", fileName);
+ if (!ConsoleUtil.CheckFileDoesNotExist(m_console, fileName))
return;
- }
using (XmlTextWriter xtw = new XmlTextWriter(fileName, Encoding.UTF8))
{
diff --git a/OpenSim/Region/OptionalModules/Asset/AssetInfoModule.cs b/OpenSim/Region/OptionalModules/Asset/AssetInfoModule.cs
index 41ec14f..7639c6c 100644
--- a/OpenSim/Region/OptionalModules/Asset/AssetInfoModule.cs
+++ b/OpenSim/Region/OptionalModules/Asset/AssetInfoModule.cs
@@ -127,6 +127,9 @@ namespace OpenSim.Region.OptionalModules.Asset
}
string fileName = rawAssetId;
+
+ if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, fileName))
+ return;
using (FileStream fs = new FileStream(fileName, FileMode.CreateNew))
{
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
index 46b0c67..4123f49 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
@@ -141,6 +141,9 @@ namespace OpenSim.Server.Handlers.Asset
}
string fileName = rawAssetId;
+
+ if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, fileName))
+ return;
using (FileStream fs = new FileStream(fileName, FileMode.CreateNew))
{
--
cgit v1.1