mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 05:20:26 +00:00
Fix the bug with git locking
This commit is contained in:
parent
f33eefe502
commit
9052f31e1f
@ -59,12 +59,16 @@ func (hop *HistoryOp) gitop(args ...string) *HistoryOp {
|
||||
return hop
|
||||
}
|
||||
|
||||
// WithError appends the `err` to the list of errors.
|
||||
func (hop *HistoryOp) WithError(err error) *HistoryOp {
|
||||
// WithErr appends the `err` to the list of errors.
|
||||
func (hop *HistoryOp) WithErr(err error) *HistoryOp {
|
||||
hop.Errs = append(hop.Errs, err)
|
||||
return hop
|
||||
}
|
||||
|
||||
func (hop *HistoryOp) WithErrAbort(err error) *HistoryOp {
|
||||
return hop.WithErr(err).Abort()
|
||||
}
|
||||
|
||||
// WithFilesRemoved git-rm-s all passed `paths`. Paths can be rooted or not. Paths that are empty strings are ignored.
|
||||
func (hop *HistoryOp) WithFilesRemoved(paths ...string) *HistoryOp {
|
||||
args := []string{"rm", "--quiet", "--"}
|
||||
|
@ -13,7 +13,7 @@ func DeleteHypha(u *user.User, h *hyphae.Hypha) (hop *history.HistoryOp, errtitl
|
||||
hop = history.Operation(history.TypeDeleteHypha)
|
||||
|
||||
if err, errtitle := CanDelete(u, h); errtitle != "" {
|
||||
hop.WithError(err).Abort()
|
||||
hop.WithErrAbort(err)
|
||||
return hop, errtitle
|
||||
}
|
||||
|
||||
|
@ -37,11 +37,11 @@ func RenameHypha(h *hyphae.Hypha, newHypha *hyphae.Hypha, recursive bool, u *use
|
||||
hop = history.Operation(history.TypeRenameHypha)
|
||||
|
||||
if err, errtitle := CanRename(u, h); errtitle != "" {
|
||||
hop.WithError(err)
|
||||
hop.WithErrAbort(err)
|
||||
return hop, errtitle
|
||||
}
|
||||
if err, errtitle := canRenameThisToThat(h, newHypha, u); errtitle != "" {
|
||||
hop.WithError(err)
|
||||
hop.WithErrAbort(err)
|
||||
return hop, errtitle
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ func UnattachHypha(u *user.User, h *hyphae.Hypha) (hop *history.HistoryOp, errti
|
||||
hop = history.Operation(history.TypeUnattachHypha)
|
||||
|
||||
if err, errtitle := CanUnattach(u, h); errtitle != "" {
|
||||
hop.WithError(err).Abort()
|
||||
hop.WithErrAbort(err)
|
||||
return hop, errtitle
|
||||
}
|
||||
|
||||
@ -26,7 +26,8 @@ func UnattachHypha(u *user.User, h *hyphae.Hypha) (hop *history.HistoryOp, errti
|
||||
|
||||
if len(hop.Errs) > 0 {
|
||||
rejectUnattachLog(h, u, "fail")
|
||||
return hop.WithError(errors.New(fmt.Sprintf("Could not unattach this hypha due to internal server errors: <code>%v</code>", hop.Errs))), "Error"
|
||||
// FIXME: something may be wrong here
|
||||
return hop.WithErrAbort(errors.New(fmt.Sprintf("Could not unattach this hypha due to internal server errors: <code>%v</code>", hop.Errs))), "Error"
|
||||
}
|
||||
|
||||
if h.BinaryPath != "" {
|
||||
|
@ -25,10 +25,10 @@ func UploadText(h *hyphae.Hypha, data []byte, u *user.User) (hop *history.Histor
|
||||
}
|
||||
|
||||
if err, errtitle := CanEdit(u, h); err != nil {
|
||||
return hop.WithError(err), errtitle
|
||||
return hop.WithErrAbort(err), errtitle
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return hop.WithError(errors.New("No data passed")), "Empty"
|
||||
return hop.WithErrAbort(errors.New("No data passed")), "Empty"
|
||||
}
|
||||
|
||||
return uploadHelp(h, hop, ".myco", data, u)
|
||||
@ -41,13 +41,13 @@ func UploadBinary(h *hyphae.Hypha, mime string, file multipart.File, u *user.Use
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return hop.WithError(err), err.Error()
|
||||
return hop.WithErrAbort(err), err.Error()
|
||||
}
|
||||
if err, errtitle := CanAttach(u, h); err != nil {
|
||||
return hop.WithError(err), errtitle
|
||||
return hop.WithErrAbort(err), errtitle
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return hop.WithError(errors.New("No data passed")), "Empty"
|
||||
return hop.WithErrAbort(errors.New("No data passed")), "Empty"
|
||||
}
|
||||
|
||||
return uploadHelp(h, hop, mimetype.ToExtension(mime), data, u)
|
||||
@ -64,16 +64,16 @@ func uploadHelp(h *hyphae.Hypha, hop *history.HistoryOp, ext string, data []byte
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(fullPath), 0777); err != nil {
|
||||
return hop.WithError(err), err.Error()
|
||||
return hop.WithErrAbort(err), err.Error()
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(fullPath, data, 0644); err != nil {
|
||||
return hop.WithError(err), err.Error()
|
||||
return hop.WithErrAbort(err), err.Error()
|
||||
}
|
||||
|
||||
if h.Exists && *originalFullPath != fullPath && *originalFullPath != "" {
|
||||
if err := history.Rename(*originalFullPath, fullPath); err != nil {
|
||||
return hop.WithError(err), err.Error()
|
||||
return hop.WithErrAbort(err), err.Error()
|
||||
}
|
||||
log.Println("Move", *originalFullPath, "to", fullPath)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user