Skip to content

Commit 718dcbe

Browse files
authored
Fix http files stream (#5405) [e2e stage]
Signed-off-by: Tom Sellman <tom.sellman@seqera.io>
1 parent 0c9b333 commit 718dcbe

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

modules/nf-commons/src/main/nextflow/file/CopyMoveHelper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
* Helper class to handle copy/move files and directories
4242
*/
4343
public class CopyMoveHelper {
44+
/**
45+
* True if currently performing a copy of a foreign file.
46+
*/
47+
public static final ThreadLocal<Boolean> IN_FOREIGN_COPY = new ThreadLocal<>();
4448

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

@@ -81,14 +85,16 @@ private static CopyOption[] convertMoveToCopyOptions(CopyOption... options)
8185
private static void copyFile(Path source, Path target, boolean foreign, CopyOption... options)
8286
throws IOException
8387
{
84-
8588
if( !foreign ) {
8689
source.getFileSystem().provider().copy(source, target, options);
8790
return;
8891
}
8992

93+
IN_FOREIGN_COPY.set(true);
9094
try (InputStream in = Files.newInputStream(source)) {
9195
Files.copy(in, target);
96+
} finally {
97+
IN_FOREIGN_COPY.set(false);
9298
}
9399
}
94100

modules/nf-httpfs/src/main/nextflow/file/http/XFileSystemProvider.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package nextflow.file.http
1818

19+
import nextflow.file.CopyMoveHelper
20+
1921
import static nextflow.file.http.XFileSystemConfig.*
2022

2123
import java.nio.ByteBuffer
@@ -352,7 +354,8 @@ abstract class XFileSystemProvider extends FileSystemProvider {
352354

353355
final conn = toConnection(path)
354356
final length = conn.getContentLengthLong()
355-
return length>0
357+
// only apply the FixedInputStream check if staging files
358+
return length>0 && CopyMoveHelper.IN_FOREIGN_COPY.get()
356359
? new FixedInputStream(conn.getInputStream(), length)
357360
: conn.getInputStream()
358361
}

0 commit comments

Comments
 (0)