mirror of
https://github.com/garethgeorge/backrest.git
synced 2026-09-23 00:15:45 +00:00
fix: use command mode when executing powershell scripts on windows (#569)
This commit is contained in:
@@ -248,16 +248,17 @@ func TestMultipleBackup(t *testing.T) {
|
||||
|
||||
func TestHookExecution(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("skipping test on windows")
|
||||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
|
||||
hookOutputBefore := path.Join(dir, "before.txt")
|
||||
hookOutputAfter := path.Join(dir, "after.txt")
|
||||
|
||||
commandBefore := fmt.Sprintf("echo before > %s", hookOutputBefore)
|
||||
commandAfter := fmt.Sprintf("echo after > %s", hookOutputAfter)
|
||||
if runtime.GOOS == "windows" {
|
||||
commandBefore = fmt.Sprintf("echo \"before\" | Out-File -FilePath %q", hookOutputBefore)
|
||||
commandAfter = fmt.Sprintf("echo \"after\" | Out-File -FilePath %q", hookOutputAfter)
|
||||
}
|
||||
|
||||
sut := createSystemUnderTest(t, &config.MemoryStore{
|
||||
Config: &v1.Config{
|
||||
Modno: 1234,
|
||||
@@ -287,7 +288,7 @@ func TestHookExecution(t *testing.T) {
|
||||
},
|
||||
Action: &v1.Hook_ActionCommand{
|
||||
ActionCommand: &v1.Hook_Command{
|
||||
Command: "echo before > " + hookOutputBefore,
|
||||
Command: commandBefore,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -297,7 +298,7 @@ func TestHookExecution(t *testing.T) {
|
||||
},
|
||||
Action: &v1.Hook_ActionCommand{
|
||||
ActionCommand: &v1.Hook_Command{
|
||||
Command: "echo after > " + hookOutputAfter,
|
||||
Command: commandAfter,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -34,7 +34,7 @@ func (commandHandler) Execute(ctx context.Context, h *v1.Hook, vars interface{},
|
||||
// Parse out the shell to use if a #! prefix is present
|
||||
shell := []string{"sh"}
|
||||
if runtime.GOOS == "windows" {
|
||||
shell = []string{"powershell", "-nologo", "-noprofile"}
|
||||
shell = []string{"powershell", "-NoLogo", "-NoProfile", "-Command", "-"}
|
||||
}
|
||||
|
||||
if len(command) > 2 && command[0:2] == "#!" {
|
||||
|
||||
Reference in New Issue
Block a user