@@ -9,8 +9,10 @@ import (
9
9
"encoding/json"
10
10
"errors"
11
11
"fmt"
12
+ "github.com/hectane/go-acl"
12
13
"os"
13
14
"path/filepath"
15
+ "runtime"
14
16
"strings"
15
17
"time"
16
18
@@ -568,7 +570,19 @@ func getSourceURI(ctx context.Context, f *atesting.Fixture, unprivileged bool) (
568
570
}
569
571
if unprivileged {
570
572
// move the file to temp directory
571
- dir , err := os .MkdirTemp ("" , "agent-upgrade-*" )
573
+ baseTmp := ""
574
+ if runtime .GOOS == "windows" {
575
+ // `elastic-agent-user` needs to have access to the file, default
576
+ // will place this in C:\Users\windows\AppData\Local\Temp\ which
577
+ // `elastic-agent-user` doesn't have access.
578
+
579
+ // create C:\Temp with world read/write to use for temp directory
580
+ baseTmp , err = windowsBaseTemp ()
581
+ if err != nil {
582
+ return "" , fmt .Errorf ("failed to create windows base temp path: %w" , err )
583
+ }
584
+ }
585
+ dir , err := os .MkdirTemp (baseTmp , "agent-upgrade-*" )
572
586
if err != nil {
573
587
return "" , fmt .Errorf ("failed to create temp directory: %w" , err )
574
588
}
@@ -590,3 +604,22 @@ func getSourceURI(ctx context.Context, f *atesting.Fixture, unprivileged bool) (
590
604
}
591
605
return "file://" + filepath .Dir (srcPkg ), nil
592
606
}
607
+
608
+ func windowsBaseTemp () (string , error ) {
609
+ baseTmp := "C:\\ Temp"
610
+ _ , err := os .Stat (baseTmp )
611
+ if err != nil {
612
+ if ! errors .Is (err , os .ErrNotExist ) {
613
+ return "" , fmt .Errorf ("failed to stat %s: %w" , baseTmp , err )
614
+ }
615
+ err = os .Mkdir (baseTmp , 0777 )
616
+ if err != nil {
617
+ return "" , fmt .Errorf ("failed to mkdir %s: %w" , baseTmp , err )
618
+ }
619
+ }
620
+ err = acl .Chmod (baseTmp , 0777 )
621
+ if err != nil {
622
+ return "" , fmt .Errorf ("failed to chmod %s: %w" , baseTmp , err )
623
+ }
624
+ return baseTmp , nil
625
+ }
0 commit comments