Skip to content

Commit

Permalink
pkgRelative
Browse files Browse the repository at this point in the history
  • Loading branch information
drernie committed Sep 11, 2024
1 parent 29973f3 commit 73f9c4f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.8.6] 2024-09-11

- Fix addOverlay bug on subfolders
- Improve Windows code coverage

## [0.8.5] 2024-09-10a

- Error with packaging subfolders on S3 overlay
Expand Down
17 changes: 14 additions & 3 deletions plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,23 @@ class QuiltObserver implements TraceObserver {
}
}

void addOverlay(String pkgKey, Path source) {
String pkgRelative(String pkgKey, Path dest) {
String destString = dest.toAbsolutePath().normalize()
// find pkgKey in destination.toString()
int index = destString.indexOf(pkgKey)
// return the portion after the end of pkgKey
if (index >= 0) {
return destString.substring(index + pkgKey.length() + 1)
}
return null
}

void addOverlay(String pkgKey, Path dest, Path source) {
lock.lock()
try {
Map<String, Path> overlays = packageOverlays.get(pkgKey, [:]) as Map<String, Path>
String relPath = workRelative(source)
log.debug("addOverlay[$relPath] = $source")
log.debug("addOverlay[$relPath] = dest:$dest <= source:$source")
overlays[relPath] = source
packageOverlays[pkgKey] = overlays
} finally {
Expand All @@ -159,7 +170,7 @@ class QuiltObserver implements TraceObserver {
log.debug("canOverlayPath: checking key[$key] for $dest")
if (dest.toString().contains(key)) {
log.debug("canOverlayPath: matched key[$key] to $dest")
addOverlay(key, source)
addOverlay(key, dest, source)
return true
}
}
Expand Down
29 changes: 29 additions & 0 deletions plugins/nf-quilt/src/test/nextflow/quilt/QuiltObserverTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import nextflow.quilt.QuiltSpecification
import nextflow.quilt.QuiltObserver
import nextflow.quilt.jep.QuiltPackage
import nextflow.Session
import spock.lang.Ignore

import java.nio.file.Path
import java.nio.file.Paths
Expand Down Expand Up @@ -95,6 +96,19 @@ class QuiltObserverTest extends QuiltSpecification {
println('done')
}

void 'should return pkgRelative path for dest'() {
given:
QuiltObserver observer = makeObserver()
expect:
Path dest = Paths.get(TEST_KEY, folderPath)
String relPath = observer.pkgRelative(offset, dest)
rc == (relPath == folderPath)
where:
rc | offset | folderPath
true | TEST_KEY | 'output/file.txt'
false | SPEC_KEY | 'output/file.txt'
}

void 'should findOutputParams'() {
given:
QuiltObserver observer = makeObserver()
Expand Down Expand Up @@ -150,6 +164,21 @@ class QuiltObserverTest extends QuiltSpecification {
false | 'output/not/a/key'
}

/// source usually lacks subfolder paths
@Ignore
void 'should addOverlay dest path with subfolders'() {
given:
QuiltObserver observer = makeObserver()
Path dest = Paths.get('output/file.txt')
Path source = Paths.get('file.txt')
String targetKey = QuiltPackage.osConvert('bucket/prefix/suffix')
expect:
!observer.packageOverlays.containsKey(targetKey)
observer.addOverlay(targetKey, dest, source)
observer.packageOverlays.containsKey(targetKey)
observer.packageOverlays[targetKey].containsKey('output/file.txt')
}

void 'should not error on onFlowComplete success'() {
given:
String quilt_uri = 'quilt+s3://bucket#package=prefix%2fsuffix'
Expand Down

0 comments on commit 73f9c4f

Please sign in to comment.