summaryrefslogtreecommitdiff
path: root/internal/types
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-08-15 11:09:03 +0300
committerPaul Buetow <paul@buetow.org>2024-08-15 11:09:03 +0300
commitb7b3a4b5baa6bb8055a1fd0695b261e971cffd4d (patch)
tree6138cacb62544996644f1d58c1a38afe77bbbf4c /internal/types
parent98599f8c592dcf1eb60c598328116b37d88fd1e4 (diff)
Update marks checksum only dirty when there was really something changed in the entry
Diffstat (limited to 'internal/types')
-rw-r--r--internal/types/entry.go24
1 files changed, 19 insertions, 5 deletions
diff --git a/internal/types/entry.go b/internal/types/entry.go
index 117cb83..fe15270 100644
--- a/internal/types/entry.go
+++ b/internal/types/entry.go
@@ -123,15 +123,17 @@ func (e Entry) Update(other Entry) (Entry, error) {
if e.ID != other.ID {
return e, fmt.Errorf("can update entry only with other entry with same ID: this(%s) other(%s)", e, other)
}
- e.checksumDirty = true
- e.Changed = true
+
+ var changed bool
if e.Body != other.Body {
e.Body = other.Body
+ changed = true
}
if e.Epoch != other.Epoch {
e.Epoch = other.Epoch
+ changed = true
}
sharedMap := make(map[string]Shared)
@@ -144,10 +146,11 @@ func (e Entry) Update(other Entry) (Entry, error) {
switch {
case !ok:
sharedMap[otherShared.Name] = shared
- continue
- case otherShared.Is:
+ changed = true
+ case otherShared.Is && !shared.Is:
shared.Is = true
sharedMap[otherShared.Name] = shared
+ changed = true
}
}
@@ -156,6 +159,11 @@ func (e Entry) Update(other Entry) (Entry, error) {
e.Shared = append(e.Shared, shared)
}
+ if changed {
+ e.checksumDirty = true
+ e.Changed = true
+ }
+
return e, nil
}
@@ -164,6 +172,12 @@ func (e Entry) JSONMarshal() ([]byte, error) {
}
func (e Entry) String() string {
+ return e.checksumBase()
+}
+
+// Used to calculate the checksum, better don't change the output, otherwise
+// repository database will get confused with entry checksum mismatches.
+func (e Entry) checksumBase() string {
var sb strings.Builder
sb.WriteString("ID:")
@@ -192,7 +206,7 @@ func (e *Entry) Checksum() string {
return e.checksum
}
- e.checksum = fmt.Sprintf("%x", sha256.Sum256([]byte(e.String())))
+ e.checksum = fmt.Sprintf("%x", sha256.Sum256([]byte(e.checksumBase())))
e.checksumDirty = false
return e.checksum
}