diff --git a/modules/nextflow/src/main/groovy/nextflow/processor/PublishDir.groovy b/modules/nextflow/src/main/groovy/nextflow/processor/PublishDir.groovy index ab9a29aa27..cfdc4d26e8 100644 --- a/modules/nextflow/src/main/groovy/nextflow/processor/PublishDir.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/processor/PublishDir.groovy @@ -17,6 +17,8 @@ package nextflow.processor +import nextflow.util.CacheHelper + import java.nio.file.FileAlreadyExistsException import java.nio.file.FileSystem import java.nio.file.FileSystems @@ -25,6 +27,7 @@ import java.nio.file.LinkOption import java.nio.file.NoSuchFileException import java.nio.file.Path import java.nio.file.PathMatcher +import java.nio.file.Paths import java.util.concurrent.ExecutorService import groovy.transform.CompileDynamic @@ -127,7 +130,16 @@ class PublishDir { } void setPath( Path obj ) { - this.path = obj.complete() + def path = obj.complete() + + if(path.getFileSystem().provider() == FileSystems.default.provider()) { + log.info("path.toString(): " + path.toUriString() + " is local file system") + this.path = applyS3PrefixForLocalPath(path) + log.info("path.toString(): " + path.toUriString() + " is conveerted to S3 path ${this.path.toUriString()}") + } else { + log.info("path.toString(): " + path.toUriString() + " is other file system") + this.path = path + } } void setMode( String str ) { @@ -513,5 +525,29 @@ class PublishDir { } } + private Path applyS3PrefixForLocalPath(Path path) { + def s3Prefix = getS3PrefixForPublishDir() + if(!s3Prefix) { + log.info("No s3 prefix defined for publishDir - returning original path: " + path.toUriString()) + return path + } + + def rootDir = Paths.get("").toAbsolutePath().normalize().toUriString() + log.info("path.toString(): " + path.toUriString() + " is root dir ${rootDir}") + + def pathStr = path.toUriString() + pathStr = pathStr.startsWith(rootDir) ? pathStr.substring(rootDir.length()) : pathStr + String normalizedLocalPath = pathStr.startsWith('/') ? pathStr.substring(1) : pathStr + if (s3Prefix.endsWith('/')) s3Prefix = s3Prefix.substring(0, s3Prefix.length() - 1) + return FileHelper.asPath("${s3Prefix}/${normalizedLocalPath}") + } + + /** + * Get S3 prefix for redirecting publishDir local paths to S3 + */ + @CompileStatic + private String getS3PrefixForPublishDir() { + return Global.session.config.navigate('lifebit.results', '') as String + } }