fix(scanner): crash if library root is filesystem root

closes #564
This commit is contained in:
Gauthier Roebroeck 2021-07-02 11:45:54 +08:00
parent 76caa4de39
commit d7391669f6
2 changed files with 24 additions and 2 deletions

View File

@ -72,14 +72,14 @@ class FileSystemScanner(
object : FileVisitor<Path> {
override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes): FileVisitResult {
logger.trace { "preVisit: $dir" }
if (dir.fileName.toString().startsWith(".") ||
if (dir.fileName?.toString()?.startsWith(".") == true ||
komgaProperties.librariesScanDirectoryExclusions.any { exclude ->
dir.toString().contains(exclude, true)
}
) return FileVisitResult.SKIP_SUBTREE
pathToSeries[dir] = Series(
name = dir.fileName.toString(),
name = dir.fileName?.toString() ?: dir.toString(),
url = dir.toUri().toURL(),
fileLastModified = attrs.getUpdatedTime()
)

View File

@ -70,6 +70,28 @@ class FileSystemScannerTest {
}
}
@Test
fun `given root directory as filesystem root when scanning then return 1 series containing those files as books`() {
Jimfs.newFileSystem(Configuration.unix()).use { fs ->
// given
val root = fs.getPath("/")
val files = listOf("file1.cbz", "file2.cbz")
files.forEach { Files.createFile(root.resolve(it)) }
// when
val scan = scanner.scanRootFolder(root).series
val series = scan.keys.first()
val books = scan.getValue(series)
// then
assertThat(scan).hasSize(1)
assertThat(series.name).isEqualTo("/")
assertThat(books).hasSize(2)
assertThat(books.map { it.name }).containsExactlyInAnyOrderElementsOf(files.map { FilenameUtils.removeExtension(it) })
}
}
@Test
fun `given directory with unsupported files when scanning then return a series excluding those files as books`() {
Jimfs.newFileSystem(Configuration.unix()).use { fs ->