Linux compatibility implementation

This commit is contained in:
Wouter Groeneveld 2023-03-14 21:19:50 +01:00
parent 6c32ff3af3
commit 63f7abc305
4 changed files with 21 additions and 11 deletions

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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)