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
7 changes: 7 additions & 0 deletions changelog/unreleased/5033
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Double separator in automatic uploads remote path

The remote path of automatic uploads has been fixed so it no longer contains a
double separator when the destination folder path ends with a separator.

https://github.com/owncloud/android/issues/4451
https://github.com/owncloud/android/pull/5033
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

import timber.log.Timber
import java.io.File
import java.util.Date
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -144,9 +143,10 @@ class AutomaticUploadsWorker(
showNotification(syncType, localPicturesDocumentFiles.size)

for (documentFile in localPicturesDocumentFiles) {
val uploadPath = folderBackUpConfiguration.getRemotePathForFile(documentFile.name.orEmpty())
val uploadId = storeInUploadsDatabase(
documentFile = documentFile,
uploadPath = folderBackUpConfiguration.uploadPath.plus(File.separator).plus(documentFile.name),
uploadPath = uploadPath,
accountName = folderBackUpConfiguration.accountName,
behavior = folderBackUpConfiguration.behavior,
createdByWorker = when (syncType) {
Expand All @@ -157,7 +157,7 @@ class AutomaticUploadsWorker(
)
enqueueSingleUpload(
contentUri = documentFile.uri,
uploadPath = folderBackUpConfiguration.uploadPath.plus(File.separator).plus(documentFile.name),
uploadPath = uploadPath,
lastModified = documentFile.lastModified(),
behavior = folderBackUpConfiguration.behavior.toString(),
accountName = folderBackUpConfiguration.accountName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package com.owncloud.android.domain.automaticuploads.model

import java.io.File

data class FolderBackUpConfiguration(
val accountName: String,
val behavior: UploadBehavior,
Expand All @@ -34,6 +36,13 @@ data class FolderBackUpConfiguration(
val isPictureUploads get() = name == pictureUploadsName
val isVideoUploads get() = name == videoUploadsName

/**
* Remote path for a file uploaded to this folder. The upload path may end with a separator
* (folders picked in the app do), so it is trimmed to avoid a double separator.
*/
fun getRemotePathForFile(fileName: String): String =
uploadPath.trimEnd(File.separatorChar) + File.separator + fileName

companion object {
const val pictureUploadsName = "Picture uploads"
const val videoUploadsName = "Video uploads"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* ownCloud Android client application
*
* Copyright (C) 2026 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android.domain.automaticuploads.model

import com.owncloud.android.testutil.OC_BACKUP
import org.junit.Assert.assertEquals
import org.junit.Test

class FolderBackUpConfigurationTest {

@Test
fun `getRemotePathForFile - ok - upload path without trailing separator`() {
val folderBackUpConfiguration = OC_BACKUP.copy(uploadPath = "/Photos")

assertEquals("/Photos/image.jpg", folderBackUpConfiguration.getRemotePathForFile("image.jpg"))
}

@Test
fun `getRemotePathForFile - ok - upload path with trailing separator`() {
val folderBackUpConfiguration = OC_BACKUP.copy(uploadPath = "/Photos/")

assertEquals("/Photos/image.jpg", folderBackUpConfiguration.getRemotePathForFile("image.jpg"))
}

@Test
fun `getRemotePathForFile - ok - root upload path`() {
val folderBackUpConfiguration = OC_BACKUP.copy(uploadPath = "/")

assertEquals("/image.jpg", folderBackUpConfiguration.getRemotePathForFile("image.jpg"))
}
}