Skip to content

Commit

Permalink
Delete entry in MetadataGarbageCollector if path is outside of reposi…
Browse files Browse the repository at this point in the history
…tory root (#73)
  • Loading branch information
DominikWolek authored May 13, 2020
1 parent dae6759 commit fd34656
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
}
Expand Down

0 comments on commit fd34656

Please sign in to comment.