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

Resolve Fusion symlinks when publishing files #4348

Merged
merged 20 commits into from
Nov 13, 2023
Merged
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 @@ -29,6 +29,7 @@ import java.util.concurrent.ExecutorService
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.Memoized
import groovy.transform.PackageScope
import groovy.transform.ToString
import groovy.util.logging.Slf4j
Expand All @@ -38,6 +39,7 @@ import nextflow.Session
import nextflow.extension.FilesEx
import nextflow.file.FileHelper
import nextflow.file.TagAwareFile
import nextflow.fusion.FusionHelper
import nextflow.util.PathTrie
/**
* Implements the {@code publishDir} directory. It create links or copies the output
Expand Down Expand Up @@ -119,6 +121,8 @@ class PublishDir {

private String taskName

private Map<String,Path> taskInputs

@Lazy
private ExecutorService threadPool = { def sess = Global.session as Session; sess.publishDirExecutorService() }()

Expand Down Expand Up @@ -282,6 +286,7 @@ class PublishDir {
this.sourceFileSystem = sourceDir.fileSystem
this.stageInMode = task.config.stageInMode
this.taskName = task.name
this.taskInputs = task.getInputFilesMap()

apply0(files)
}
Expand Down Expand Up @@ -364,6 +369,11 @@ class PublishDir {
@CompileStatic
protected void processFile( Path source, Path destination ) {

// resolve Fusion symlink if applicable
if( FusionHelper.isFusionEnabled(Global.session as Session) )
if( source.name in taskInputs )
bentsherman marked this conversation as resolved.
Show resolved Hide resolved
pditommaso marked this conversation as resolved.
Show resolved Hide resolved
source = resolveFusionLink(taskInputs[source.name])

// create target dirs if required
makeDirs(destination.parent)

Expand All @@ -387,6 +397,31 @@ class PublishDir {
notifyFilePublish(destination, source)
}

/**
* Resolve a Fusion symlink by following the .fusion.symlinks
* file in the task directory until the original file is reached.
*
* @param file
*/
@CompileStatic
protected Path resolveFusionLink(Path file) {
while( file.name in getFusionLinks(file.parent) )
file = file.text.replace('/fusion/s3/', 's3://') as Path
return file
bentsherman marked this conversation as resolved.
Show resolved Hide resolved
}

@CompileStatic
@Memoized
protected List<String> getFusionLinks(Path workDir) {
try {
final file = workDir.resolve('.fusion.symlinks')
return file.text.tokenize('\n')
}
catch( NoSuchFileException ) {
return []
}
}

private String real0(Path p) {
try {
// resolve symlink if it's file in the default (posix) file system
Expand Down