diff --git a/packages/nextcloud/lib/src/clients/custom/webdav/client.dart b/packages/nextcloud/lib/src/clients/custom/webdav/client.dart index 00331144..00b1cafd 100644 --- a/packages/nextcloud/lib/src/clients/custom/webdav/client.dart +++ b/packages/nextcloud/lib/src/clients/custom/webdav/client.dart @@ -146,25 +146,28 @@ class WebDavClient { } /// just like mkdir -p - Future mkdirs( + Future mkdirs( final String remotePath, { final bool safe = true, }) async { final dirs = remotePath.trim().split('/')..removeWhere((final value) => value == ''); if (dirs.isEmpty) { - return; + return null; } if (remotePath.trim().startsWith('/')) { dirs[0] = '/${dirs[0]}'; } final prevPath = StringBuffer(); + late HttpClientResponse response; for (final dir in dirs) { - await mkdir( + response = await mkdir( '$prevPath/$dir', safe: safe, ); prevPath.write('/$dir'); } + + return response; } /// remove dir with given [path] diff --git a/packages/nextcloud/test/webdav_test.dart b/packages/nextcloud/test/webdav_test.dart index f6592a29..7b13bc40 100644 --- a/packages/nextcloud/test/webdav_test.dart +++ b/packages/nextcloud/test/webdav_test.dart @@ -52,6 +52,15 @@ Future main() async { expect(response.statusCode, equals(201)); }); + test('Create directory recursively', () async { + final response = await client.webdav.mkdirs('test/bla'); + expect(response!.statusCode, equals(201)); + + final files = await client.webdav.ls('/test'); + expect(files, hasLength(1)); + expect(files[0].path, '/test/bla/'); + }); + test('Upload files', () async { final pngBytes = File('test/files/test.png').readAsBytesSync(); final txtBytes = File('test/files/test.txt').readAsBytesSync();