From 9f9ff58a0d06e84745a72930a1bcdfe3f9a04c17 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sat, 29 May 2021 22:26:53 +0200 Subject: [PATCH] postCreationMutex --- postsDb.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/postsDb.go b/postsDb.go index 8ff9ab0..a6553d9 100644 --- a/postsDb.go +++ b/postsDb.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "strings" + "sync" "text/template" "time" @@ -120,11 +121,16 @@ type postCreationOptions struct { oldStatus postStatus } +var postCreationMutex sync.Mutex + func (p *post) createOrReplace(o *postCreationOptions) error { err := p.checkPost() if err != nil { return err } + // Prevent bad things + postCreationMutex.Lock() + defer postCreationMutex.Unlock() // Check if path is already in use if o.new || (p.Path != o.oldPath) { // Post is new or post path was changed