File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -42,4 +42,24 @@ Describe 'tests for function expressions' {
42
42
$out = $config_yaml | dsc config -- target- path $PSHOME get | ConvertFrom-Json
43
43
$out.results [0 ].result.actualState.output | Should - BeExactly $expected
44
44
}
45
+
46
+ It ' default targetPath() is correct for the OS' {
47
+ $config_yaml = @'
48
+ $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
49
+ resources:
50
+ - name: Echo
51
+ type: Microsoft.DSC.Debug/Echo
52
+ properties:
53
+ output: "[targetPath()]"
54
+ '@
55
+
56
+ $expected = if ($IsWindows ) {
57
+ $env: SYSTEMDRIVE + ' \'
58
+ } else {
59
+ ' /'
60
+ }
61
+ $out = $config_yaml | dsc config get | ConvertFrom-Json
62
+ $LASTEXITCODE | Should - Be 0
63
+ $out.results [0 ].result.actualState.output | Should - BeExactly $expected
64
+ }
45
65
}
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ impl Context {
25
25
Self {
26
26
execution_type : ExecutionKind :: Actual ,
27
27
outputs : HashMap :: new ( ) ,
28
- target_path : PathBuf :: new ( ) ,
28
+ target_path : get_default_os_target_path ( ) ,
29
29
parameters : HashMap :: new ( ) ,
30
30
security_context : match get_security_context ( ) {
31
31
SecurityContext :: Admin => SecurityContextKind :: Elevated ,
@@ -42,3 +42,15 @@ impl Default for Context {
42
42
Self :: new ( )
43
43
}
44
44
}
45
+
46
+ #[ cfg( target_os = "windows" ) ]
47
+ fn get_default_os_target_path ( ) -> PathBuf {
48
+ // use SYSTEMDRIVE env var to get the default target path
49
+ let system_drive = std:: env:: var ( "SYSTEMDRIVE" ) . unwrap_or_else ( |_| "C:" . to_string ( ) ) ;
50
+ PathBuf :: from ( system_drive) . join ( "\\ " )
51
+ }
52
+
53
+ #[ cfg( not( target_os = "windows" ) ) ]
54
+ fn get_default_os_target_path ( ) -> PathBuf {
55
+ PathBuf :: from ( "/" )
56
+ }
You can’t perform that action at this time.
0 commit comments