Skip to content

Commit e1997aa

Browse files
authored
Merge pull request #699 from dotnet-script/bugfix/cache-path
allow DOTNET_SCRIPT_CACHE_LOCATION to be relative
2 parents 01ff5ac + 7ee51b0 commit e1997aa

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using Dotnet.Script.DependencyModel.Environment;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.IO;
54
using System.Runtime.InteropServices;
65
using System.Text;
6+
using Dotnet.Script.DependencyModel.Environment;
77
using SysEnvironment = System.Environment;
88

99
namespace Dotnet.Script.DependencyModel.ProjectSystem
@@ -51,8 +51,14 @@ public static string GetTempPath()
5151
{
5252
// prefer the custom env variable if set
5353
var cachePath = SysEnvironment.GetEnvironmentVariable("DOTNET_SCRIPT_CACHE_LOCATION");
54+
5455
if (!string.IsNullOrEmpty(cachePath))
5556
{
57+
// if the path is not absolute, make it relative to the current folder
58+
if (!Path.IsPathRooted(cachePath))
59+
{
60+
cachePath = Path.Combine(Directory.GetCurrentDirectory(), cachePath);
61+
}
5662
return cachePath;
5763
}
5864

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.IO;
3+
using Dotnet.Script.DependencyModel.ProjectSystem;
4+
using Xunit;
5+
6+
namespace Dotnet.Script.Tests
7+
{
8+
public class FileUtilsTests
9+
{
10+
[Fact]
11+
public void GetTempPathCanBeOverridenWithAbsolutePathViaEnvVar()
12+
{
13+
var path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
14+
try
15+
{
16+
Environment.SetEnvironmentVariable("DOTNET_SCRIPT_CACHE_LOCATION", path);
17+
var tempPath = FileUtils.GetTempPath();
18+
Assert.Equal(path, tempPath);
19+
}
20+
finally
21+
{
22+
Environment.SetEnvironmentVariable("DOTNET_SCRIPT_CACHE_LOCATION", null);
23+
}
24+
}
25+
26+
[Fact]
27+
public void GetTempPathCanBeOverridenWithRelativePathViaEnvVar()
28+
{
29+
var path = "foo";
30+
try
31+
{
32+
Environment.SetEnvironmentVariable("DOTNET_SCRIPT_CACHE_LOCATION", path);
33+
var tempPath = FileUtils.GetTempPath();
34+
Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), path), tempPath);
35+
}
36+
finally
37+
{
38+
Environment.SetEnvironmentVariable("DOTNET_SCRIPT_CACHE_LOCATION", null);
39+
}
40+
}
41+
}
42+
}

src/Dotnet.Script.Tests/NuGetSourceReferenceResolverTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Collections.Immutable;
43
using System.IO;
54
using System.Text;

0 commit comments

Comments
 (0)