fix recursive copying

This commit is contained in:
tibbi 2016-11-05 20:23:32 +01:00
parent 2422b0fd53
commit 5b79b025ce
1 changed files with 11 additions and 6 deletions

View File

@ -54,15 +54,20 @@ class CopyTask(listener: CopyTask.CopyListener, val context: Context) : AsyncTas
val children = source.list() val children = source.list()
for (child in children) { for (child in children) {
val newFile = File(source, child)
if (Utils.needsStupidWritePermissions(context, destination.absolutePath)) { if (Utils.needsStupidWritePermissions(context, destination.absolutePath)) {
var document = Utils.getFileDocument(context, destination.absolutePath) if (newFile.isDirectory) {
document = document.createFile("", child) copyDirectory(newFile, File(destination, child))
} else {
var document = Utils.getFileDocument(context, destination.absolutePath)
document = document.createFile("", child)
val inputStream = FileInputStream(File(source, child)) val inputStream = FileInputStream(newFile)
val out = context.contentResolver.openOutputStream(document.uri) val out = context.contentResolver.openOutputStream(document.uri)
copyStream(inputStream, out) copyStream(inputStream, out)
}
} else { } else {
copy(File(source, child), File(destination, child)) copy(newFile, File(destination, child))
} }
} }
} }