Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Adding more fallbacks for BufferingHelper temporary folder location #217

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Microsoft.AspNet.Http.Core/BufferingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.IO;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.WebUtilities;

namespace Microsoft.AspNet.Http.Core
Expand All @@ -16,11 +15,12 @@ public static string TempDirectory
{
get
{
var temp = Environment.GetEnvironmentVariable("ASPNET_TEMP");
if (string.IsNullOrEmpty(temp))
{
temp = Environment.GetEnvironmentVariable("TEMP");
}
// Look for folders in the following order.
var temp = Environment.GetEnvironmentVariable("ASPNET_TEMP") ?? // ASPNET_TEMP - User set temporary location.
Environment.GetEnvironmentVariable("TEMP") ?? // TEMP - Points to AppData\Local on Windows.
Environment.GetEnvironmentVariable("TMPDIR") ?? // TMPDIR - Temporary folder on Mac and some linux distributions.
Environment.GetEnvironmentVariable("TMP") ?? // TMP
"/tmp"; // Fallback

if (!Directory.Exists(temp))
{
Expand Down
19 changes: 19 additions & 0 deletions test/Microsoft.AspNet.Http.Core.Tests/BufferingHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.IO;
using Xunit;

namespace Microsoft.AspNet.Http.Core.Tests
{
public class BufferingHelperTests
{
[Fact]
public void GetTempDirectory_Returns_Valid_Location()
{
var tempDirectory = BufferingHelper.TempDirectory;
Assert.NotNull(tempDirectory);
Assert.True(Directory.Exists(tempDirectory));
}
}
}