From 4ef99ed2d807cc2d6ec6caa68c20c053034d3716 Mon Sep 17 00:00:00 2001 From: TheDiscordian Date: Fri, 23 Jul 2021 02:09:51 -0400 Subject: [PATCH] Only allow one CleanFilestore routine to run at a time, fixes #36 --- main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.go b/main.go index 7a0d1ed..331c7b3 100644 --- a/main.go +++ b/main.go @@ -269,8 +269,20 @@ type FileStoreEntry struct { Key FileStoreKey } +var fileStoreCleanupLock chan int + +func init() { + fileStoreCleanupLock = make(chan int, 1) +} + // CleanFilestore removes blocks that point to files that don't exist func CleanFilestore() { + select { + case fileStoreCleanupLock <- 1: + defer func() { <-fileStoreCleanupLock }() + default: + return + } if Verbose { log.Println("Removing blocks that point to a file that doesn't exist from filestore...") }