1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 13:30:26 +00:00
mycorrhiza/shroom/unattach.go
Mikhail Chekan 85c936d94a Housekeeping with linter
'I do as the golint guides'
2021-10-02 01:14:26 +08:00

41 lines
981 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package shroom
import (
"fmt"
"github.com/bouncepaw/mycorrhiza/history"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/user"
)
// UnattachHypha unattaches hypha and makes a history record about that.
func UnattachHypha(u *user.User, h *hyphae.Hypha) (hop *history.Op, errtitle string) {
hop = history.Operation(history.TypeUnattachHypha)
if errtitle, err := CanUnattach(u, h); errtitle != "" {
hop.WithErrAbort(err)
return hop, errtitle
}
hop.
WithFilesRemoved(h.BinaryPath).
WithMsg(fmt.Sprintf("Unattach %s", h.Name)).
WithUser(u).
Apply()
if len(hop.Errs) > 0 {
rejectUnattachLog(h, u, "fail")
// FIXME: something may be wrong here
return hop.WithErrAbort(fmt.Errorf("Could not unattach this hypha due to internal server errors: <code>%v</code>", hop.Errs)), "Error"
}
if h.BinaryPath != "" {
h.BinaryPath = ""
}
// If nothing is left of the hypha
if h.TextPath == "" {
h.Delete()
}
return hop, ""
}