From cb59d970f6ed06d2c71243ec040e7c68c15e159d Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" Date: Thu, 25 Jan 2024 20:39:25 -0800 Subject: [PATCH] handle single-slash URIs #PostelsLaw --- .../quilt/nio/QuiltFileSystemProvider.groovy | 21 +++++++++++++------ .../quilt/nio/QuiltPathFactory.groovy | 10 +++++++-- .../nio/QuiltFileSystemProviderTest.groovy | 2 ++ .../quilt/nio/QuiltPathFactoryTest.groovy | 5 +++-- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltFileSystemProvider.groovy b/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltFileSystemProvider.groovy index 55298d48..a2ea1d8f 100644 --- a/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltFileSystemProvider.groovy +++ b/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltFileSystemProvider.groovy @@ -68,13 +68,21 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr private Map attributesCache = [:] static QuiltPath asQuiltPath(Path path) { - if (path !in QuiltPath) { - String pathClassName = path?.class?.name ?: '-' - throw new IllegalArgumentException( - "Not a valid Quilt blob storage path object: `${path}` [${pathClassName}]" - ) + println("asQuiltPath.path: ${path}") + if (path in QuiltPath) { + return (QuiltPath)path + } + String pathString = path?.toString() ?: '-' + println("asQuiltPath.pathString: ${pathString}") + if (pathString.startsWith(QuiltParser.SCHEME + ':/')) { + QuiltPath qPath = QuiltPathFactory.parse(pathString) + println("asQuiltPath.qPath: ${qPath}") + return qPath } - return (QuiltPath)path + String pathClassName = path?.class?.name ?: '-' + throw new IllegalArgumentException( + "Not a valid Quilt blob storage path object: `${path}` [${pathClassName}]" + ) } static QuiltFileSystem getQuiltFilesystem(Path path) { @@ -108,6 +116,7 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr void download(Path remoteFile, Path localDestination, CopyOption... options) throws IOException { log.debug "QuiltFileSystemProvider.download: ${remoteFile} -> ${localDestination}" QuiltPath qPath = asQuiltPath(remoteFile) + println("QuiltFileSystemProvider.download: ${qPath}") Path proxy = qPath.localPath() QuiltPackage pkg = qPath.pkg() String pathName = pkg.parsed.getPath() diff --git a/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltPathFactory.groovy b/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltPathFactory.groovy index 52a4716d..c4a11aa3 100644 --- a/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltPathFactory.groovy +++ b/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltPathFactory.groovy @@ -40,10 +40,16 @@ class QuiltPathFactory extends FileSystemPathFactory { @Override protected Path parseUri(String uriString) { - if (!uriString.startsWith(QuiltParser.PREFIX)) { + println('parseUri.uriString: ' + uriString) + if (!uriString.startsWith(QuiltParser.SCHEME)) { return null } - final uri = new URI(uriString) + String[] split = uriString.split('/') + println('parseUri.split: ' + split) + String newString = (split[1] == '') ? uriString : uriString.replaceFirst(/\/+/, '//') + println('parseUri.newString: ' + newString) + final uri = new URI(newString) + println('parseUri.uri: ' + uri) return FileHelper.getOrCreateFileSystemFor(uri).provider().getPath(uri) } diff --git a/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltFileSystemProviderTest.groovy b/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltFileSystemProviderTest.groovy index 2c5d0519..5ed36070 100644 --- a/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltFileSystemProviderTest.groovy +++ b/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltFileSystemProviderTest.groovy @@ -4,6 +4,8 @@ package nextflow.quilt.nio import nextflow.quilt.QuiltSpecification import groovy.transform.CompileDynamic import java.nio.file.Path +import java.nio.file.Paths +import java.nio.file.Files /** * diff --git a/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltPathFactoryTest.groovy b/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltPathFactoryTest.groovy index 5343a39a..d0811b97 100644 --- a/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltPathFactoryTest.groovy +++ b/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltPathFactoryTest.groovy @@ -53,8 +53,9 @@ class QuiltPathFactoryTest extends QuiltSpecification { QuiltPathFactory.parse(PATH).toString() == STR where: - _ | PATH | STR - _ | 'quilt+s3://reg#package=user/pkg' | 'reg#package=user%2fpkg' + _ | PATH | STR + _ | 'quilt+s3://reg#package=user/pkg' | 'reg#package=user%2fpkg' + _ | 'quilt+s3:/reg#package=user/pkg&path=test.md' | 'reg#package=user%2fpkg&path=test.md' } void 'should create Channel from URL'() {