Skip to content

Commit

Permalink
addOverlay(String pkgKey, Path dest
Browse files Browse the repository at this point in the history
  • Loading branch information
drernie committed Sep 11, 2024
1 parent 73f9c4f commit e8855dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
11 changes: 6 additions & 5 deletions plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class QuiltObserver implements TraceObserver {
}

String pkgRelative(String pkgKey, Path dest) {
String destString = dest.toAbsolutePath().normalize()
String destString = QuiltPackage.osConvert(dest.toAbsolutePath().normalize().toString())
// find pkgKey in destination.toString()
int index = destString.indexOf(pkgKey)
// return the portion after the end of pkgKey
Expand All @@ -142,17 +142,20 @@ class QuiltObserver implements TraceObserver {
return null
}

void addOverlay(String pkgKey, Path dest, Path source) {
String 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)
String relPath = pkgRelative(pkgKey, dest)
println("addOverlay.relPath: $relPath")
log.debug("addOverlay[$relPath] = dest:$dest <= source:$source")
overlays[relPath] = source
packageOverlays[pkgKey] = overlays
return relPath
} finally {
lock.unlock()
}
return null
}

boolean confirmQuiltPath(QuiltPath qPath) {
Expand All @@ -165,9 +168,7 @@ class QuiltObserver implements TraceObserver {
boolean canOverlayPath(Path dest, Path source) {
log.debug("canOverlayPath[$dest] <- $source")
Set<String> keys = outputURIs.keySet()
log.debug("canOverlayPath: keys[${keys.size()}]: $keys")
for (String key : keys) {
log.debug("canOverlayPath: checking key[$key] for $dest")
if (dest.toString().contains(key)) {
log.debug("canOverlayPath: matched key[$key] to $dest")
addOverlay(key, dest, source)
Expand Down
37 changes: 14 additions & 23 deletions plugins/nf-quilt/src/test/nextflow/quilt/QuiltObserverTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import nextflow.quilt.QuiltSpecification
import nextflow.quilt.QuiltObserver
import nextflow.quilt.jep.QuiltPackage
import nextflow.Session
import spock.lang.Ignore
//import spock.lang.Ignore

import java.nio.file.Path
import java.nio.file.Paths
Expand Down Expand Up @@ -84,16 +84,12 @@ class QuiltObserverTest extends QuiltSpecification {
given:
QuiltObserver observer = makeObserver()
Path workDir = observer.session.workDir
println("workDir: $workDir")
String subPath = 'output/file.txt'
String workPath = "job/hash/${subPath}"
Path source = Paths.get(workDir.toString(), workPath)
println("source: $source")
expect:
String relPath = observer.workRelative(source)
println("relPath: $relPath")
relPath == QuiltPackage.osConvert(subPath)
println('done')
}

void 'should return pkgRelative path for dest'() {
Expand Down Expand Up @@ -149,34 +145,29 @@ class QuiltObserverTest extends QuiltSpecification {
!observer.confirmQuiltPath(testPath)
}

void 'should return: #rc if canOverlayPath with: #path'() {
void 'should return: #rc if canOverlayPath with: #path in: #root'() {
given:
QuiltObserver observer = makeObserver()
expect:
observer.session.workDir.toString() == QuiltPackage.osConvert('./work')
rc == observer.canOverlayPath(Paths.get(path), Paths.get(path))
rc == observer.canOverlayPath(Paths.get(root, path), Paths.get(path))
where:
rc | path
true | SPEC_KEY
true | "./work/${SPEC_KEY}"
true | "/tmp/${SPEC_KEY}"
true | "output/${TEST_KEY}"
false | 'output/not/a/key'
rc | root | path
true | SPEC_KEY | 'output/file.txt'
true | TEST_KEY | 'output/file.txt'
false | '/root' | 'output/file.txt'
}

/// source usually lacks subfolder paths
@Ignore
void 'should addOverlay dest path with subfolders'() {
void 'should addOverlay logical 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')
String file_path = 'file.txt'
String full_path = "output/${file_path}"
Path source = Paths.get(TEST_KEY, file_path)
Path dest = Paths.get(TEST_KEY, full_path)
expect:
!observer.packageOverlays.containsKey(targetKey)
observer.addOverlay(targetKey, dest, source)
observer.packageOverlays.containsKey(targetKey)
observer.packageOverlays[targetKey].containsKey('output/file.txt')
String relPath = observer.addOverlay(TEST_KEY, dest, source)
relPath == full_path
}

void 'should not error on onFlowComplete success'() {
Expand Down

0 comments on commit e8855dd

Please sign in to comment.