Skip to content

Commit

Permalink
Move agent logs outside of the virtualized %LocalAppData%
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell committed Nov 21, 2023
1 parent 7b5c9d2 commit 1646212
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions end-to-end/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ var filesToCleanUp = []struct {
}{
{prefixEnv: "LocalAppData", path: "Ubuntu Pro"},
{prefixEnv: "UserProfile", path: ".ubuntupro"},
{prefixEnv: "UserProfile", path: ".ubuntupro.log"},
}

// assertCleanFilesystem returns error if directory '%LocalAppData%/Ubuntu Pro' exists.
Expand Down
9 changes: 4 additions & 5 deletions end-to-end/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"testing"
"time"

"github.com/canonical/ubuntu-pro-for-windows/common"
"github.com/canonical/ubuntu-pro-for-windows/common/wsltestutils"
"github.com/stretchr/testify/require"
"github.com/ubuntu/gowsl"
Expand Down Expand Up @@ -202,13 +201,13 @@ func logWindowsAgentJournal(t *testing.T, skipOnSuccess bool) {
return
}

localAppData := os.Getenv("LocalAppData")
if localAppData == "" {
t.Log("could not access Windows Agent's logs: $env:LocalAppData is not assigned")
home := os.Getenv("UserProfile")
if home == "" {
t.Log("could not access Windows Agent's logs: $env:UserProfile is not assigned")
return
}

out, err := os.ReadFile(filepath.Join(localAppData, common.LocalAppDataDir, "log"))
out, err := os.ReadFile(filepath.Join(home, ".ubuntupro.log"))
if err != nil {
t.Logf("could not read Windows Agent's logs: %v", err)
return
Expand Down
8 changes: 4 additions & 4 deletions windows-agent/cmd/ubuntu-pro-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func run(a app) int {
}

func setLoggerOutput() (func(), error) {
lad := os.Getenv("LocalAppData")
if lad == "" {
return nil, errors.New("could not find LocalAppData")
home := os.Getenv("UserProfile")
if home == "" {
return nil, errors.New("environment variable %UserProfile% is empty")
}

p := filepath.Join(lad, common.LocalAppDataDir, "log")
p := filepath.Join(home, ".ubuntupro.log")

f, err := os.OpenFile(p, os.O_APPEND|os.O_CREATE, 0600)
if err != nil {
Expand Down

0 comments on commit 1646212

Please sign in to comment.