Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Dotnet.Script.DependencyModel.Environment;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Dotnet.Script.DependencyModel.Environment;
using SysEnvironment = System.Environment;

namespace Dotnet.Script.DependencyModel.ProjectSystem
Expand Down Expand Up @@ -51,8 +51,14 @@ public static string GetTempPath()
{
// prefer the custom env variable if set
var cachePath = SysEnvironment.GetEnvironmentVariable("DOTNET_SCRIPT_CACHE_LOCATION");

if (!string.IsNullOrEmpty(cachePath))
{
// if the path is not absolute, make it relative to the current folder
if (!Path.IsPathRooted(cachePath))
{
cachePath = Path.Combine(Directory.GetCurrentDirectory(), cachePath);
}
return cachePath;
}

Expand Down
42 changes: 42 additions & 0 deletions src/Dotnet.Script.Tests/FileUtilsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.IO;
using Dotnet.Script.DependencyModel.ProjectSystem;
using Xunit;

namespace Dotnet.Script.Tests
{
public class FileUtilsTests
{
[Fact]
public void GetTempPathCanBeOverridenWithAbsolutePathViaEnvVar()
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
try
{
Environment.SetEnvironmentVariable("DOTNET_SCRIPT_CACHE_LOCATION", path);
var tempPath = FileUtils.GetTempPath();
Assert.Equal(path, tempPath);
}
finally
{
Environment.SetEnvironmentVariable("DOTNET_SCRIPT_CACHE_LOCATION", null);
}
}

[Fact]
public void GetTempPathCanBeOverridenWithRelativePathViaEnvVar()
{
var path = "foo";
try
{
Environment.SetEnvironmentVariable("DOTNET_SCRIPT_CACHE_LOCATION", path);
var tempPath = FileUtils.GetTempPath();
Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), path), tempPath);
}
finally
{
Environment.SetEnvironmentVariable("DOTNET_SCRIPT_CACHE_LOCATION", null);
}
}
}
}
3 changes: 1 addition & 2 deletions src/Dotnet.Script.Tests/NuGetSourceReferenceResolverTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Text;
Expand Down