mirror of https://github.com/jlelse/GoBlog
postCreationMutex
This commit is contained in:
parent
29dba59574
commit
9f9ff58a0d
|
@ -6,6 +6,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -120,11 +121,16 @@ type postCreationOptions struct {
|
||||||
oldStatus postStatus
|
oldStatus postStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var postCreationMutex sync.Mutex
|
||||||
|
|
||||||
func (p *post) createOrReplace(o *postCreationOptions) error {
|
func (p *post) createOrReplace(o *postCreationOptions) error {
|
||||||
err := p.checkPost()
|
err := p.checkPost()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Prevent bad things
|
||||||
|
postCreationMutex.Lock()
|
||||||
|
defer postCreationMutex.Unlock()
|
||||||
// Check if path is already in use
|
// Check if path is already in use
|
||||||
if o.new || (p.Path != o.oldPath) {
|
if o.new || (p.Path != o.oldPath) {
|
||||||
// Post is new or post path was changed
|
// Post is new or post path was changed
|
||||||
|
|
Loading…
Reference in New Issue