A fix for backups umounting too early

This commit is contained in:
Marcel Otte 2022-10-10 22:55:20 +02:00
parent 8376d00973
commit 0e98dc93e9
5 changed files with 19 additions and 30 deletions

View File

@ -93,6 +93,7 @@ func (b *Backup) PrepareRun() error {
// Run runs the backup script with appropriate rights.
func (b *Backup) Run() error {
log.Printf("Running backup '%s'.", b.Name)
UiHdl.DisplayMessage("Backive backup", fmt.Sprintf("Running backup '%s'...", b.Name), MsgLevels.Info)
dev, ok := config.Devices[b.TargetDevice]
if ok {
log.Printf("Device found: %s (%s).", dev.Name, dev.UUID)
@ -157,6 +158,7 @@ func (b *Backup) Run() error {
return err
}
runs.RegisterRun(b)
UiHdl.DisplayMessage("Backive backup", fmt.Sprintf("Finished backup '%s'", b.Name), MsgLevels.Info)
return nil
}
// quit with error that the device is not available.

View File

@ -74,11 +74,15 @@ func defaultCallback(envMap map[string]string) {
if rerr != nil {
log.Printf("Error running the backup routine: %v", err)
}
dev.Unmount()
} else {
log.Printf("Backup '%s' can not run (error or frequency not reached): %s", backup.Name, err)
msg := fmt.Sprintf("Backup '%s' can not run (error or frequency not reached): %s", backup.Name, err)
log.Printf(msg)
backive.UiHdl.DisplayMessage("Backive backup", msg, backive.MsgLevels.Info)
}
}
if dev.IsMounted() {
dev.Unmount()
}
} else {
log.Println("No backup found.")
}

View File

@ -53,7 +53,6 @@ func (eh *EventHandler) RegisterCallback(cb func(map[string]string)) {
func (eh *EventHandler) process() {
client, err := mockAccept(eh)
log.Println("Accepted client")
UiHdl.DisplayMessage("Event debugging", "Catched event...", MsgLevels.Debug)
if err != nil {
log.Println(err)
return
@ -87,7 +86,6 @@ func (eh *EventHandler) process() {
for k, v := range message["data"].(map[string]interface{}) {
env[k] = v.(string)
}
UiHdl.DisplayMessage("Event debugging", "Got udev event msg.", MsgLevels.Debug)
}
for _, v := range eh.callbacks {
if v != nil {

View File

@ -3,8 +3,6 @@ package ui
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net"
"os"
@ -59,10 +57,7 @@ func PollConnection() {
if c == nil {
log.Println("Creating connection")
c, err = net.Dial("unix", config.Settings.UIUnixSocketLocation)
} else {
err = fmt.Errorf("Connection already established")
log.Println(err)
}
} // else already connected
// handle error on connection
if err != nil {
log.Println(err)
@ -75,24 +70,12 @@ func PollConnection() {
// receive msgs
if c != nil {
data := make([]byte, 2048)
for {
buf := make([]byte, 512)
nr, err := c.Read(buf)
nr, err := c.Read(data)
log.Printf("Read %d bytes...", nr)
if err == io.ErrClosedPipe {
c = nil
err = nil
break
}
if err != nil && err != io.EOF {
if err != nil {
log.Println(err)
break
}
data = append(data, buf[0:nr]...)
if err == io.EOF {
break
}
}
sdata := string(bytes.Trim(data, "\x00"))
var message map[string]string
log.Printf("Reading JSON: %s", sdata)
@ -124,7 +107,7 @@ func ShallShow(data map[string]string) bool {
if err != nil {
return false
}
if level <= 10 {
if level <= 30 {
return true
}
if int(level) <= uisettings.globalLevel && messageLevel > 0 {

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net"
"os"
"path"
)
@ -49,6 +50,7 @@ func (uh *UIHandler) Init(socketPath string) error {
dir, _ := path.Split(socketPath)
CreateDirectoryIfNotExists(dir)
uh.ls, err = net.Listen("unix", socketPath)
os.Chmod(socketPath, 0777)
if err != nil {
log.Printf("Error: %s", err)
return err
@ -79,8 +81,8 @@ func (uh *UIHandler) Listen() {
// DisplayMessage is the method to use inside the service to display messages, with intended level
func (uh *UIHandler) DisplayMessage(header string, message string, level MsgLevel) error {
if uh.client != nil {
var data map[string]interface{}
data["level"] = int(level)
var data = make(map[string]string)
data["level"] = fmt.Sprint(level)
data["header"] = header
data["message"] = message
b, err := json.Marshal(data)