From d0a81b0d587276daf3d4038bf2c1ca1183962fc1 Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Wed, 4 Sep 2024 21:27:06 -0700 Subject: [PATCH] QuiltPackage.osSep --- .../src/main/nextflow/quilt/jep/QuiltPackage.groovy | 11 ++++++++++- .../src/main/nextflow/quilt/nio/QuiltPath.groovy | 11 +---------- .../src/test/nextflow/quilt/nio/QuiltPathTest.groovy | 8 +++++--- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltPackage.groovy b/plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltPackage.groovy index 7b6b5bb9..912f16f5 100644 --- a/plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltPackage.groovy +++ b/plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltPackage.groovy @@ -20,6 +20,7 @@ package nextflow.quilt.jep import groovy.json.JsonOutput import groovy.transform.CompileStatic import groovy.util.logging.Slf4j +import java.nio.file.FileSystems import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths @@ -55,6 +56,14 @@ class QuiltPackage { private final Map meta private boolean installed + static String osSep() { + return FileSystems.getDefault().getSeparator() + } + + static String osJoin(String... parts) { + return parts.join(osSep()) + } + static String today() { LocalDate date = LocalDate.now() return date.toString() @@ -153,7 +162,7 @@ class QuiltPackage { */ List relativeChildren(String subpath) { Path subfolder = folder.resolve(subpath) - String base = subfolder.toString() + QuiltPath.osSep() + String base = subfolder.toString() + osSep() List result = [] final String[] children = subfolder.list().sort() //log.debug("relativeChildren[${base}] $children") diff --git a/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltPath.groovy b/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltPath.groovy index 4e5b69e0..cc18e5ba 100644 --- a/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltPath.groovy +++ b/plugins/nf-quilt/src/main/nextflow/quilt/nio/QuiltPath.groovy @@ -19,7 +19,6 @@ import nextflow.quilt.jep.QuiltPackage import nextflow.quilt.jep.QuiltParser import java.nio.file.Files import java.nio.file.FileSystem -import java.nio.file.FileSystems import java.nio.file.LinkOption import java.nio.file.Path import java.nio.file.Paths @@ -46,14 +45,6 @@ final class QuiltPath implements Path, Comparable { private final String[] paths private final boolean isFileName - static String osSep() { - return FileSystems.getDefault().getSeparator() - } - - static String osJoin(String... parts) { - return parts.join(osSep()) - } - QuiltPath(QuiltFileSystem filesystem, QuiltParser parsed, boolean isFileName = false) { this.filesystem = filesystem this.parsed = parsed @@ -223,7 +214,7 @@ final class QuiltPath implements Path, Comparable { Path relativize(Path other) { if (this == other) { return null } String file = (other in QuiltPath) ? ((QuiltPath)other).localPath() : other.toString() - String base = osJoin(pkg().toString(), parsed.getPath()) + String base = QuiltPackage.osJoin(pkg().toString(), parsed.getPath()) println("relativize[$base] in [$file]") int i = file.indexOf(base) if (i < 1) { diff --git a/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltPathTest.groovy b/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltPathTest.groovy index 72323dbf..f3637a8e 100644 --- a/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltPathTest.groovy +++ b/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltPathTest.groovy @@ -261,13 +261,15 @@ class QuiltPathTest extends QuiltSpecification { @Unroll // @IgnoreIf({ System.getProperty('os.name').toLowerCase().contains('windows') }) void 'should validate relativize'() { + given: + String base = 'bucket#package=so%2fme' expect: pathify(path).relativize(pathify(other)).toString() == pathify(expected).toString() where: path | other | expected - 'bucket#package=so%2fme' | 'bucket#package=so%2fme%2fdata%2ffile.txt' | 'data%2ffile.txt' - 'bucket#package=so%2fme%2fdata' | 'bucket#package=so%2fme%2fdata%2ffile.txt' | 'file.txt' - 'bucket#package=so%2fme&path=foo' | 'bucket#package=so%2fme&path=foo%2fbar' | 'bar' + base | "${base}%2fdata%2ffile.txt" | QuiltPackage.osJoin('data', 'file.txt') + "${base}%2fdata" | "${base}%2fdata%2ffile.txt" | 'file.txt' + "${base}&path=foo" | "${base}&path=foo%2fbar" | 'bar' } void 'should reconstruct full URLs'() {