From 4da9d89749fd1bdfd9701c8efb83b69a7eef3395 Mon Sep 17 00:00:00 2001 From: Gareth Date: Sat, 14 Sep 2024 02:57:50 -0700 Subject: [PATCH] fix: windows installation for restic 0.17.1 (#474) Note: this fix relocates the restic binary on windows to C:\Program Files\backrest OR to the directory where backrest is installed (path relative). --- internal/env/environment.go | 6 +++--- internal/resticinstaller/resticinstaller.go | 5 +++-- pkg/restic/restic_test.go | 6 +----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/internal/env/environment.go b/internal/env/environment.go index 1e08be37..2acaff73 100644 --- a/internal/env/environment.go +++ b/internal/env/environment.go @@ -32,7 +32,7 @@ func ConfigFilePath() string { if val := os.Getenv(EnvVarConfigPath); val != "" { return val } - return path.Join(getConfigDir(), "backrest/config.json") + return filepath.Join(getConfigDir(), "backrest", "config.json") } // DataDir @@ -50,7 +50,7 @@ func DataDir() string { } if runtime.GOOS == "windows" { - return path.Join(getConfigDir(), "backrest/data") + return filepath.Join(getConfigDir(), "backrest", "data") } return path.Join(getHomeDir(), ".local/share/backrest") } @@ -99,7 +99,7 @@ func getConfigDir() string { if val := os.Getenv("XDG_CONFIG_HOME"); val != "" { return val } - return path.Join(getHomeDir(), ".config") + return filepath.Join(getHomeDir(), ".config") } func formatBindAddress(addr string) string { diff --git a/internal/resticinstaller/resticinstaller.go b/internal/resticinstaller/resticinstaller.go index 0ce5f3ff..66e6e2eb 100644 --- a/internal/resticinstaller/resticinstaller.go +++ b/internal/resticinstaller/resticinstaller.go @@ -14,6 +14,7 @@ import ( "os" "os/exec" "path" + "path/filepath" "runtime" "strings" "sync" @@ -245,8 +246,8 @@ func FindOrInstallResticBinary() (string, error) { // Check for restic installation in data directory. resticInstallPath := path.Join(env.DataDir(), resticBinName) if runtime.GOOS == "windows" { - programFiles := os.Getenv("programfiles") - resticInstallPath = path.Join(programFiles, "backrest", resticBinName) + // on windows use a path relative to the executable. + resticInstallPath, _ = filepath.Abs(path.Join(path.Dir(os.Args[0]), resticBinName)) } // Install restic if not found. diff --git a/pkg/restic/restic_test.go b/pkg/restic/restic_test.go index 014b1eff..a941a450 100644 --- a/pkg/restic/restic_test.go +++ b/pkg/restic/restic_test.go @@ -168,12 +168,8 @@ func TestResticPartialBackup(t *testing.T) { t.Fatalf("wanted summary, got: nil") } - if summary.TotalFilesProcessed != 0 { - t.Errorf("wanted 0 files, got: %d", summary.TotalFilesProcessed) - } - if !slices.ContainsFunc(entries, func(e BackupProgressEntry) bool { - return e.MessageType == "error" && e.Item == unreadablePath + return e.MessageType == "error" && strings.Contains(e.Item, unreadablePath) }) { t.Errorf("wanted entries to contain an error event for the unreadable file (%s), but did not find it", unreadablePath) t.Logf("entries:\n")