Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import eu.opencloud.android.domain.transfers.TransferRepository
import eu.opencloud.android.domain.transfers.model.OCTransfer
import eu.opencloud.android.domain.transfers.model.TransferResult
import eu.opencloud.android.domain.transfers.model.TransferStatus
import eu.opencloud.android.extensions.isContentUri
import eu.opencloud.android.extensions.parseError
import eu.opencloud.android.domain.capabilities.usecases.GetStoredCapabilitiesUseCase
import eu.opencloud.android.lib.common.OpenCloudAccount
Expand Down Expand Up @@ -142,7 +141,12 @@ class UploadFileFromContentUriWorker(
val localStorageProvider: LocalStorageProvider by inject()
cachePath = localStorageProvider.getTemporalPath(account.name, ocTransfer.spaceId) + uploadPath

if (ocTransfer.isContentUri(appContext)) {
// Re-copy if the cache file is missing or empty. A previous run may have copied it
// and then had it removed (e.g. by removeCacheFile() after a sibling worker for the
// same uploadPath completed). Without this, the PUT would go out against a stale or
// missing cache file. Only the contentUri from worker params is authoritative.
val cacheFile = File(cachePath)
if (!cacheFile.exists() || cacheFile.length() == 0L) {
checkDocumentFileExists()
checkPermissionsToReadDocumentAreGranted()
copyFileToLocalStorage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,24 @@ open class FileRequestBody(
override fun contentLength(): Long = file.length()

override fun writeTo(sink: BufferedSink) {
val source: Source
var it: Iterator<OnDatatransferProgressListener>
try {
source = file.source()
var transferred: Long = 0
var read: Long
while (source.read(sink.buffer, BYTES_TO_READ).also { read = it } != -1L) {
// Don't swallow IO errors here — a missing source file used to silently produce
// a 0-byte PUT that the server happily stored (issue #78).
val source: Source = file.source()
var transferred: Long = 0
var read: Long
source.use { src ->
while (src.read(sink.buffer, BYTES_TO_READ).also { read = it } != -1L) {
transferred += read
sink.flush()
synchronized(dataTransferListeners) {
it = dataTransferListeners.iterator()
val it = dataTransferListeners.iterator()
while (it.hasNext()) {
it.next().onTransferProgress(read, transferred, file.length(), file.absolutePath)
}
}
}
Timber.d("File with name ${file.name} and size ${file.length()} written in request body")
} catch (e: Exception) {
Timber.e(e)
}
Timber.d("File with name ${file.name} and size ${file.length()} written in request body")
}

override fun addDatatransferProgressListener(listener: OnDatatransferProgressListener) {
Expand Down
Loading