Skip to content

Commit 2b7d7bc

Browse files
[MOD] XQuery, file:delete: ignore non-existing paths. qtspecs#2547
1 parent 7537d1f commit 2b7d7bc

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

basex-core/src/main/java/org/basex/query/func/file/FileDelete.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ public Value eval(final QueryContext qc) throws QueryException, IOException {
2020
final Path path = toPath(arg(0), qc);
2121
final boolean recursive = toBooleanOrFalse(arg(1), qc);
2222

23-
if(recursive) {
24-
delete(path, qc);
25-
} else {
26-
Files.delete(path);
23+
if(Files.exists(path)) {
24+
if(recursive) {
25+
delete(path, qc);
26+
} else {
27+
Files.delete(path);
28+
}
2729
}
2830
return Empty.VALUE;
2931
}
3032

3133
/**
32-
* Recursively deletes a file path.
34+
* Deletes a path recursively.
3335
* @param path path to be deleted
3436
* @param job job
3537
* @throws IOException I/O exception

basex-core/src/test/java/org/basex/query/func/FileModuleTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ public final class FileModuleTest extends SandboxTest {
202202
query(_FILE_CREATE_DIR.args(PATH3));
203203
query(_FILE_WRITE.args(PATH4, " ()"));
204204
query(func.args(PATH1, true));
205-
error(func.args(PATH1), FILE_NOT_FOUND_X);
205+
// raise no error if file does not exist
206+
query(func.args(PATH1, true));
207+
query(func.args(PATH1));
206208
}
207209

208210
/** Test method. */

0 commit comments

Comments
 (0)