Rename source download folder on source rename (#7898)

* Rename source download folder on source rename

* Review Changes

* Review Changes 2
This commit is contained in:
AntsyLich
2022-08-30 23:15:34 +06:00
committed by GitHub
parent fc6946ed61
commit 53f5ea7fe9
2 changed files with 32 additions and 0 deletions

View File

@@ -343,6 +343,30 @@ class DownloadManager(
}
}
/**
* Renames source download folder
*
* @param oldSource the old source.
* @param newSource the new source.
*/
fun renameSource(oldSource: Source, newSource: Source) {
val oldFolder = provider.findSourceDir(oldSource) ?: return
val newName = provider.getSourceDirName(newSource)
val capitalizationChanged = oldFolder.name.equals(newName, ignoreCase = true)
if (capitalizationChanged) {
val tempName = newName + "_tmp"
if (oldFolder.renameTo(tempName).not()) {
logcat(LogPriority.ERROR) { "Could not rename source download folder: ${oldFolder.name}." }
return
}
}
if (oldFolder.renameTo(newName).not()) {
logcat(LogPriority.ERROR) { "Could not rename source download folder: ${oldFolder.name}." }
}
}
/**
* Renames an already downloaded chapter
*