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

Allow http file to be closed early #5405

Merged
merged 1 commit into from
Oct 17, 2024
Merged
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 @@ -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