From e7be6967b6d14b5cca67018dd1a30e4fc302001a Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Sat, 28 Jun 2014 16:52:33 +0200 Subject: [PATCH] Fixed Tempfolder to use the system tempfolder instead of hardcoded /var/tmp --- HttpServer/FormDecoders/MultipartDecoder.cs | 12 +++++++----- HttpServer/HttpServer.cs | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/HttpServer/FormDecoders/MultipartDecoder.cs b/HttpServer/FormDecoders/MultipartDecoder.cs index b4a6dbb..6da4967 100755 --- a/HttpServer/FormDecoders/MultipartDecoder.cs +++ b/HttpServer/FormDecoders/MultipartDecoder.cs @@ -22,6 +22,12 @@ namespace HttpServer.FormDecoders /// form-data /// public const string FormData = "form-data"; + + /// + /// Gets the temp folder used to store multi-part uploads + /// + public static readonly string Tempfolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "HttpServer"); + #region IFormDecoder Members /// @@ -73,11 +79,7 @@ namespace HttpServer.FormDecoders // Generate a filename string filename = element.Filename; - string internetCache = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache); - // if the internet path doesn't exist, assume mono and /var/tmp - string path = string.IsNullOrEmpty(internetCache) - ? Path.Combine("var", "tmp") - : Path.Combine(internetCache.Replace("\\\\", "\\"), "tmp"); + string path = Tempfolder; element.Filename = Path.Combine(path, Math.Abs(element.Filename.GetHashCode()) + ".tmp"); // If the file exists generate a new filename diff --git a/HttpServer/HttpServer.cs b/HttpServer/HttpServer.cs index 9dd4215..4ecf16a 100755 --- a/HttpServer/HttpServer.cs +++ b/HttpServer/HttpServer.cs @@ -476,15 +476,17 @@ namespace HttpServer _components.AddInstance(new HttpContextFactory(LogWriter, 16384, _components.Get())); - // the special folder does not exist on mono - string tempPath = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache); - if (string.IsNullOrEmpty(tempPath)) - tempPath = "/var/tmp/"; + string tempPath = System.IO.Path.GetTempPath(); if (!Directory.Exists(tempPath)) { WriteLog(this, LogPrio.Warning, "Temp path do not exist: " + tempPath); return; } + + tempPath = MultipartDecoder.Tempfolder; + if (!Directory.Exists(tempPath)) + Directory.CreateDirectory(tempPath); + DirectoryInfo info = new DirectoryInfo(tempPath); foreach (FileInfo file in info.GetFiles("*.tmp")) file.Delete(); -- 1.8.4.2