Skip to content
Draft
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 @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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
}
}
Loading