Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for unstage strategy and fix for special characters #2181

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,17 @@ class SimpleFileCopyStrategy implements ScriptFileCopyStrategy {

final escape = new ArrayList(outputFiles.size())
for( String it : patterns )
escape.add( Escape.path(it) )
escape.add( Escape.path( it, true ) )

final mode = stageoutMode ?: ( workDir==targetDir ? 'copy' : 'move' )
return """\
IFS=\$'\\n'
for name in \$(eval "ls -1d ${escape.join(' ')}" | sort | uniq); do
pathes=`ls -1d ${escape.join(' ')} | sort | uniq`
set -f
for name in \$pathes; do
${stageOutCommand('$name', targetDir, mode)} || true
done
set +f
unset IFS""".stripIndent(true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,12 @@ class BashWrapperBuilderTest extends Specification {
then:
binding.unstage_outputs == '''\
IFS=$'\\n'
for name in $(eval "ls -1d test.bam test.bai" | sort | uniq); do
pathes=`ls -1d test.bam test.bai | sort | uniq`
set -f
for name in $pathes; do
nxf_fs_copy "$name" /work/dir || true
done
set +f
unset IFS
'''.stripIndent().rightTrim()

Expand All @@ -425,9 +428,12 @@ class BashWrapperBuilderTest extends Specification {
then:
binding.unstage_outputs == '''\
IFS=$'\\n'
for name in $(eval "ls -1d test.bam test.bai" | sort | uniq); do
pathes=`ls -1d test.bam test.bai | sort | uniq`
set -f
for name in $pathes; do
nxf_fs_move "$name" /another/dir || true
done
set +f
unset IFS
'''.stripIndent().rightTrim()
}
Expand Down

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion modules/nf-commons/src/main/nextflow/util/Escape.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ class Escape {
replace(WILDCARDS, str)
}

static String path(String val) {
static String path(String val, boolean glob = false) {
List<String> SPECIAL_CHARS = Escape.SPECIAL_CHARS
if ( glob ){
SPECIAL_CHARS = SPECIAL_CHARS.findAll {it != '\\' }
}
replace(SPECIAL_CHARS, val, true)
}

Expand Down
10 changes: 10 additions & 0 deletions modules/nf-commons/src/test/nextflow/util/EscapeTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ class EscapeTest extends Specification {
Escape.wildcards('file_[!a].txt') == 'file_\\[\\!a\\].txt'
}

def 'should ignore globs in file names' () {

expect:
Escape.path('hell?.txt', true ) == "hell?.txt"
Escape.path('hell\\?.txt', true ) == "hell\\?.txt"
Escape.path('hell*.txt', true ) == "hell*.txt"
Escape.path('hell**.txt', true ) == "hell**.txt"

}

def 'should escape cli' () {
expect:
Escape.cli('nextflow','run','this') == 'nextflow run this'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ class BashWrapperBuilderWithS3Test extends Specification {
then:
binding.unstage_outputs == '''\
IFS=$'\\n'
for name in $(eval "ls -1d test.bam test.bai" | sort | uniq); do
pathes=`ls -1d test.bam test.bai | sort | uniq`
set -f
for name in $pathes; do
nxf_s3_upload '$name' s3://some/bucket || true
done
set +f
unset IFS
'''.stripIndent().rightTrim()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ class BashWrapperBuilderWithAzTest extends Specification {
then:
binding.unstage_outputs == """\
IFS=\$'\\n'
for name in \$(eval "ls -1d test.bam test.bai" | sort | uniq); do
pathes=`ls -1d test.bam test.bai | sort | uniq`
set -f
for name in \$pathes; do
nxf_az_upload '\$name' '${AzHelper.toHttpUrl(target)}' || true
done
set +f
unset IFS
""".stripIndent().rightTrim()

Expand Down