Skip to content
Merged
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 @@ -185,14 +185,13 @@ public int updateSyncedFolderEnabled(long id, Boolean enabled) {
}

public SyncedFolder findByLocalPathAndAccount(String localPath, Account account) {

SyncedFolder result = null;
Cursor cursor = mContentResolver.query(
ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
null,
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + "=? AND " +
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + "LIKE ? AND " +
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " =? ",
new String[]{localPath, account.name},
new String[]{localPath + "%", account.name},
null
);

Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/owncloud/android/jobs/FilesSyncJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,20 @@ private void syncFolder(Context context, Resources resources, boolean lightVersi
remotePath += adaptedPath;
}

String relativeSubfolderPath = new File(path.replace(syncedFolder.getLocalPath(), ""))
.getParentFile().getAbsolutePath();

requester.uploadFileWithOverwrite(
context,
account,
file.getAbsolutePath(),
FileStorageUtils.getInstantUploadFilePath(
currentLocale,
remotePath, file.getName(),
lastModificationTime, subfolderByDate),
currentLocale,
remotePath,
relativeSubfolderPath,
file.getName(),
lastModificationTime,
subfolderByDate),
uploadAction,
mimeType,
true, // create parent folder if not existent
Expand All @@ -223,7 +229,7 @@ private void syncFolder(Context context, Resources resources, boolean lightVersi
);

filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
Long.toString(syncedFolder.getId()));
Long.toString(syncedFolder.getId()));
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/owncloud/android/utils/FileStorageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,22 @@ private static String getSubPathFromDate(long date, Locale currentLocale) {
*/
public static String getInstantUploadFilePath(Locale current,
String remotePath,
String subfolder,
@Nullable String fileName,
long dateTaken,
Boolean subfolderByDate) {
String subPath = "";
String subfolderByDatePath = "";
if (subfolderByDate) {
subPath = getSubPathFromDate(dateTaken, current);
subfolderByDatePath = getSubPathFromDate(dateTaken, current);
}

// Path must be normalized; otherwise the next RefreshFolderOperation has a mismatch and deletes the local file.
return (remotePath + OCFile.PATH_SEPARATOR + subPath + (fileName == null ? "" : fileName))
return (remotePath +
OCFile.PATH_SEPARATOR +
subfolderByDatePath +
subfolder + // starts with / so no separator is needed
OCFile.PATH_SEPARATOR +
(fileName == null ? "" : fileName))
.replaceAll(OCFile.PATH_SEPARATOR + "+", OCFile.PATH_SEPARATOR);
}

Expand Down
56 changes: 44 additions & 12 deletions src/test/java/com/nextcloud/client/utils/FileStorageUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,74 +27,106 @@ import org.junit.Test
import java.util.Locale

class FileStorageUtilsTest {
@Test
fun testInstantUploadPathSubfolder() {
val result = FileStorageUtils.getInstantUploadFilePath(Locale.ROOT,
"/remotePath/",
"subfolder",
"file.pdf",
123123123L,
false)
val expected = "/remotePath/subfolder/file.pdf"

assertEquals(expected, result)
}

@Test
fun testInstantUploadPathNoSubfolder() {
val result = FileStorageUtils.getInstantUploadFilePath(Locale.ROOT,
"/remotePath/",
"",
"file.pdf",
123123123L,
false)
val expected = "/remotePath/file.pdf"

assertEquals(expected, result)
}

@Test
fun testInstantUploadPathNullFilename() {
val result = FileStorageUtils.getInstantUploadFilePath(Locale.ROOT,
"/subfolder/",
"/remotePath/",
"subfolder",
null,
123123123L,
false)
val expected = "/subfolder/"
val expected = "/remotePath/subfolder/"

assertEquals(expected, result)
}

@Test
fun testInstantUploadPathNullEmptyDate() {
val result = FileStorageUtils.getInstantUploadFilePath(Locale.ROOT,
"/subfolder/",
"/remotePath/",
"",
"file.pdf",
0,
true)
val expected = "/subfolder/file.pdf"
val expected = "/remotePath/file.pdf"

assertEquals(expected, result)
}

@Test
fun testInstantUploadPath() {
val result = FileStorageUtils.getInstantUploadFilePath(Locale.ROOT,
"/subfolder/",
"/remotePath/",
"",
"file.pdf",
123123123L,
false)
val expected = "/subfolder/file.pdf"
val expected = "/remotePath/file.pdf"

assertEquals(expected, result)
}

@Test
fun testInstantUploadPathWithSubfolderByDate() {
val result = FileStorageUtils.getInstantUploadFilePath(Locale.ROOT,
"/subfolder/",
"/remotePath/",
"",
"file.pdf",
1569918628000,
true)
val expected = "/subfolder/2019/10/file.pdf"
val expected = "/remotePath/2019/10/file.pdf"

assertEquals(expected, result)
}

@Test
fun testInstantUploadPathWithSubfolderFile() {
val result = FileStorageUtils.getInstantUploadFilePath(Locale.ROOT,
"/subfolder/",
"/remotePath/",
"",
"/sub/file.pdf",
123123123L,
false)
val expected = "/subfolder/sub/file.pdf"
val expected = "/remotePath/sub/file.pdf"

assertEquals(expected, result)
}

@Test
fun testInstantUploadPathWithSubfolderByDateWithSubfolderFile() {
val result = FileStorageUtils.getInstantUploadFilePath(Locale.ROOT,
"/subfolder/",
"/remotePath/",
"",
"/sub/file.pdf",
1569918628000,
true)
val expected = "/subfolder/2019/10/sub/file.pdf"
val expected = "/remotePath/2019/10/sub/file.pdf"

assertEquals(expected, result)
}
Expand Down