diff --git a/src/main/kotlin/pl/edu/uj/ii/ksi/mordor/services/MetadataGarbageCollector.kt b/src/main/kotlin/pl/edu/uj/ii/ksi/mordor/services/MetadataGarbageCollector.kt index dc64068..8483222 100644 --- a/src/main/kotlin/pl/edu/uj/ii/ksi/mordor/services/MetadataGarbageCollector.kt +++ b/src/main/kotlin/pl/edu/uj/ii/ksi/mordor/services/MetadataGarbageCollector.kt @@ -3,6 +3,7 @@ package pl.edu.uj.ii.ksi.mordor.services import org.slf4j.LoggerFactory import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Service +import pl.edu.uj.ii.ksi.mordor.exceptions.BadRequestException import pl.edu.uj.ii.ksi.mordor.persistence.entities.FileEntry import pl.edu.uj.ii.ksi.mordor.persistence.entities.FileMetadata import pl.edu.uj.ii.ksi.mordor.persistence.repositories.FileEntryRepository @@ -19,7 +20,7 @@ class MetadataGarbageCollector( private val logger = LoggerFactory.getLogger(ExternalUserService::class.java) } - @Scheduled(fixedDelay = 60 * 60 * 1000) + @Scheduled(fixedDelay = 60 * 1000 * 1000) fun collect() { logger.info("Metadata garbage collection started") // TODO count done/total @@ -33,8 +34,13 @@ class MetadataGarbageCollector( private fun checkFile(entry: FileEntry) { logger.debug("Checking entry ${entry.path}") - if (!repositoryService.fileExists(entry.path)) { - logger.debug("File doesn't exists, deleting entry ${entry.path}") + try { + if (!repositoryService.fileExists(entry.path)) { + logger.debug("File doesn't exists, deleting entry ${entry.path}") + entryRepository.delete(entry) + } + } catch (e: BadRequestException) { + logger.debug("File outside of repository root, deleting entry ${entry.path}") entryRepository.delete(entry) } }