WebDav创建目录时添加try防止报错

pull/981/head
gedoor 4 years ago
parent 90fd0d1a59
commit 60fb0d385d
  1. 15
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt

@ -144,19 +144,20 @@ class WebDav(urlStr: String) {
/** /**
* 根据自己的URL在远程处创建对应的文件夹 * 根据自己的URL在远程处创建对应的文件夹
*
* @return 是否创建成功 * @return 是否创建成功
*/ */
suspend fun makeAsDir(): Boolean { suspend fun makeAsDir(): Boolean {
val url = httpUrl val url = httpUrl
val auth = HttpAuth.auth val auth = HttpAuth.auth
if (url != null && auth != null) { if (url != null && auth != null) {
okHttpClient.newCall { //防止报错
url(url) return kotlin.runCatching {
method("MKCOL", null) okHttpClient.newCall {
addHeader("Authorization", Credentials.basic(auth.user, auth.pass)) url(url)
} method("MKCOL", null)
return true addHeader("Authorization", Credentials.basic(auth.user, auth.pass))
}
}.isSuccess
} }
return false return false
} }

Loading…
Cancel
Save