Skip to content

Commit

Permalink
copyFile rather than writeString
Browse files Browse the repository at this point in the history
  • Loading branch information
drernie committed Sep 6, 2024
1 parent fc0f41f commit efc2392
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
Expand Down Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -139,9 +151,12 @@ ${nextflow}
}

void publishOverlays(Map<String, Path> 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)
}
}

Expand Down
32 changes: 16 additions & 16 deletions plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltPathTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -225,24 +225,24 @@ 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
void 'should validate normalise'() {
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
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit efc2392

Please sign in to comment.