1
0
Fork 0
mirror of https://github.com/Luzifer/cloudbox.git synced 2024-11-08 22:20:09 +00:00
cloudbox/sync/change.go
Knut Ahlers c658048ad1
Fix linter advices
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-06-16 23:10:54 +02:00

69 lines
1.1 KiB
Go

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 |= 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, ", ")
}