Skip to content

Commit b43bdd5

Browse files
committed
Fix listFiles() for task path inputs
Signed-off-by: Ben Sherman <[email protected]>
1 parent 8bd24fa commit b43bdd5

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

docs/reference/stdlib-types.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,6 @@ The following methods are available for manipulating files and directories in a
691691
`getPermissions() -> String`
692692
: Returns a file's permissions using the [symbolic notation](http://en.wikipedia.org/wiki/File_system_permissions#Symbolic_notation), e.g. `'rw-rw-r--'`.
693693

694-
`list() -> List<String>`
695-
: Returns the first-level elements (files and directories) of a directory as a list of strings.
696-
697694
`listFiles() -> List<Path>`
698695
: Returns the first-level elements (files and directories) of a directory as a list of Paths.
699696

modules/nextflow/src/main/groovy/nextflow/processor/TaskPath.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ final class TaskPath implements Path, PathEscapeAware {
334334
FilesEx.or(getFileName(),other)
335335
}
336336

337+
List<Path> listFiles(Closure<Boolean> filter = null) {
338+
FilesEx.listFiles(target, filter)
339+
}
337340

338341
String getPermissions() {
339342
FilesEx.getPermissions(target)

modules/nextflow/src/test/groovy/nextflow/processor/TaskPathTest.groovy

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class TaskPathTest extends Specification {
8787

8888
cleanup:
8989
folder.deleteDir()
90-
9190
}
9291

9392
def 'should validate equals method' () {
@@ -111,10 +110,8 @@ class TaskPathTest extends Specification {
111110
new TaskPath(p1, 'foo.txt').equals(t2)
112111

113112
!t1.equals(t3)
114-
115113
}
116114

117-
118115
def 'should validate operator equality' () {
119116
given:
120117
def p1 = Paths.get('/foo/bar/baz.txt')
@@ -138,7 +135,6 @@ class TaskPathTest extends Specification {
138135

139136
expect:
140137
new TaskPath(Paths.get('/foo')).size() == 0
141-
142138
}
143139

144140
@Ignore
@@ -159,10 +155,8 @@ class TaskPathTest extends Specification {
159155

160156
cleanup:
161157
folder.deleteDir()
162-
163158
}
164159

165-
166160
def 'should serialised task path' () {
167161

168162
given:
@@ -174,7 +168,22 @@ class TaskPathTest extends Specification {
174168
copy.equals(p)
175169
}
176170

177-
}
171+
def 'should support directory listing' () {
178172

173+
given:
174+
def folder = Files.createTempDirectory('test')
175+
folder.resolve('hello.txt').text = 'Hello world'
179176

177+
when:
178+
def path = new TaskPath(folder, 'test')
179+
def result = path.listFiles()
180+
181+
then:
182+
result.size() == 1
183+
result[0].name == 'hello.txt'
184+
185+
cleanup:
186+
folder.deleteDir()
187+
}
180188

189+
}

0 commit comments

Comments
 (0)