Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete entry if path is outside of repository root #73

Merged
merged 1 commit into from
May 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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