diff --git a/src/main/kotlin/com/github/thetric/iliasdownloader/cli/sync/ItemDownloadingItemVisitor.kt b/src/main/kotlin/com/github/thetric/iliasdownloader/cli/sync/ItemDownloadingItemVisitor.kt index b9f2fb8..ab3950d 100644 --- a/src/main/kotlin/com/github/thetric/iliasdownloader/cli/sync/ItemDownloadingItemVisitor.kt +++ b/src/main/kotlin/com/github/thetric/iliasdownloader/cli/sync/ItemDownloadingItemVisitor.kt @@ -5,6 +5,7 @@ import com.github.thetric.iliasdownloader.service.IliasService import com.github.thetric.iliasdownloader.service.model.CourseFile import com.github.thetric.iliasdownloader.service.model.CourseFolder import com.github.thetric.iliasdownloader.service.model.IliasItem +import com.github.thetric.iliasdownloader.service.webparser.impl.IliasHttpException import mu.KotlinLogging import java.io.File import java.nio.file.Files @@ -79,10 +80,31 @@ class ItemDownloadingItemVisitor( } private fun syncAndSaveFile(path: Path, file: CourseFile) { - iliasService.getContentAsStream(file).use { - Files.copy(it, path, StandardCopyOption.REPLACE_EXISTING) + try { + iliasService.getContentAsStream(file).use { + Files.copy(it, path, StandardCopyOption.REPLACE_EXISTING) + } + Files.setLastModifiedTime(path, toFileTime(file.modified)) + } catch (e: IliasHttpException) { + // skip downloads with an unexpected HTTP status code (not 2xx). + // in some rare cases (see issue #11) the webdav interface can + // throw a 403 forbidden when accessing a file, although the user + // can download the file via the 'normal' web interface. + // other files in the course don't seem affected and can be + // downloaded. + log.error { + getLocalizedMessage( + "sync.download.failed", + e.url, + e.statusCode, + file.name + ) + } + log.trace( + e, + { "Download of ${e.url} failed with HTTP status code ${e.statusCode}" } + ) } - Files.setLastModifiedTime(path, toFileTime(file.modified)) } } diff --git a/src/main/resources/ilias-cli.properties b/src/main/resources/ilias-cli.properties index 19d460f..fcf165a 100644 --- a/src/main/resources/ilias-cli.properties +++ b/src/main/resources/ilias-cli.properties @@ -17,5 +17,8 @@ sync.courses.prompt=Enter the numbers of the courses to sync (separate by a spac sync.courses.prompt.errors.out-of-range=Invalid course selection! The selection must contain indices between 1 and {0} sync.download.file.started=Downloading file "{0}" ({1,number,integer} bytes)... sync.download.file.finished=Saved to {0} +sync.download.started= +sync.download.finished= sync.download.file.found=Found file "{0}" sync.course.found=Found course "{0}" +sync.download.failed=Failed to download {0} (HTTP status code {1,number,integer}). Skipping "{2}" in this sync. diff --git a/src/main/resources/ilias-cli_de.properties b/src/main/resources/ilias-cli_de.properties index c2884be..321d358 100644 --- a/src/main/resources/ilias-cli_de.properties +++ b/src/main/resources/ilias-cli_de.properties @@ -20,3 +20,4 @@ sync.download.started=Lade Datei "{0}" ({1,number,integer} Bytes) herunter... sync.download.finished=Gespeichert unter {0} sync.download.file.found=Datei "{0}" gefunden sync.course.found=Kurs "{0}" gefunden +sync.download.failed=Download von {0} fehlgeschlagen (HTTP status code {1,number,integer}). "{2}" wird bei diesem Sync übersprungen.