Skip to content

Commit

Permalink
Only apply the FixedInputStream check when staging files
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Sellman <[email protected]>
  • Loading branch information
tom-seqera committed Oct 16, 2024
1 parent 0c9b333 commit 6830712
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ private static void copyFile(Path source, Path target, boolean foreign, CopyOpti
return;
}

try (InputStream in = Files.newInputStream(source)) {
// open the remote input stream using FULL_DOWNLOAD option, so it will error if not
// all bytes are read before closing
try (InputStream in = Files.newInputStream(source, ForeignOpenOption.FULL_DOWNLOAD)) {
Files.copy(in, target);
}
}
Expand Down
14 changes: 14 additions & 0 deletions modules/nf-commons/src/main/nextflow/file/ForeignOpenOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package nextflow.file;

import java.nio.file.OpenOption;

/**
* File open options for remote (foreign) file systems
*/
public enum ForeignOpenOption implements OpenOption {
/**
* This option causes an exception to be thrown if the file {@link java.io.InputStream}
* is closed before all the data has been read.
*/
FULL_DOWNLOAD
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package nextflow.file.http

import nextflow.file.ForeignOpenOption

import static nextflow.file.http.XFileSystemConfig.*

import java.nio.ByteBuffer
Expand Down Expand Up @@ -341,18 +343,21 @@ abstract class XFileSystemProvider extends FileSystemProvider {
if (path.class != XPath)
throw new ProviderMismatchException()

boolean requireCompletion = false;
if (options.length > 0) {
for (OpenOption opt: options) {
// All OpenOption values except for APPEND and WRITE are allowed
if (opt == StandardOpenOption.APPEND ||
opt == StandardOpenOption.WRITE)
throw new UnsupportedOperationException("'$opt' not allowed");
if (opt == StandardOpenOption.APPEND || opt == StandardOpenOption.WRITE)
throw new UnsupportedOperationException("'$opt' not allowed")

if (opt == ForeignOpenOption.FULL_DOWNLOAD)
requireCompletion = true
}
}

final conn = toConnection(path)
final length = conn.getContentLengthLong()
return length>0
return length>0 && requireCompletion
? new FixedInputStream(conn.getInputStream(), length)
: conn.getInputStream()
}
Expand Down

0 comments on commit 6830712

Please sign in to comment.