File tree 3 files changed +51
-4
lines changed
Dotnet.Script.DependencyModel/ProjectSystem
3 files changed +51
-4
lines changed Original file line number Diff line number Diff line change 1
- using Dotnet . Script . DependencyModel . Environment ;
2
- using System ;
1
+ using System ;
3
2
using System . Collections . Generic ;
4
3
using System . IO ;
5
4
using System . Runtime . InteropServices ;
6
5
using System . Text ;
6
+ using Dotnet . Script . DependencyModel . Environment ;
7
7
using SysEnvironment = System . Environment ;
8
8
9
9
namespace Dotnet . Script . DependencyModel . ProjectSystem
@@ -51,8 +51,14 @@ public static string GetTempPath()
51
51
{
52
52
// prefer the custom env variable if set
53
53
var cachePath = SysEnvironment . GetEnvironmentVariable ( "DOTNET_SCRIPT_CACHE_LOCATION" ) ;
54
+
54
55
if ( ! string . IsNullOrEmpty ( cachePath ) )
55
56
{
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
+ }
56
62
return cachePath ;
57
63
}
58
64
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
- using System ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
3
2
using System . Collections . Immutable ;
4
3
using System . IO ;
5
4
using System . Text ;
You can’t perform that action at this time.
0 commit comments