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 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 @@ -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.time.temporal.ChronoUnit
import java.util.concurrent.ExecutorService

Expand Down Expand Up @@ -337,10 +340,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 @@ -363,9 +366,23 @@ 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 {
retryableProcessFile(source, 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())
retryableProcessFile(sourceFile, targetFile)
FileVisitResult.CONTINUE
}
})
}

// otherwise publish file directly
else {
retryableProcessFile(source, target)
}
}
catch( Throwable e ) {
final msg = "Failed to publish file: ${source.toUriString()}; to: ${target.toUriString()} [${mode.toString().toLowerCase()}] -- See log file for details"
Expand Down Expand Up @@ -395,7 +412,7 @@ class PublishDir {
.build()
Failsafe
.with( retryPolicy )
.get({it-> processFile(source, target)})
.get { it-> processFile(source, target) }
}

protected void processFile( Path source, Path destination ) {
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