From 01ca3a91ad8741665838260728193e5ba8deba7f Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Tue, 19 May 2009 19:41:01 +0000 Subject: * Take another attempt at http://opensimulator.org/mantis/view.php?id=3191 * Return something more sensible if a file isn't found --- .../World/Archiver/ArchiveReadRequest.cs | 26 ++++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs index a3ec419..2b1c552 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs @@ -423,15 +423,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// private Stream GetStream(string path) { - try + if (File.Exists(path)) { - if (File.Exists(path)) - { - return new FileStream(path, FileMode.Open, FileAccess.Read); - } - else + return new FileStream(path, FileMode.Open, FileAccess.Read); + } + else + { + try { - Uri uri = new Uri(path); // throw exception if not valid URI + Uri uri = new Uri(path); if (uri.Scheme == "file") { return new FileStream(uri.AbsolutePath, FileMode.Open, FileAccess.Read); @@ -446,16 +446,18 @@ namespace OpenSim.Region.CoreModules.World.Archiver return URIFetch(uri); } } - } - catch (Exception e) - { - throw new Exception(String.Format("Unable to create file input stream for {0}: {1}", path, e.Message)); + catch (UriFormatException) + { + // In many cases the user will put in a plain old filename that cannot be found so assume that + // this is the problem rather than confusing the issue with a UriFormatException + throw new Exception(String.Format("Cannot find file {0}", path)); + } } } private static Stream URIFetch(Uri uri) { - HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri); + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); // request.Credentials = credentials; -- cgit v1.1