mirror of
https://github.com/Luzifer/cloudbox.git
synced 2024-11-08 14:10:09 +00:00
Make change human readable in logs
This commit is contained in:
parent
d65571a245
commit
f4227214de
3 changed files with 73 additions and 45 deletions
69
sync/change.go
Normal file
69
sync/change.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
package sync
|
||||
|
||||
import "strings"
|
||||
|
||||
type Change uint8
|
||||
|
||||
const (
|
||||
ChangeLocalAdd Change = 1 << iota
|
||||
ChangeLocalDelete
|
||||
ChangeLocalUpdate
|
||||
ChangeRemoteAdd
|
||||
ChangeRemoteDelete
|
||||
ChangeRemoteUpdate
|
||||
)
|
||||
|
||||
var changeNameMap = map[Change]string{
|
||||
ChangeLocalAdd: "local-add",
|
||||
ChangeLocalDelete: "local-delete",
|
||||
ChangeLocalUpdate: "local-update",
|
||||
ChangeRemoteAdd: "remote-add",
|
||||
ChangeRemoteDelete: "remote-delete",
|
||||
ChangeRemoteUpdate: "remote-update",
|
||||
}
|
||||
|
||||
func (c Change) Changed() bool {
|
||||
return c != 0
|
||||
}
|
||||
|
||||
func (c *Change) Register(add Change) {
|
||||
*c = *c | add
|
||||
}
|
||||
|
||||
func (c Change) HasAll(test ...Change) bool {
|
||||
for _, t := range test {
|
||||
if c&t == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (c Change) HasOne(test ...Change) bool {
|
||||
for _, t := range test {
|
||||
if c&t != 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c Change) Is(test Change) bool {
|
||||
return c == test
|
||||
}
|
||||
|
||||
func (c Change) String() string {
|
||||
if !c.Changed() {
|
||||
return "none"
|
||||
}
|
||||
|
||||
names := []string{}
|
||||
for k, v := range changeNameMap {
|
||||
if c.HasOne(k) {
|
||||
names = append(names, v)
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Join(names, ", ")
|
||||
}
|
|
@ -19,7 +19,7 @@ func (s *Sync) decideAction(syncState *state, fileName string) error {
|
|||
logger.Warn("File has local and remote updates, sync not possible")
|
||||
|
||||
case change.HasAll(ChangeLocalAdd, ChangeRemoteAdd):
|
||||
// Special case: Both are added, check thet are the same file or break
|
||||
// Special case: Both are added, check they are the same file or leave this to manual resolve
|
||||
logger.Debug("File added locally as well as remotely")
|
||||
// TODO: Handle special case
|
||||
|
||||
|
@ -62,8 +62,9 @@ func (s *Sync) decideAction(syncState *state, fileName string) error {
|
|||
}
|
||||
|
||||
default:
|
||||
// Unhandled case
|
||||
logger.WithField("change", change).Warn("Unhandled change case")
|
||||
// Unhandled case (i.e. human screwed around in sync process)
|
||||
// Stuff like: LocalUpdate + RemoteDelete, ...
|
||||
logger.WithField("change", change.String()).Warn("Unhandled change case, sync not possible")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -8,48 +8,6 @@ import (
|
|||
"github.com/Luzifer/cloudbox/providers"
|
||||
)
|
||||
|
||||
type Change uint8
|
||||
|
||||
const (
|
||||
ChangeLocalAdd Change = 1 << iota
|
||||
ChangeLocalDelete
|
||||
ChangeLocalUpdate
|
||||
ChangeRemoteAdd
|
||||
ChangeRemoteDelete
|
||||
ChangeRemoteUpdate
|
||||
)
|
||||
|
||||
func (c Change) Changed() bool {
|
||||
return c != 0
|
||||
}
|
||||
|
||||
func (c *Change) Register(add Change) {
|
||||
*c = *c | add
|
||||
}
|
||||
|
||||
func (c Change) HasAll(test ...Change) bool {
|
||||
for _, t := range test {
|
||||
if c&t == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (c Change) HasOne(test ...Change) bool {
|
||||
for _, t := range test {
|
||||
if c&t != 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c Change) Is(test Change) bool {
|
||||
return c == test
|
||||
}
|
||||
|
||||
const (
|
||||
sideLocal string = "local"
|
||||
sideRemote string = "remote"
|
||||
|
|
Loading…
Reference in a new issue