From efc2392ef684475c0aae57a03ee07e1bf38ccbd2 Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:55:21 -0700 Subject: [PATCH] copyFile rather than writeString --- CHANGELOG.md | 4 +++ .../main/nextflow/quilt/QuiltObserver.groovy | 5 ++- .../main/nextflow/quilt/QuiltProduct.groovy | 21 ++++++++++-- .../nextflow/quilt/nio/QuiltPathTest.groovy | 32 +++++++++---------- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be8b5262..c268d5ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [0.8.2] 2024-09-05 + +- Use copyFile rather than writeString for overlay files + ## [0.8.1] 2024-09-05 - Get output URI directly from params diff --git a/plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy b/plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy index e9f5b2f1..d7651815 100644 --- a/plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy +++ b/plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy @@ -117,7 +117,7 @@ class QuiltObserver implements TraceObserver { } boolean confirmPath(QuiltPath path) { - log.debug("checkPath[$path]") + log.debug("confirmPath[$path]") String key = pkgKey(path) if (!outputURIs.containsKey(key)) { log.warn("Output URI not found for key[$key] from path[$path]") @@ -153,12 +153,11 @@ class QuiltObserver implements TraceObserver { // Path source may be null, won't work with older versions of Nextflow log.debug("onFilePublish.Path[$destination] <- $source") QuiltPath qPath = asQuiltPath(destination) - if (qPath) { + if (qPath != null) { confirmPath(qPath) } else { matchPath(destination.toString()) } - confirmPath(qPath) } @Override diff --git a/plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy b/plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy index 2c4b3143..18242a86 100644 --- a/plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy +++ b/plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy @@ -106,6 +106,18 @@ ${nextflow} } } + static void copyFile(Path source, QuiltPackage pkg, String filepath) { + String dir = pkg.packageDest() + Path dest = Paths.get(dir, filepath.split('/') as String[]) + try { + dest.getParent().toFile().mkdirs() // ensure directories exist first + Files.copy(source, dest) + } + catch (Exception e) { + log.error("writeString: cannot write `$source` to `$dest` for `${pkg}`") + } + } + static String now() { LocalDateTime time = LocalDateTime.now() return time.toString() @@ -139,9 +151,12 @@ ${nextflow} } void publishOverlays(Map overlays) { - overlays.each { key, overlay -> - log.info("publishing overlay[$key]: ${overlay}") - writeString(overlay.text, pkg, key) + /// Copying working files to local package directory + /// for (re)upload to the package + /// FIXME: Replace this with in-place packaging + overlays.each { key, source -> + log.info("publishing overlay[$key]: ${source}") + copyFile(source, pkg, key) } } 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 0b5ac8da..4f24cb44 100644 --- a/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltPathTest.groovy +++ b/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltPathTest.groovy @@ -191,10 +191,10 @@ class QuiltPathTest extends QuiltSpecification { thrown ProviderMismatchException } - @Ignore('FIXME: subpath not yet implemented') + @Ignore('FIXME: test subpath in QuiltParser first') void 'should validate subpath: #expected'() { expect: - pathify(path).subpath(from, to) == pathify(expected) + pathify(path).subpath(from, to).getPath() == expected where: path | from | to | expected 'bucket#package=some%2fbig%2fdata%2ffile.txt' | 0 | 1 | 'data' @@ -209,13 +209,13 @@ class QuiltPathTest extends QuiltSpecification { pathify(path).startsWith(pathify(prefix)) == expected where: - path | prefix | expected + path | prefix | expected 'bucket#package=s/d/file.txt' | 'bucket#package=s%2fd' | true 'bucket#package=s/d/file.txt' | 'bucket#package=s' | true 'bucket#package=s/d/file.txt' | 'bucket' | true 'bucket#package=s/d/file.txt' | 'file.txt' | false - 'data%2ffile.txt' | 'data' | true - 'data%2ffile.txt' | 'file.txt' | false + 'data%2ffile.txt' | 'data' | true + 'data%2ffile.txt' | 'file.txt' | false } @Unroll @@ -225,13 +225,13 @@ class QuiltPathTest extends QuiltSpecification { //pathify(path).endsWith(pathify(suffix)) == expected where: - path | suffix | expected - SUB_PATH | 'file.txt' | true - SUB_PATH | 'f%2ffile.txt' | true - SUB_PATH | '/f%2ffile.txt' | false - SUB_PATH | 'bucket' | false - 'data%2ffile.txt' | 'data' | false - 'data%2ffile.txt' | 'file.txt' | true + path | suffix | expected + SUB_PATH | 'file.txt' | true + SUB_PATH | 'f%2ffile.txt' | true + SUB_PATH | '/f%2ffile.txt' | false + SUB_PATH | 'bucket' | false + 'data%2ffile.txt' | 'data' | false + 'data%2ffile.txt' | 'file.txt' | true } @Unroll @@ -239,10 +239,10 @@ class QuiltPathTest extends QuiltSpecification { expect: pathify(path).normalize() == pathify(expected) where: - path | expected - 'bucket#path=s/d/file.txt' | 'bucket#path=s/d/file.txt' + path | expected + 'bucket#path=s/d/file.txt' | 'bucket#path=s/d/file.txt' 'bucket#path=some%2f..%2ffile.txt' | 'bucket#path=file.txt' - 'file.txt' | 'file.txt' + 'file.txt' | 'file.txt' } @Unroll @@ -272,7 +272,7 @@ class QuiltPathTest extends QuiltSpecification { expect: pathify(path).relativize(pathify(other)).toString() == pathify(expected).toString() where: - path | other | expected + path | other | expected based() | based('%2fdata%2ffile.txt') | sepJoin('data', 'file.txt') based('%2fdata') | based('%2fdata%2ffile.txt') | 'file.txt' based('&path=foo') | based('&path=foo%2fbar') | 'bar'