From b2ff970a5a43260671a6a2f7b32110d50bdca950 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sun, 23 Apr 2023 10:42:38 +0200 Subject: [PATCH] nextcloud: Fix WebDav propfind depth --- packages/nextcloud/lib/src/webdav/client.dart | 6 ++++-- packages/nextcloud/test/webdav.dart | 13 ++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index a48c2cee..1c345f1f 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/packages/nextcloud/lib/src/webdav/client.dart @@ -213,11 +213,13 @@ class WebDavClient { /// list the directories and files under given [remotePath]. /// /// Optionally populates the given [prop]s on the returned files. + /// [depth] can be '0', '1' or 'infinity'. Future ls( final String remotePath, { final WebDavPropfindProp? prop, - final int? depth, + final String? depth, }) async { + assert(depth == null || ['0', '1', 'infinity'].contains(depth), 'Depth has to be 0, 1 or infinity'); final response = await _send( 'PROPFIND', _constructPath(remotePath), @@ -231,7 +233,7 @@ class WebDavClient { ), headers: { if (depth != null) ...{ - 'Depth': depth.toString(), + 'Depth': depth, }, }, ); diff --git a/packages/nextcloud/test/webdav.dart b/packages/nextcloud/test/webdav.dart index 9645708e..51f6817f 100644 --- a/packages/nextcloud/test/webdav.dart +++ b/packages/nextcloud/test/webdav.dart @@ -55,6 +55,15 @@ Future run(final DockerImage image) async { expect(props.ocsize, 50598); }); + test('List directory recursively', () async { + final responses = (await client.webdav.ls( + '/', + depth: 'infinity', + )) + .responses; + expect(responses, hasLength(37)); + }); + test('Create directory', () async { final response = await client.webdav.mkdir('test'); expect(response.statusCode, equals(201)); @@ -229,7 +238,6 @@ Future run(final DockerImage image) async { ocssharepermissions: true, ocmsharepermissions: true, ), - depth: 0, )) .responses .single @@ -276,7 +284,7 @@ Future run(final DockerImage image) async { davgetlastmodified: true, ocsize: true, ), - depth: 0, + depth: '0', )) .responses .single @@ -339,7 +347,6 @@ Future run(final DockerImage image) async { nccreationtime: true, ncuploadtime: true, ), - depth: 0, )) .responses .single