Skip to content
Snippets Groups Projects
Commit d4954821 authored by Ophestra's avatar Ophestra
Browse files

implement proper parent unsetting, reject setting parent when already grouped

parent 40f5a0d9
No related branches found
Tags v1.4.2
No related merge requests found
......@@ -315,22 +315,40 @@ func (s *Store) ImageUpdate(hash, source, parent, commentary, commentaryTranslat
info.Source = source
msg += "source"
}
if parent != "\000" && parent != "" && parent != info.Snowflake {
if parent != "\000" && parent != info.Snowflake {
if p := s.ImageSnowflake(parent); p.Snowflake == parent {
s.getLock(p.Hash).Lock()
defer s.getLock(p.Hash).Unlock()
// If no parent, then get the current parent and unset
if parent == "" {
p = s.ImageSnowflake(info.Parent)
// If no current parent, nothing to do
if p.Snowflake == "" {
goto end
}
} else {
// If setting parent but parent has child, reject
if p.Child != "" {
goto end
}
}
info.Parent = parent
// Update the parent to reflect the child
p.Child = info.Snowflake
if parent == "" {
p.Child = ""
}
s.getLock(p.Hash).Lock()
s.imageMetadataWrite(p)
s.getLock(p.Hash).Unlock()
if msg != "" {
msg += ", "
}
msg += "parent " + parent
}
end:
}
if commentary != "\000" {
info.Commentary = commentary
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment