Skip to content

Commit

Permalink
Fix http files stream (nextflow-io#5405) [e2e stage]
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Sellman <[email protected]>
  • Loading branch information
tom-seqera authored and alberto-miranda committed Nov 19, 2024
1 parent 4abbb17 commit 35978c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
* Helper class to handle copy/move files and directories
*/
public class CopyMoveHelper {
/**
* True if currently performing a copy of a foreign file.
*/
public static final ThreadLocal<Boolean> IN_FOREIGN_COPY = new ThreadLocal<>();

private static Logger log = LoggerFactory.getLogger(CopyMoveHelper.class);

Expand Down Expand Up @@ -81,14 +85,16 @@ private static CopyOption[] convertMoveToCopyOptions(CopyOption... options)
private static void copyFile(Path source, Path target, boolean foreign, CopyOption... options)
throws IOException
{

if( !foreign ) {
source.getFileSystem().provider().copy(source, target, options);
return;
}

IN_FOREIGN_COPY.set(true);
try (InputStream in = Files.newInputStream(source)) {
Files.copy(in, target);
} finally {
IN_FOREIGN_COPY.set(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package nextflow.file.http

import nextflow.file.CopyMoveHelper

import static nextflow.file.http.XFileSystemConfig.*

import java.nio.ByteBuffer
Expand Down Expand Up @@ -352,7 +354,8 @@ abstract class XFileSystemProvider extends FileSystemProvider {

final conn = toConnection(path)
final length = conn.getContentLengthLong()
return length>0
// only apply the FixedInputStream check if staging files
return length>0 && CopyMoveHelper.IN_FOREIGN_COPY.get()
? new FixedInputStream(conn.getInputStream(), length)
: conn.getInputStream()
}
Expand Down

0 comments on commit 35978c9

Please sign in to comment.