Skip to content

Commit

Permalink
fix: windows installation for restic 0.17.1 (#474)
Browse files Browse the repository at this point in the history
Note: this fix relocates the restic binary on windows to C:\Program Files\backrest  OR to the directory where backrest is installed (path relative).
  • Loading branch information
garethgeorge committed Sep 14, 2024
1 parent d2650fd commit 4da9d89
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
6 changes: 3 additions & 3 deletions internal/env/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions internal/resticinstaller/resticinstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions pkg/restic/restic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 4da9d89

Please sign in to comment.