diff --git a/main.go b/main.go index 0765e64..bf6dd9a 100644 --- a/main.go +++ b/main.go @@ -199,7 +199,7 @@ func buildMenu() *resticmenu { systray.AddSeparator() mnu.backupNow = systray.AddMenuItem("Backup now", "Backup now") mnu.backupNow.Disable() - mnu.browse = systray.AddMenuItem("Browse backups in Finder...", "Mount and browse backups") + mnu.browse = systray.AddMenuItem("Browse backups folders...", "Mount and browse backups") mnu.logs = systray.AddMenuItem("Open logfile...", "Open logging file") mnu.config = systray.AddMenuItem("Open config file...", "Open config file") systray.AddSeparator() diff --git a/restic/config.go b/restic/config.go index 7a03ba9..6bcaa9b 100644 --- a/restic/config.go +++ b/restic/config.go @@ -45,13 +45,13 @@ func ConfigFile() string { return filepath.Join(configDir, "config.json") } -func (cnf *Config) MountDir() string { +func MountDir() string { return filepath.Join(configDir, "mnt") } func (cnf *Config) CreateMountDirIfDoesntExist() error { - if _, err := os.Stat(cnf.MountDir()); os.IsNotExist(err) { - return os.Mkdir(cnf.MountDir(), os.ModePerm) + if _, err := os.Stat(MountDir()); os.IsNotExist(err) { + return os.Mkdir(MountDir(), os.ModePerm) } return nil } @@ -70,6 +70,15 @@ func ReadConfig() (*Config, error) { if err != nil { log.Warn().Err(err).Msg("No config.json found, writing default") + + // in case the base config dir doesn't exist, create it + if _, err := os.Stat(configDir); os.IsNotExist(err) { + err = os.Mkdir(configDir, os.ModePerm) + if err != nil { + return nil, err + } + } + conf = defaultConfig() confData, _ := json.Marshal(conf) os.WriteFile(ConfigFile(), confData, os.ModePerm) @@ -89,10 +98,10 @@ func ReadConfig() (*Config, error) { } if _, err := os.Stat(ExcludeFile()); os.IsNotExist(err) { - os.WriteFile(ExcludeFile(), []byte(""), os.ModePerm) + os.WriteFile(ExcludeFile(), []byte("node_modules"), os.ModePerm) } if _, err := os.Stat(PasswordFile()); os.IsNotExist(err) { - os.WriteFile(PasswordFile(), []byte(""), os.ModePerm) + os.WriteFile(PasswordFile(), []byte("password"), os.ModePerm) } return conf, nil diff --git a/restic/util.go b/restic/util.go index adda4f7..e0a7c7f 100644 --- a/restic/util.go +++ b/restic/util.go @@ -2,11 +2,12 @@ package restic import ( "os" + "path/filepath" "time" ) var home, _ = os.UserHomeDir() var executable, _ = os.Executable() var isDev = os.Getenv("RESTICTRAY_DEV") -var configDir = home + "/.restic/" +var configDir = filepath.Join(home, ".restic") var timeNow = time.Now diff --git a/restic/wrapper.go b/restic/wrapper.go index 7874c8f..6d7caa9 100644 --- a/restic/wrapper.go +++ b/restic/wrapper.go @@ -53,7 +53,7 @@ func (w *Wrapper) Cleanup() { // Could be killed or terminated due to manual unmount, ignore errors and retry anyway w.mountCommand.Process.Kill() // Sometimes not correctly unmounted causing consecutive open attempts of mounted folder to fail - exec.Command("umount", "restic").Run() + exec.Command("umount", MountDir()).Run() } } @@ -78,12 +78,12 @@ func (w *Wrapper) MountBackups(c *Config) error { w.Cleanup() // Open the folder first: MacFuse could take a second; results in occasional weird errors otherwise. - err := openFolder(c.MountDir()) + err := openFolder(MountDir()) if err != nil { return err } - w.mountCommand = resticCmd("--password-file", PasswordFile(), "-r", c.Repository, "mount", c.MountDir()) + w.mountCommand = resticCmd("--password-file", PasswordFile(), "-r", c.Repository, "mount", MountDir()) err = w.mountCommand.Start() // restic's mount is a blocking call if err != nil { return fmt.Errorf("restic mount cmd: %w", err) @@ -141,7 +141,7 @@ func (w *Wrapper) UpdateLatestSnapshots(c *Config) error { // Backup uses "restic backup" to create a new snapshot. This is a blocking call. // Returns a ResticCmdTimeoutError if no response from restic after cmdTimeout func (w *Wrapper) Backup(c *Config) error { - cmd := resticCmd("--password-file", PasswordFile(), "-r", c.Repository, "--exclude-file", ExcludeFile(), "backup", c.Backup, "--no-scan") + cmd := resticCmd("--password-file", PasswordFile(), "-r", c.Repository, "--exclude-file", ExcludeFile(), "backup", c.Backup) stdout, _ := cmd.StdoutPipe() busy := make(chan bool, 1)