Skip to content
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
4 changes: 3 additions & 1 deletion lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Client {
/// Recursively create folders
Future<void> mkdirAll(String path, [CancelToken? cancelToken]) async {
path = fixSlashes(path);

var resp = await this.c.wdMkcol(this, path, cancelToken: cancelToken);
var status = resp.statusCode;
if (status == 201 || status == 405) {
Expand All @@ -107,9 +108,10 @@ class Client {
continue;
}
sub += e + '/';

resp = await this.c.wdMkcol(this, sub, cancelToken: cancelToken);
status = resp.statusCode;
if (status != 201 && status != 405) {
if (status != 201 && status != 405 && status != 409) {
throw newResponseError(resp);
}
}
Expand Down
53 changes: 44 additions & 9 deletions lib/src/xml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,55 @@ class WebdavXml {

// create time
final cTimeElements = findElements(prop, 'creationdate');
DateTime? cTime = cTimeElements.isNotEmpty
? DateTime.parse(cTimeElements.single.text).toLocal()
: null;
DateTime? cTime;
try {
cTime = cTimeElements.isNotEmpty
? DateTime.parse(cTimeElements.single.text).toLocal()
: null;
} catch (e) {
cTime = null;
}

// modified time
final mTimeElements = findElements(prop, 'getlastmodified');
DateTime? mTime = mTimeElements.isNotEmpty
? str2LocalTime(mTimeElements.single.text)
DateTime? mTime;
try {
mTime = mTimeElements.isNotEmpty
? str2LocalTime(mTimeElements.single.text)
: null;
} catch (e) {
mTime = null;
}

// displayname
final displayNameElements = findElements(prop, 'displayname');
String? displayName = displayNameElements.isNotEmpty
? displayNameElements.single.text
: null;

//
var str = Uri.decodeFull(href);
var name = path2Name(str);
var filePath = path + name + (isDir ? '/' : '');
// Try to parse href to Uri. Use encoded version of hrefas fallback
// so filename with special characters wont lead to crash
var hrefAsUri =
Uri.tryParse(href) ?? Uri.tryParse(Uri.encodeFull(href));

String pathElementName;
String name;
// use manual path splitting as fallback
if (hrefAsUri != null) {
pathElementName = hrefAsUri.pathSegments.lastWhere(
(element) => element != "",
orElse: () => path2Name(href),
);
} else {
pathElementName = path2Name(href);
}

// some WebDav serve provides a custom name for path, if not use jsut the path name
name = displayName ?? pathElementName;
// uri.pathSegments will be decoded so we need to encode it back to sue
// it as path for further requests
var filePath =
path + Uri.encodeFull(pathElementName) + (isDir ? '/' : '');

files.add(File(
path: filePath,
Expand Down