Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Walk file tree on directory publish #3933

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -19,11 +19,14 @@ package nextflow.processor
import java.nio.file.FileAlreadyExistsException
import java.nio.file.FileSystem
import java.nio.file.FileSystems
import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.LinkOption
import java.nio.file.NoSuchFileException
import java.nio.file.Path
import java.nio.file.PathMatcher
import java.nio.file.SimpleFileVisitor
import java.nio.file.attribute.BasicFileAttributes
import java.util.concurrent.ExecutorService
import java.util.regex.Pattern

Expand Down Expand Up @@ -331,10 +334,10 @@ class PublishDir {
}

if( inProcess ) {
safeProcessFile(source, destination)
safeProcessPath(source, destination)
}
else {
threadPool.submit({ safeProcessFile(source, destination) } as Runnable)
threadPool.submit({ safeProcessPath(source, destination) } as Runnable)
}

}
Expand All @@ -357,18 +360,35 @@ class PublishDir {
throw new IllegalArgumentException("Not a valid publish target path: `$target` [${target?.class?.name}]")
}

protected void safeProcessFile(Path source, Path target) {
protected void safeProcessPath(Path source, Path target) {
try {
processFile(source, target)
processPath(source, target)
}
catch( Throwable e ) {
log.warn "Failed to publish file: ${source.toUriString()}; to: ${target.toUriString()} [${mode.toString().toLowerCase()}] -- See log file for details", e
if( NF.strictMode || failOnError){
if( NF.strictMode || failOnError ) {
session?.abort(e)
}
}
}

protected void processPath(Path source, Path target) {

// publish each file in the directory tree
if( Files.isDirectory(source) )
Files.walkFileTree(source, new SimpleFileVisitor<Path>() {
FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attrs) {
final targetFile = target.resolve(source.relativize(sourceFile).toString())
processFile(sourceFile, targetFile)
FileVisitResult.CONTINUE
}
})

// otherwise publish file directly
else
processFile(source, target)
}

protected void processFile( Path source, Path destination ) {

// resolve Fusion symlink if applicable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PublishDirS3Test extends Specification {
when:
spy.apply1(source, true)
then:
1 * spy.safeProcessFile(source, _) >> { sourceFile, s3File ->
1 * spy.safeProcessPath(source, _) >> { sourceFile, s3File ->
assert s3File instanceof S3Path
assert (s3File as S3Path).getTagsList().find{ it.getKey()=='FOO'}.value == 'this'
assert (s3File as S3Path).getTagsList().find{ it.getKey()=='BAR'}.value == 'that'
Expand Down
Loading