File tree Expand file tree Collapse file tree 3 files changed +51
-4
lines changed
Dotnet.Script.DependencyModel/ProjectSystem Expand file tree Collapse file tree 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 ;
32using System . Collections . Generic ;
43using System . IO ;
54using System . Runtime . InteropServices ;
65using System . Text ;
6+ using Dotnet . Script . DependencyModel . Environment ;
77using SysEnvironment = System . Environment ;
88
99namespace 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
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 ;
32using System . Collections . Immutable ;
43using System . IO ;
54using System . Text ;
You can’t perform that action at this time.
0 commit comments