Skip to content
Merged
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: 2 additions & 2 deletions app/src/main/java/io/legado/app/help/AppWebDav.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ object AppWebDav {

val isJianGuoYun get() = rootWebDavUrl.startsWith(defaultWebDavUrl, true)

/** 增量同步根目录 */
/** 增量同步根目录, 位于备份目录(rootWebDavUrl)下的 sync/ */
val syncRootUrl: String
get() {
val root = if (rootWebDavUrl.endsWith("/")) rootWebDavUrl else "$rootWebDavUrl/"
return "${root}legado/sync/"
return "${root}sync/"
}

init {
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/io/legado/app/help/sync/SyncClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ object SyncClient {

/** 确保所有云端目录存在 */
suspend fun ensureDirs() {
ensureDir(baseUrl)
DataSyncType.values().forEach { type ->
kotlin.runCatching {
webDav(dirUrl(type)).makeAsDir()
Expand All @@ -55,6 +56,17 @@ object SyncClient {
}
}

/** 逐级创建目录, 兼容不支持自动创建父目录的服务器 */
private suspend fun ensureDir(url: String) {
val dav = webDav(url)
if (dav.exists()) return
val parent = url.trimEnd('/').substringBeforeLast('/', url) + "/"
if (parent != url && parent.contains("://")) {
ensureDir(parent)
}
dav.makeAsDir()
}

// ============================ push ============================

suspend fun pushBooks() {
Expand Down Expand Up @@ -101,6 +113,7 @@ object SyncClient {

/** 推送全部启用的类型 */
suspend fun pushAll() {
ensureDirs()
SyncConfig.dataTypes.forEach { type ->
when (type) {
DataSyncType.BOOKS -> pushBooks()
Expand Down