Skip to content

Commit

Permalink
Fix Error while publishing S3 file with blanks
Browse files Browse the repository at this point in the history
This error is reported when publishing a S3 file that container
one or more blanks *and* trace logging is enabled. The issue
is caused by the use of the Path.toUri method that tries to convert
the S3 path to a URI object which does not support the blank chars.

The method toUriString should be used instead which is safer to render
cloud paths to fully qualified path string

Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Mar 9, 2024
1 parent bb5c4f9 commit b74c022
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class FilePorter {
}

private String fmtError(Path filePath, Exception e) {
def message = "Can't stage file ${filePath.toUri().toString()}"
def message = "Can't stage file ${FilesEx.toUriString(filePath)}"
if( e instanceof NoSuchFileException )
message += " -- file does not exist"
else if( e.message )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.util.EnumSet;

import nextflow.extension.FilesEx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -130,7 +131,7 @@ public FileVisitResult visitFile(Path current, BasicFileAttributes attr)
String delta = rel != null ? rel.toString() : null;
Path newFile = delta != null ? target.resolve(delta) : target;
if( log.isTraceEnabled())
log.trace("Copy file: " + current + " -> "+newFile.toUri());
log.trace("Copy file: " + current + " -> "+ FilesEx.toUriString(newFile));
copyFile(current, newFile, foreign, options);
return FileVisitResult.CONTINUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import com.amazonaws.services.s3.transfer.UploadContext;
import nextflow.cloud.aws.nio.util.S3MultipartOptions;
import nextflow.cloud.aws.util.AwsHelper;
import nextflow.extension.FilesEx;
import nextflow.util.Duration;
import nextflow.util.ThreadPoolHelper;
import nextflow.util.ThreadPoolManager;
Expand Down Expand Up @@ -551,7 +552,7 @@ public FileVisitResult visitFile(Path current, BasicFileAttributes attr) {
String delta = rel != null ? rel.toString() : null;
Path newFile = delta != null ? target.resolve(delta) : target;
if( log.isTraceEnabled())
log.trace("Copy file: " + current + " -> "+newFile.toUri());
log.trace("Copy file: " + current + " -> "+ FilesEx.toUriString(newFile));

String sourceKey = ((S3Path) current).getKey();
Download it = transferManager() .download(source.getBucket(), sourceKey, newFile.toFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V>
return (V) new S3FileAttributesView(readAttr0(s3Path));
}
catch (IOException e) {
throw new RuntimeException("Unable read attributes for file: " + s3Path.toUri(), e);
throw new RuntimeException("Unable read attributes for file: " + FilesEx.toUriString(s3Path), e);
}
}
throw new UnsupportedOperationException("Not a valid S3 file system provider file attribute view: " + type.getName());
Expand Down

0 comments on commit b74c022

Please sign in to comment.