mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Merge pull request #2056 from Naveen3Singh/file_permission_fix
Fix file permission issue related to automatic backup feature
This commit is contained in:
@@ -50,6 +50,7 @@ import org.joda.time.DateTime
|
|||||||
import org.joda.time.DateTimeZone
|
import org.joda.time.DateTimeZone
|
||||||
import org.joda.time.LocalDate
|
import org.joda.time.LocalDate
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||||
@@ -222,6 +223,7 @@ fun Context.checkAndBackupEventsOnBoot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Context.backupEventsAndTasks() {
|
fun Context.backupEventsAndTasks() {
|
||||||
|
require(isRPlus())
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val config = config
|
val config = config
|
||||||
val events = eventsHelper.getEventsToExport(
|
val events = eventsHelper.getEventsToExport(
|
||||||
@@ -257,9 +259,24 @@ fun Context.backupEventsAndTasks() {
|
|||||||
mkdirs()
|
mkdirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
val exportFile = File(outputFolder, "$filename.ics")
|
var exportFile = File(outputFolder, "$filename.ics")
|
||||||
|
var exportFilePath = exportFile.absolutePath
|
||||||
val outputStream = try {
|
val outputStream = try {
|
||||||
exportFile.outputStream()
|
if (hasProperStoredFirstParentUri(exportFilePath)) {
|
||||||
|
val exportFileUri = createDocumentUriUsingFirstParentTreeUri(exportFilePath)
|
||||||
|
if (!getDoesFilePathExist(exportFilePath)) {
|
||||||
|
createSAFFileSdk30(exportFilePath)
|
||||||
|
}
|
||||||
|
applicationContext.contentResolver.openOutputStream(exportFileUri, "wt") ?: FileOutputStream(exportFile)
|
||||||
|
} else {
|
||||||
|
var num = 0
|
||||||
|
while (getDoesFilePathExist(exportFilePath) && !exportFile.canWrite()) {
|
||||||
|
num++
|
||||||
|
exportFile = File(outputFolder, "${filename}_${num}.ics")
|
||||||
|
exportFilePath = exportFile.absolutePath
|
||||||
|
}
|
||||||
|
FileOutputStream(exportFile)
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
null
|
null
|
||||||
@@ -273,8 +290,8 @@ fun Context.backupEventsAndTasks() {
|
|||||||
}
|
}
|
||||||
MediaScannerConnection.scanFile(
|
MediaScannerConnection.scanFile(
|
||||||
this,
|
this,
|
||||||
arrayOf(exportFile.absolutePath),
|
arrayOf(exportFilePath),
|
||||||
arrayOf(exportFile.getMimeType())
|
arrayOf(exportFilePath.getMimeType())
|
||||||
) { _, _ -> }
|
) { _, _ -> }
|
||||||
|
|
||||||
config.lastAutoBackupTime = getNowSeconds()
|
config.lastAutoBackupTime = getNowSeconds()
|
||||||
|
Reference in New Issue
Block a user