@@ -23,11 +23,14 @@ package eu.openanalytics.shinyproxyoperator.impl.docker
2323import com.fasterxml.jackson.module.kotlin.convertValue
2424import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
2525import eu.openanalytics.shinyproxyoperator.model.ShinyProxy
26+ import java.nio.file.Files
2627import java.nio.file.Path
28+ import kotlin.io.path.PathWalkOption
2729import kotlin.io.path.absolute
2830import kotlin.io.path.exists
2931import kotlin.io.path.getLastModifiedTime
3032import kotlin.io.path.isRegularFile
33+ import kotlin.io.path.walk
3134
3235fun ShinyProxy.getCaddyTlsCertFile (): Path ? {
3336 if (getSpec().get(" caddyTlsCertFile" )?.isTextual == true ) {
@@ -70,6 +73,18 @@ fun ShinyProxy.getCaBundleFile(inputDir: Path): Path {
7073 return inputDir.resolve(" ca-bundle.crt" ).absolute()
7174}
7275
76+ private fun ShinyProxy.isTemplateModified (inputDir : Path , lastModified : Long ): Pair <Boolean , Path ?> {
77+ val source = getTemplateSource(inputDir) ? : return Pair (false , null )
78+
79+ source.walk(PathWalkOption .INCLUDE_DIRECTORIES ).forEach { path ->
80+ if (path.getLastModifiedTime().toMillis() > lastModified) {
81+ return Pair (true , path)
82+ }
83+ }
84+
85+ return Pair (false , null )
86+ }
87+
7388fun ShinyProxy.isReferencedFileMoreRecent (inputDir : Path , lastModified : Long ): Pair <Boolean , Path ?> {
7489 val files = listOf (getCaddyTlsCertFile(), getCaddyTlsKeyFile(), getCaBundleFile(inputDir)) + getAdditionalConfigFiles()
7590 for (file in files) {
@@ -80,7 +95,19 @@ fun ShinyProxy.isReferencedFileMoreRecent(inputDir: Path, lastModified: Long): P
8095 return Pair (true , file)
8196 }
8297 }
83- return Pair (false , null )
98+ return isTemplateModified(inputDir, lastModified)
99+ }
100+
101+ fun ShinyProxy.getTemplateSource (inputDir : Path ): Path ? {
102+ val source = inputDir.resolve(" templates" ).resolve(name)
103+ if (Files .exists(source) && Files .isDirectory(source)) {
104+ return source
105+ }
106+ val source2 = inputDir.resolve(" templates" ).resolve(realmId)
107+ if (Files .exists(source2) && Files .isDirectory(source2)) {
108+ return source2
109+ }
110+ return null
84111}
85112
86113data class CaddyRedirect (val from : String , val to : String , val statusCode : Int = 302 )
0 commit comments